| @@ -37,14 +37,20 @@ class DiscountTicketListController extends WebController | |||
| ->firstOrFail(); | |||
| $res = [ | |||
| "parking_name" => $parking->park_name, | |||
| "parking_management_code" => $parking->park_code, | |||
| "list" => DiscountTicket::getBuilder() | |||
| ->where(DiscountTicket::COL_NAME_PARK_ID, $parking->id) | |||
| ->select([ | |||
| sprintf("%s as %s", DiscountTicket::COL_NAME_DISCOUNT_TICKET_CODE, ColumnName::DISCOUNT_TICKET_CODE), | |||
| sprintf("%s as %s", DiscountTicket::COL_NAME_TICKET_NAME, "ticket_name"), | |||
| ])->get() | |||
| ]) | |||
| ->orderBy(DiscountTicket::COL_NAME_DISCOUNT_TICKET_CODE) | |||
| ->get() | |||
| ]; | |||
| return $this->successResponse($res); | |||
| } | |||
| } | |||
| @@ -51,6 +51,10 @@ class CheckDataFormatController extends WebController | |||
| ->first(); | |||
| if ($relation === null) { | |||
| logger([ | |||
| "shop_id" => $this->sessionUser->shopId(), | |||
| "駐車場管理コード" => $data->駐車場管理コード | |||
| ]); | |||
| throw new GeneralErrorMessageException("認証できない駐車場"); | |||
| } | |||
| @@ -62,6 +66,10 @@ class CheckDataFormatController extends WebController | |||
| if ($setting->isEmpty()) { | |||
| logger([ | |||
| "shop_id" => $this->sessionUser->shopId(), | |||
| "駐車場管理コード" => $data->駐車場管理コード | |||
| ]); | |||
| throw new GeneralErrorMessageException("認証できるサービス券なし"); | |||
| } | |||
| @@ -70,6 +78,10 @@ class CheckDataFormatController extends WebController | |||
| ->first(); | |||
| if ($parking instanceof Parking === false) { | |||
| logger([ | |||
| "shop_id" => $this->sessionUser->shopId(), | |||
| "駐車場管理コード" => $data->駐車場管理コード | |||
| ]); | |||
| throw new GeneralErrorMessageException("存在しない駐車場"); | |||
| } | |||
| @@ -86,7 +98,8 @@ class CheckDataFormatController extends WebController | |||
| // サービス券一覧の取得 | |||
| $discountTicketCodes = $setting->pluck(CertificationAvailableSetting::COL_NAME_DISCOUNT_TICKET_CODE)->toArray(); | |||
| $discountTickets = DiscountTicket::whereParkId($parking->id) | |||
| $discountTickets = DiscountTicket::getBuilder() | |||
| ->where(DiscountTicket::COL_NAME_PARK_ID, $parking->id) | |||
| ->whereIn(DiscountTicket::COL_NAME_DISCOUNT_TICKET_CODE, $discountTicketCodes) | |||
| ->select([ | |||
| sprintf("%s as %s", DiscountTicket::COL_NAME_DISCOUNT_TICKET_CODE, ColumnName::DISCOUNT_TICKET_CODE), | |||
| @@ -2,6 +2,7 @@ | |||
| namespace App\Models\HtpmsCustomer\Existing; | |||
| use App\Models\Cast; | |||
| use App\Models\ColumnName; | |||
| use App\Util\DateUtil; | |||
| use Illuminate\Database\Eloquent\Model; | |||
| @@ -13,6 +14,7 @@ class DiscountTicket extends Model | |||
| const COL_NAME_PARK_ID = 'park_id'; | |||
| const COL_NAME_TICKET_NAME = 'ticketname'; | |||
| const COL_NAME_DISCOUNT_TICKET_CODE = 'lineno'; | |||
| const COL_NAME_START_DATETIME = 'start_datetime'; | |||
| protected $connection = 'htpms_customer'; | |||
| protected $table = 'tbl2_discountticket'; | |||
| @@ -25,12 +27,22 @@ class DiscountTicket extends Model | |||
| ColumnName::DISCOUNT_TICKET_CODE, | |||
| ]; | |||
| protected $casts = [ | |||
| self::COL_NAME_START_DATETIME => Cast::DATETIME, | |||
| ]; | |||
| public static function getBuilder(string $name = 'main'): Builder | |||
| { | |||
| $now = DateUtil::now(); | |||
| $instance = new static(); | |||
| return DB::connection($instance->getConnectionName())->table(static::getTableName(), $name); | |||
| $tablename = self::getTableName(); | |||
| $sub = function (Builder $query) use ($tablename) { | |||
| $query->selectRaw('*, rank() over (partition by park_id, adjuster_id, lineno order by start_datetime desc) as rank') | |||
| ->from($tablename) | |||
| ->where('start_datetime', '<=', DB::raw('CURRENT_TIMESTAMP')); | |||
| }; | |||
| return DB::connection($instance->getConnectionName())->table($sub, $name)->where($name . '.rank', 1); | |||
| } | |||
| public static function getTableName(): string | |||
| @@ -38,6 +38,9 @@ class CertificationAvailableSettingRepository extends BaseRepository | |||
| $join->on( | |||
| $this->makeColumnName([static::TABLE_RELATION, ShopNoRelation::COL_NAME_PARKING_MANAGEMENT_CODE]), | |||
| $this->makeColumnName([static::TABLE_SETTING, CertificationAvailableSetting::COL_NAME_PARKING_MANAGEMENT_CODE]) | |||
| )->on( | |||
| $this->makeColumnName([static::TABLE_RELATION, ShopNoRelation::COL_NAME_SHOP_ID]), | |||
| $this->makeColumnName([static::TABLE_SETTING, CertificationAvailableSetting::COL_NAME_SHOP_ID]) | |||
| ); | |||
| }); | |||
| $table->leftJoinSub(Parking::getBuilder(), static::TABLE_PARKING, function (JoinClause $join) { | |||
| @@ -64,6 +67,8 @@ class CertificationAvailableSettingRepository extends BaseRepository | |||
| // リミット | |||
| $this->limit($main, $condition); | |||
| logger($main->toRawSql()); | |||
| return CertificationAvailableSettingRepositoryData::makeList($main->get()); | |||
| } | |||