|
- <?php
-
- namespace App\Http\Controllers\Web\QRService\Certification;
-
- use App\Exceptions\GeneralErrorMessageException;
- use App\Http\Controllers\Web\WebController;
- use App\Logics\QRService\QRCryptoLogic;
- use App\Models\ColumnName;
- use App\Models\HtpmsCustomer\Existing\DiscountTicket;
- use App\Models\HtpmsCustomer\Existing\Parking;
- use App\Models\HtpmsCustomer\Mst\ShopNoRelation;
- use App\Models\HtpmsCustomer\QRService\CertificationAvailableSetting;
- use App\Models\HtpmsCustomer\QRService\CertificationTicket;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
-
- class CheckDataFormatController extends WebController
- {
-
- public function name(): string
- {
- return "データチェック";
- }
-
- public function description(): string
- {
- return "暗号化文字列をチェック認証に必要な情報を取得する";
- }
-
-
- public function __construct(protected CheckDataFormatParam $param)
- {
- parent::__construct();
- }
-
- protected function run(Request $request): JsonResponse
- {
- $param = $this->param;
-
- // 暗号化文字列の解読
- $data = DataConverter::read($param->data);
-
- // 対象の駐車場か判定
- $relation = ShopNoRelation::whereShopId($this->sessionUser->shopId())
- ->whereParkingManagementCode($data->駐車場管理コード)
- ->first();
-
- if ($relation === null) {
- throw new GeneralErrorMessageException("認証できない駐車場");
- }
-
-
- // 認証可能なサービス券一覧取得
- $setting = CertificationAvailableSetting::whereShopId($this->sessionUser->shopId())
- ->whereParkingManagementCode($data->駐車場管理コード)
- ->get();
-
-
- if ($setting->isEmpty()) {
- throw new GeneralErrorMessageException("認証できるサービス券なし");
- }
-
- // 駐車場情報の取得
- $parking = Parking::whereParkCode($data->駐車場管理コード)
- ->first();
-
- if ($parking instanceof Parking === false) {
- throw new GeneralErrorMessageException("存在しない駐車場");
- }
-
- // 認証済みチェック
- if (CertificationTicket::whereParkingManagementCode($data->駐車場管理コード)
- ->wherePublishingTerminalCode($data->発行端末)
- ->wherePublishingDate($data->発行日)
- ->wherePublishingNo($data->発行連番)
- ->exists()
- ) {
- throw new GeneralErrorMessageException("認証ずみのサービス券");
- }
-
-
- // サービス券一覧の取得
- $discountTicketCodes = $setting->pluck(CertificationAvailableSetting::COL_NAME_DISCOUNT_TICKET_CODE)->toArray();
- $discountTickets = DiscountTicket::whereParkId($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),
- sprintf("%s as %s", DiscountTicket::COL_NAME_TICKET_NAME, "ticket_name"),
- ])->get();
-
-
- $res = [
- "parking" => [
- "parking_name" => $parking->park_name,
- "parking_management_code" => $parking->park_code,
- "publishing_terminal_code" => $data->発行端末,
- "publishing_date" => $data->発行日,
- "publishing_no" => $data->発行連番,
- ],
- "discount_tickets" => $discountTickets,
- ];
-
- return $this->successResponse($res);
- }
- }
-
- /**
- * 精算機で暗号化された文字列をパースする
- */
- class DataConverter
- {
- public string $発行端末;
- public Carbon $発行日;
- public int $発行連番;
- public string $顧客コード;
- public string $駐車場管理コード;
-
- public static function read(string $data): static
- {
- $ret = new static();
-
- $dec = QRCryptoLogic::decrypt($data);
- if (strlen($dec) !== 30) {
- throw new GeneralErrorMessageException("文字数不正");
- }
- $data = substr($dec, 5);
-
- $ret->発行端末 = substr($data, 0, 2);
- $ret->発行日 = Carbon::createFromFormat("Ymd", substr($data, 2, 8));
- $ret->発行連番 = intval(substr($data, 10, 6));
- $ret->顧客コード = substr($data, 16, 4);
- $ret->駐車場管理コード = substr($data, 20, 5);
-
-
- return $ret;
- }
- }
|