From e1daada1e38cf5be347c8b7db1d691f65aeb2de1 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Mon, 19 Jun 2023 14:36:29 +0900 Subject: [PATCH] =?UTF-8?q?=E5=88=A9=E7=94=A8=E5=AE=9F=E7=B8=BE=E4=B8=80?= =?UTF-8?q?=E8=A6=A7=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Codes/QueueName.php | 1 + .../CreateReceiptIssuingOrderController.php | 79 +++++++++------- .../HelloTechno/UseSummariesController.php | 53 +++++++++++ .../Custom/HelloTechno/UseSummariesParam.php | 26 ++++++ .../UseSummaryYYYYMMsController.php | 50 +++++++++++ .../Web/UseSummary/UseSummaryYYYYMMsParam.php | 18 ++++ .../Custom/HelloTechno/CacheParkingName.php | 65 ++++++++++++++ .../Custom/HelloTechno/CreateManager.php | 6 ++ app/Models/HtCustomParkingName.php | 23 +++++ app/Models/UseSummary.php | 6 -- .../HelloTechno/UseSummaryRepository.php | 89 +++++++++++++++++++ .../HelloTechno/UseSummaryRepositoryData.php | 11 +++ app/Util/Custom/HelloTechno/API.php | 6 +- ...receipt_issuing_ht_custom_orders_table.php | 1 + ...0_create_ht_custom_parking_names_table.php | 42 +++++++++ routes/api.php | 3 + 16 files changed, 436 insertions(+), 43 deletions(-) create mode 100644 app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesController.php create mode 100644 app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesParam.php create mode 100644 app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsController.php create mode 100644 app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsParam.php create mode 100644 app/Jobs/Other/Custom/HelloTechno/CacheParkingName.php create mode 100644 app/Models/HtCustomParkingName.php create mode 100644 app/Repositories/Custom/HelloTechno/UseSummaryRepository.php create mode 100644 app/Repositories/Custom/HelloTechno/UseSummaryRepositoryData.php create mode 100644 database/migrations/2023_06_16_093400_create_ht_custom_parking_names_table.php diff --git a/app/Codes/QueueName.php b/app/Codes/QueueName.php index 065c711..2792102 100644 --- a/app/Codes/QueueName.php +++ b/app/Codes/QueueName.php @@ -6,4 +6,5 @@ enum QueueName: string { case EMAIL = 'email'; case SMS = 'sms'; + case OTHER = 'other'; } diff --git a/app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderController.php b/app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderController.php index 62f5081..02552bf 100644 --- a/app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderController.php +++ b/app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderController.php @@ -9,6 +9,7 @@ use App\Logic\ReceiptIssuingOrder\Custom\HelloTechno\CreateManager; use App\Models\ReceiptIssuingOrder as Order; use App\Models\ReceiptIssuingHTParkingCustomOrder as HT; use App\Util\Custom\HelloTechno\API; +use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -42,41 +43,51 @@ class CreateReceiptIssuingOrderController extends HelloTechnoController { $param = $this->param; - // 顧客情報取得 - $customer = collect(API::getCustomers($param->customerCode)) - ->where('customer_code', $param->customerCode) - ->firstOrFail(); - // 駐車場情報取得 - $parking = collect(API::getParkings($param->customerCode, $param->parkingManagementCode)) - ->where('parking_management_code', $param->parkingManagementCode) - ->firstOrFail(); - - $orderData = [ - ...$param->toArray(), - HT::COL_NAME_CUSTOMER_NAME => $customer['name'], - HT::COL_NAME_PARKING_NAME => $parking['name'], - Order::COL_NAME_HANDLER_ID => Auth::id(), - Order::COL_NAME_SUMMARY_KEY1 => $param->customerCode, - Order::COL_NAME_SUMMARY_KEY2 => $param->parkingManagementCode, - Order::COL_NAME_RECEIPT_PURPOSE => "駐車領収証", - Order::COL_NAME_RECEIPT_INVOICE_NO => "##TODO インボイス登録番号##", - Order::COL_NAME_RECEIPT_PURPOSE => "駐車料金", - Order::COL_NAME_RECEIPT_ISSUER => $customer['name'], - Order::COL_NAME_RECEIPT_SHOP_NAME => $parking['name'], - Order::COL_NAME_RECEIPT_PURPOSE => "駐車料金", - Order::COL_NAME_MEMO => "駐車料金", - ]; - - logger($orderData); - - $messages = $this->manager->init() - ->fill($orderData) - ->create(); - - if (count($messages) !== 0) { - return $this->failedResponse([], $messages); - } + try { + + + $this->transaction->beginTransaction(); + + // 顧客情報取得 + $customer = collect(API::getCustomers($param->customerCode)) + ->where('customer_code', $param->customerCode) + ->firstOrFail(); + // 駐車場情報取得 + $parking = collect(API::getParkings($param->customerCode, $param->parkingManagementCode)) + ->where('parking_management_code', $param->parkingManagementCode) + ->firstOrFail(); + + $orderData = [ + ...$param->toArray(), + HT::COL_NAME_CUSTOMER_NAME => $customer['name'], + HT::COL_NAME_PARKING_NAME => $parking['name'], + Order::COL_NAME_HANDLER_ID => Auth::id(), + Order::COL_NAME_SUMMARY_KEY1 => $param->customerCode, + Order::COL_NAME_SUMMARY_KEY2 => $param->parkingManagementCode, + Order::COL_NAME_RECEIPT_PURPOSE => "駐車領収証", + Order::COL_NAME_RECEIPT_INVOICE_NO => "##TODO インボイス登録番号##", + Order::COL_NAME_RECEIPT_PURPOSE => "駐車料金", + Order::COL_NAME_RECEIPT_ISSUER => $customer['name'], + Order::COL_NAME_RECEIPT_SHOP_NAME => $parking['name'], + Order::COL_NAME_RECEIPT_PURPOSE => "駐車料金", + Order::COL_NAME_MEMO => "駐車料金", + ]; + logger($orderData); + + $messages = $this->manager->init() + ->fill($orderData) + ->create(); + + if (count($messages) !== 0) { + return $this->failedResponse([], $messages); + } + + $this->transaction->commit(); + } catch (Exception $e) { + $this->transaction->rollBack(); + throw $e; + } return $this->successResponse(); } diff --git a/app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesController.php b/app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesController.php new file mode 100644 index 0000000..cc1f5d6 --- /dev/null +++ b/app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesController.php @@ -0,0 +1,53 @@ +roleAllow(UserRole::NORMAL_ADMIN); + } + + protected function getParam(): IParam + { + return $this->param; + } + + protected function run(Request $request): JsonResponse + { + $param = $this->param; + + $condition = [ + ...$param->toArray(), + Repository::CONDITION_CONTRACT_ID => Auth::user()->contract_id, + ]; + + $list = $this->repository->get($condition); + + + return $this->successResponse([ + 'records' => $list + ]); + } +} diff --git a/app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesParam.php b/app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesParam.php new file mode 100644 index 0000000..73ffd8a --- /dev/null +++ b/app/Http/Controllers/Web/Custom/HelloTechno/UseSummariesParam.php @@ -0,0 +1,26 @@ + $this->str(true), + Repository::CONDITION_SUMMARY_YYYYMM => $this->str(), + ], + $this->sortableRules(), + ); + } +} diff --git a/app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsController.php b/app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsController.php new file mode 100644 index 0000000..4b51792 --- /dev/null +++ b/app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsController.php @@ -0,0 +1,50 @@ +roleAllow(UserRole::NORMAL_ADMIN); + } + + protected function getParam(): IParam + { + return $this->param; + } + + protected function run(Request $request): JsonResponse + { + $list = UseSummary::whereContractId($this->loginUser()->getCurrentContractId()) + ->orderByDesc(UseSummary::COL_NAME_SUMMARY_YYYYMM) + ->pluck(UseSummary::COL_NAME_SUMMARY_YYYYMM); + + return $this->successResponse(['records' => $list]); + } +} diff --git a/app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsParam.php b/app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsParam.php new file mode 100644 index 0000000..eaf5a81 --- /dev/null +++ b/app/Http/Controllers/Web/UseSummary/UseSummaryYYYYMMsParam.php @@ -0,0 +1,18 @@ +onQueue(QueueName::OTHER->value); + } + + /** + * Execute the job. + * + * @return void + */ + public function handle(SMSManager $manager) + { + + // 顧客情報取得 + $customer = collect(API::getCustomers($this->customerCode)) + ->where('customer_code', $this->customerCode) + ->firstOrFail(); + // 駐車場情報取得 + $parking = collect(API::getParkings($this->customerCode, $this->parkingManagementCode)) + ->where('parking_management_code', $this->parkingManagementCode) + ->firstOrFail(); + + + // モデル更新 + $model = HtCustomParkingName::whereCustomerCode($this->customerCode) + ->whereParkingManagementCode($this->parkingManagementCode) + ->firstOrNew([ + HtCustomParkingName::COL_NAME_CUSTOMER_CODE => $this->customerCode, + HtCustomParkingName::COL_NAME_PARKING_MANAGEMENT_CODE => $this->parkingManagementCode, + ]); + + $model->customer_name = $customer['name']; + $model->parking_name = $parking['name']; + + $model->save(); + } +} diff --git a/app/Logic/ReceiptIssuingOrder/Custom/HelloTechno/CreateManager.php b/app/Logic/ReceiptIssuingOrder/Custom/HelloTechno/CreateManager.php index cd7f309..026589a 100644 --- a/app/Logic/ReceiptIssuingOrder/Custom/HelloTechno/CreateManager.php +++ b/app/Logic/ReceiptIssuingOrder/Custom/HelloTechno/CreateManager.php @@ -2,6 +2,7 @@ namespace App\Logic\ReceiptIssuingOrder\Custom\HelloTechno; +use App\Jobs\Other\Custom\HelloTechno\CacheParkingName; use App\Logic\ReceiptIssuingOrder\CreateManager as BaseManager; use App\Models\ReceiptIssuingHTParkingCustomOrder; @@ -39,6 +40,11 @@ class CreateManager $this->customOrder->setReceiptIssuingOrder($this->manager->id()); $this->customOrder->save(); + + // 駐車場名キャッシュ + CacheParkingName::dispatch($this->customOrder->customer_code, $this->customOrder->parking_management_code); + + return []; } } diff --git a/app/Models/HtCustomParkingName.php b/app/Models/HtCustomParkingName.php new file mode 100644 index 0000000..a26fdd4 --- /dev/null +++ b/app/Models/HtCustomParkingName.php @@ -0,0 +1,23 @@ + 'datetime', - self::COL_NAME_SUMMARY_DATE_END => 'datetime', - ]; public function getModelName(): string { diff --git a/app/Repositories/Custom/HelloTechno/UseSummaryRepository.php b/app/Repositories/Custom/HelloTechno/UseSummaryRepository.php new file mode 100644 index 0000000..94f6b77 --- /dev/null +++ b/app/Repositories/Custom/HelloTechno/UseSummaryRepository.php @@ -0,0 +1,89 @@ + + */ + public function get(array $condition): Collection + { + $order = UseByKeySummary::getBuilder(static::TABLE_SUMMARY); + + $parkingName = HtCustomParkingName::getBuilder(); + + + $table = $order + ->leftJoinSub($parkingName, static::TABLE_NAME, function (JoinClause $join) { + $join->on( + $this->makeColumnName([static::TABLE_SUMMARY, UseByKeySummary::COL_NAME_SUMMARY_KEY1]), + $this->makeColumnName([static::TABLE_NAME, HtCustomParkingName::COL_NAME_CUSTOMER_CODE]) + )->on( + $this->makeColumnName([static::TABLE_SUMMARY, UseByKeySummary::COL_NAME_SUMMARY_KEY2]), + $this->makeColumnName([static::TABLE_NAME, HtCustomParkingName::COL_NAME_PARKING_MANAGEMENT_CODE]) + ); + }); + + // -----検索条件 + // 契約ID + $this->where($table, $condition, static::CONDITION_CONTRACT_ID, $this->makeColumnName([static::TABLE_SUMMARY, UseByKeySummary::COL_NAME_CONTRACT_ID])); + // 年月 + $this->where($table, $condition, static::CONDITION_SUMMARY_YYYYMM, $this->makeColumnName([static::TABLE_SUMMARY, UseByKeySummary::COL_NAME_SUMMARY_YYYYMM])); + + + $table->select($this->columns()); + + $main = DB::table($table, "main"); + + // ソート + $this->sort($main, $condition); + $main->orderBy(static::CONDITION_ID); + + // リミット + $this->limit($main, $condition); + + + return ReceiptIssuingOrderRepositoryData::makeList($main->get()); + } + + private function columns() + { + $summary = static::TABLE_SUMMARY; + $name = static::TABLE_NAME; + $columns = [ + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_ID]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_SUMMARY_YYYYMM]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_SUMMARY_KEY1]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_SUMMARY_KEY2]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_RECEIPT_ORDER_COUNT]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_SMS_SEND_COUNT]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_IS_FIXED]), + $this->makeColumnNameForSelect([$summary, UseByKeySummary::COL_NAME_UPDATED_AT]), + $this->makeColumnNameForSelect([$name, HtCustomParkingName::COL_NAME_CUSTOMER_NAME]), + $this->makeColumnNameForSelect([$name, HtCustomParkingName::COL_NAME_PARKING_NAME]), + ]; + return $columns; + } +} diff --git a/app/Repositories/Custom/HelloTechno/UseSummaryRepositoryData.php b/app/Repositories/Custom/HelloTechno/UseSummaryRepositoryData.php new file mode 100644 index 0000000..b8c82a8 --- /dev/null +++ b/app/Repositories/Custom/HelloTechno/UseSummaryRepositoryData.php @@ -0,0 +1,11 @@ +string("parking_name")->comment("駐車場名")->nullable(); $helper->index(1, [ColumnName::RECEIPT_ISSUING_ORDER_ID]); + $helper->index(2, ['customer_code', 'parking_management_code', 'adjust_seq_no']); }; } }; diff --git a/database/migrations/2023_06_16_093400_create_ht_custom_parking_names_table.php b/database/migrations/2023_06_16_093400_create_ht_custom_parking_names_table.php new file mode 100644 index 0000000..eb78a84 --- /dev/null +++ b/database/migrations/2023_06_16_093400_create_ht_custom_parking_names_table.php @@ -0,0 +1,42 @@ +schema()); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('ht_custom_parking_names'); + } + + private function schema(bool $forHistory = false) + { + + return function (Blueprint $table, MigrationHelper $helper) use ($forHistory) { + $helper->baseColumn(); + + $table->string("customer_code")->comment("顧客コード"); + $table->string("parking_management_code")->comment("駐車場管理コード"); + $table->string("customer_name")->comment("顧客名")->nullable(); + $table->string("parking_name")->comment("駐車場名")->nullable(); + + $helper->index(1, ['customer_code', 'parking_management_code']); + }; + } +}; diff --git a/routes/api.php b/routes/api.php index e0bd387..6ce9eb5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,6 +22,8 @@ RouteHelper::post('/receipt-issuing-order/confirm', App\Http\Controllers\Web\Rec RouteHelper::post('/receipt-issuing-order/mail-order', App\Http\Controllers\Web\ReceiptIssuingOrder\MailOrderController::class); RouteHelper::post('/receipt-issuing-order/mail-complete', App\Http\Controllers\Web\ReceiptIssuingOrder\MailPostCompleteController::class); +RouteHelper::get('/use-summary/yyyymm', App\Http\Controllers\Web\UseSummary\UseSummaryYYYYMMsController::class); + RouteHelper::get('/receipt/download', App\Http\Controllers\Web\ReceiptIssuingOrder\TokenCheckController::class); @@ -41,3 +43,4 @@ RouteHelper::get('/custom/hello-techno/parkings', App\Http\Controllers\Web\Custo // RouteHelper::get('/custom/hello-techno/adjust-data', App\Http\Controllers\Web\Custom\HelloTechno\CustomersController::class); RouteHelper::get('/custom/hello-techno/receipt-issuing-orders', App\Http\Controllers\Web\Custom\HelloTechno\ReceiptIssuingOrdersController::class); RouteHelper::post('/custom/hello-techno/receipt-issuing-order/create', App\Http\Controllers\Web\Custom\HelloTechno\CreateReceiptIssuingOrderController::class); +RouteHelper::get('/custom/hello-techno/use-summaries', App\Http\Controllers\Web\Custom\HelloTechno\UseSummariesController::class);