You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7KB

  1. <?php
  2. namespace App\Http\Controllers\Web\QRService;
  3. use App\Http\Controllers\Web\WebController;
  4. use App\Logics\QRService\CreateLogic;
  5. use App\Logics\QRService\QRCryptoLogic;
  6. use App\Models\HtpmsCustomer\QRService\AcquisitionTicket;
  7. use Illuminate\Http\JsonResponse;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Auth;
  10. class CreateTicketController extends WebController
  11. {
  12. public function name(): string
  13. {
  14. return "サービス券取得";
  15. }
  16. public function description(): string
  17. {
  18. return "サービス券を取得する";
  19. }
  20. public function __construct(protected CreateTicketParam $param)
  21. {
  22. parent::__construct();
  23. }
  24. protected function run(Request $request): JsonResponse
  25. {
  26. $param = $this->param;
  27. if ($param->ticketId) {
  28. $ticket = AcquisitionTicket::findOrFail($param->ticketId);
  29. if (!$ticket->canUse()) {
  30. $ticket = CreateLogic::create($param->token);
  31. }
  32. } else {
  33. $ticket = CreateLogic::create($param->token);
  34. }
  35. $res = [
  36. 'ticket_id' => $ticket->id,
  37. 'data' => $this->convertToQrStr($ticket),
  38. ];
  39. return $this->successResponse($res);
  40. }
  41. private function convertToQrStr(AcquisitionTicket $ticket): string
  42. {
  43. $body = sprintf(
  44. "%02d%s$06d%02d%02d",
  45. "01",
  46. $ticket->publishing_date->format('Ymd'),
  47. $ticket->publishing_no,
  48. $ticket->shop_no,
  49. $ticket->discount_ticket_code,
  50. );
  51. return sprintf(
  52. "HT004%s",
  53. QRCryptoLogic::encrypt($body)
  54. );
  55. }
  56. }