|
- <?php
-
- namespace App\Http\Controllers\Web\QRService;
-
- use App\Http\Controllers\Web\WebController;
- use App\Logics\QRService\CreateLogic;
- use App\Logics\QRService\QRCryptoLogic;
- use App\Models\HtpmsCustomer\QRService\AcquisitionTicket;
- use App\Models\HtpmsCustomer\QRService\AcquisitionTicketToken;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Http\Request;
-
- class CreateTicketController extends WebController
- {
-
- public function name(): string
- {
- return "サービス券取得";
- }
-
- public function description(): string
- {
- return "サービス券を取得する";
- }
-
-
- public function __construct(protected CreateTicketParam $param)
- {
- parent::__construct();
- }
-
- protected function run(Request $request): JsonResponse
- {
- $param = $this->param;
-
- $token = AcquisitionTicketToken::whereToken($param->token)->first();
- if ($token === null) {
- return $this->failedResponse();
- }
-
- if ($param->ticketId) {
- $ticket = AcquisitionTicket::find($param->ticketId);
- if ($ticket === null || !$ticket->canUse()) {
- $ticket = CreateLogic::create($param->token);
- }
- } else {
- $ticket = CreateLogic::create($param->token);
- }
-
- $res = [
- 'ticket_id' => $ticket->id,
- 'data' => $this->convertToQrStr($ticket),
- ];
-
- return $this->successResponse($res);
- }
-
- private function convertToQrStr(AcquisitionTicket $ticket): string
- {
- $body = sprintf(
- "%02d%s%06d%02d%02d",
- "01",
- $ticket->publishing_date->format('Ymd'),
- $ticket->publishing_no,
- $ticket->shop_no,
- $ticket->discount_ticket_code,
- );
- return sprintf(
- "HT004%s",
- QRCryptoLogic::encrypt($body)
- );
- }
- }
|