From f3590e16f4eb83528a71aed9deac14e7e86e610d Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Wed, 27 Mar 2024 11:38:42 +0900 Subject: [PATCH] =?UTF-8?q?QR=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9=E5=88=B8?= =?UTF-8?q?=E9=A7=90=E8=BB=8A=E5=A0=B4=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=A8=E8=BE=BA=E6=95=B4=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Web/Parking/ParkingListController.php | 41 ++++++++ .../Web/Parking/ParkingListParam.php | 9 ++ .../Group/QRServiceGroupAddController.php | 43 +++++++++ .../Group/QRServiceGroupAddParam.php | 22 +++++ .../Group/QRServiceGroupListController.php | 84 ++++++++++++++++ .../Group/QRServiceGroupListParam.php | 25 +++++ .../QRServiceGroupRegisterController.php | 46 +++++++++ .../Group/QRServiceGroupRegisterParam.php | 19 ++++ .../Group/QRServiceGroupRemoveController.php | 43 +++++++++ .../Group/QRServiceGroupRemoveParam.php | 22 +++++ .../{ => Config}/ShopConfigController.php | 2 +- .../Web/Shop/{ => Config}/ShopConfigParam.php | 2 +- .../QRService/QRServiceParkingGroupLogic.php | 50 ++++++++++ app/Models/HtpmsCustomer/Existing/Parking.php | 18 ++++ .../QRService/ServiceParkingGroupHistory.php | 2 +- .../QRServiceParkingGroupRepository.php | 95 +++++++++++++++++++ .../QRServiceParkingGroupRepositoryData.php | 14 +++ routes/api.php | 9 +- 18 files changed, 541 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/Web/Parking/ParkingListController.php create mode 100644 app/Http/Controllers/Web/Parking/ParkingListParam.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupAddController.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupAddParam.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupListController.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupListParam.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterController.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterParam.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveController.php create mode 100644 app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveParam.php rename app/Http/Controllers/Web/Shop/{ => Config}/ShopConfigController.php (95%) rename app/Http/Controllers/Web/Shop/{ => Config}/ShopConfigParam.php (94%) create mode 100644 app/Logics/QRService/QRServiceParkingGroupLogic.php create mode 100644 app/Repositories/QRServiceParkingGroupRepository.php create mode 100644 app/Repositories/QRServiceParkingGroupRepositoryData.php diff --git a/app/Http/Controllers/Web/Parking/ParkingListController.php b/app/Http/Controllers/Web/Parking/ParkingListController.php new file mode 100644 index 0000000..f973352 --- /dev/null +++ b/app/Http/Controllers/Web/Parking/ParkingListController.php @@ -0,0 +1,41 @@ + Parking::getBuilder()->select([ + sprintf("%s as %s", Parking::COL_NAME_PARKING_MANAGEMENT_CODE, ColumnName::PARKING_MANAGEMENT_CODE), + sprintf("%s as %s", Parking::COL_NAME_PARKING_NAME, "parking_name"), + ])->get() + ]; + + return $this->successResponse($res); + } +} diff --git a/app/Http/Controllers/Web/Parking/ParkingListParam.php b/app/Http/Controllers/Web/Parking/ParkingListParam.php new file mode 100644 index 0000000..929e502 --- /dev/null +++ b/app/Http/Controllers/Web/Parking/ParkingListParam.php @@ -0,0 +1,9 @@ +param; + + $group = ServiceParkingGroup::findOrFail($param->id); + $parking = Parking::whereParkCode($param->parkingManagementCode) + ->firstOrFail(); + QRServiceParkingGroupLogic::add($group, $parking); + + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupAddParam.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupAddParam.php new file mode 100644 index 0000000..49a6c09 --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupAddParam.php @@ -0,0 +1,22 @@ + $this->str(), + ServiceParkingGroupRelation::COL_NAME_PARKING_MANAGEMENT_CODE => $this->str(), + ]; + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupListController.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupListController.php new file mode 100644 index 0000000..6d0bfa8 --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupListController.php @@ -0,0 +1,84 @@ +param; + + $list = $this->repository->get([ + ...$param->toArray(), + ]); + + + // データ整形 + $container = new データ整形(); + foreach ($list as $data) { + $container->add($data); + } + + $res = [ + 'list' => $container->output(), + ]; + + return $this->successResponse($res); + } +} + + +class データ整形 +{ + + private array $name = []; + private array $parking = []; + + public function add(QRServiceParkingGroupRepositoryData $data) + { + $this->name[$data->id] = $data->name; + + if ($data->parking_management_code === null) return; + + $this->parking[$data->id][] = [ + "parking_management_code" => $data->parking_management_code, + "parking_name" => $data->parking_name, + ]; + } + + public function output(): array + { + $ret = []; + foreach ($this->name as $id => $name) { + $data = []; + $data['id'] = $id; + $data['name'] = $name; + $data['parkings'] = data_get($this->parking, $id, []); + $ret[] = $data; + } + return $ret; + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupListParam.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupListParam.php new file mode 100644 index 0000000..1e4affb --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupListParam.php @@ -0,0 +1,25 @@ + $this->str(true), + QRServiceParkingGroupRepository::CONDITION_NAME => $this->str(true), + QRServiceParkingGroupRepository::CONDITION_PARKING_MANAGEMENT_CODE => $this->str(true), + ...$this->sortableRules(), + ]; + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterController.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterController.php new file mode 100644 index 0000000..d14218a --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterController.php @@ -0,0 +1,46 @@ +param; + + $group = new ServiceParkingGroup(); + $group->name = $param->name; + QRServiceParkingGroupLogic::register($group); + + + $res = [ + 'id' => $group->id, + ]; + + return $this->successResponse($res); + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterParam.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterParam.php new file mode 100644 index 0000000..8cc850b --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRegisterParam.php @@ -0,0 +1,19 @@ + $this->str(["between:5,100"]) + ]; + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveController.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveController.php new file mode 100644 index 0000000..cc40785 --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveController.php @@ -0,0 +1,43 @@ +param; + + $group = ServiceParkingGroup::findOrFail($param->id); + $parking = Parking::whereParkCode($param->parkingManagementCode) + ->firstOrFail(); + QRServiceParkingGroupLogic::remove($group, $parking); + + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveParam.php b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveParam.php new file mode 100644 index 0000000..5007483 --- /dev/null +++ b/app/Http/Controllers/Web/QRService/Group/QRServiceGroupRemoveParam.php @@ -0,0 +1,22 @@ + $this->str(), + ServiceParkingGroupRelation::COL_NAME_PARKING_MANAGEMENT_CODE => $this->str(), + ]; + } +} diff --git a/app/Http/Controllers/Web/Shop/ShopConfigController.php b/app/Http/Controllers/Web/Shop/Config/ShopConfigController.php similarity index 95% rename from app/Http/Controllers/Web/Shop/ShopConfigController.php rename to app/Http/Controllers/Web/Shop/Config/ShopConfigController.php index 67f9c8c..28eb2d0 100644 --- a/app/Http/Controllers/Web/Shop/ShopConfigController.php +++ b/app/Http/Controllers/Web/Shop/Config/ShopConfigController.php @@ -1,6 +1,6 @@ name)->exists()) { + ParamException::throw(ServiceParkingGroup::COL_NAME_NAME, trans('validate.exists')); + } + + $group->save(); + } + + public static function add(ServiceParkingGroup $group, Parking $parking) + { + + // 重複チェック + if (ServiceParkingGroupRelation::whereQrServiceParkingGroupId($group->id) + ->whereParkingManagementCode($parking->park_code) + ->exists() + ) { + ParamException::throw(ServiceParkingGroupRelation::COL_NAME_PARKING_MANAGEMENT_CODE, trans('validate.exists')); + } + + $relation = new ServiceParkingGroupRelation(); + $relation->qr_service_parking_group_id = $group->id; + $relation->parking_management_code = $parking->park_code; + $relation->save(); + + return $relation; + } + public static function remove(ServiceParkingGroup $group, Parking $parking) + { + $relation = ServiceParkingGroupRelation::whereQrServiceParkingGroupId($group->id) + ->whereParkingManagementCode($parking->park_code) + ->firstOrFail(); + + $relation->delete(); + } +} diff --git a/app/Models/HtpmsCustomer/Existing/Parking.php b/app/Models/HtpmsCustomer/Existing/Parking.php index 97c841a..9405ffa 100644 --- a/app/Models/HtpmsCustomer/Existing/Parking.php +++ b/app/Models/HtpmsCustomer/Existing/Parking.php @@ -3,6 +3,8 @@ namespace App\Models\HtpmsCustomer\Existing; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Facades\DB; class Parking extends Model { @@ -13,4 +15,20 @@ class Parking extends Model protected $table = 'tbl_park'; protected $fillable = []; // 参照専用 + protected $visible = [ + self::COL_NAME_PARKING_MANAGEMENT_CODE, + self::COL_NAME_PARKING_NAME, + ]; + + + public static function getBuilder(string $name = 'main'): Builder + { + $instance = new static(); + return DB::connection($instance->getConnectionName())->table(static::getTableName(), $name); + } + + public static function getTableName(): string + { + return (new static)->getTable(); + } } diff --git a/app/Models/HtpmsCustomer/QRService/ServiceParkingGroupHistory.php b/app/Models/HtpmsCustomer/QRService/ServiceParkingGroupHistory.php index 641dc13..76a11af 100644 --- a/app/Models/HtpmsCustomer/QRService/ServiceParkingGroupHistory.php +++ b/app/Models/HtpmsCustomer/QRService/ServiceParkingGroupHistory.php @@ -5,7 +5,7 @@ namespace App\Models\HtpmsCustomer\QRService; use App\Models\HtpmsCustomer\HtpmsCustomerHistoryModel; /** - * QRサービス券駐車場グループ + * QRサービス券駐車場グループ履歴 */ class ServiceParkingGroupHistory extends HtpmsCustomerHistoryModel { diff --git a/app/Repositories/QRServiceParkingGroupRepository.php b/app/Repositories/QRServiceParkingGroupRepository.php new file mode 100644 index 0000000..0e1aa65 --- /dev/null +++ b/app/Repositories/QRServiceParkingGroupRepository.php @@ -0,0 +1,95 @@ + + */ + public function get(array $condition): Collection + { + + $table = ServiceParkingGroup::getBuilder(static::TABLE_GROUP); + + $table->leftJoinSub(ServiceParkingGroupRelation::getBuilder(), static::TABLE_RELATION, function (JoinClause $join) { + $join->on( + $this->makeColumnName([static::TABLE_GROUP, ServiceParkingGroup::COL_NAME_ID]), + $this->makeColumnName([static::TABLE_RELATION, ServiceParkingGroupRelation::COL_NAME_QR_SERVICE_PARKING_GROUP_ID]) + ); + }); + $table->leftJoinSub(Parking::getBuilder(), static::TABLE_PARKING, function (JoinClause $join) { + $join->on( + $this->makeColumnName([static::TABLE_RELATION, ServiceParkingGroupRelation::COL_NAME_PARKING_MANAGEMENT_CODE]), + $this->makeColumnName([static::TABLE_PARKING, Parking::COL_NAME_PARKING_MANAGEMENT_CODE]) + ); + }); + + // -----検索条件 + // GROUP_ID + $this->where($table, $condition, static::CONDITION_QR_SERVICE_PARKING_GROUP_ID, $this->makeColumnName([static::TABLE_GROUP, ServiceParkingGroup::COL_NAME_ID])); + + // 名前 + $name = data_get($condition, static::CONDITION_NAME); + if ($name) { + $table->where($this->makeColumnName([static::TABLE_GROUP, ServiceParkingGroup::COL_NAME_NAME]), 'like', "%{$name}%"); + } + + // 駐車場管理コード + $this->where($table, $condition, static::CONDITION_PARKING_MANAGEMENT_CODE, $this->makeColumnName([ + static::TABLE_RELATION, + ServiceParkingGroupRelation::COL_NAME_PARKING_MANAGEMENT_CODE + ])); + + + $table->select($this->columns()); + + $main = DB::connection("htpms_customer")->table($table, "main"); + + // ソート + $this->sort($main, $condition); + + // リミット + $this->limit($main, $condition); + + + return QRServiceParkingGroupRepositoryData::makeList($main->get()); + } + + private function columns() + { + $group = static::TABLE_GROUP; + $relation = static::TABLE_RELATION; + $parking = static::TABLE_PARKING; + $columns = [ + $this->makeColumnNameForSelect([$group, ServiceParkingGroup::COL_NAME_ID]), + $this->makeColumnNameForSelect([$group, ServiceParkingGroup::COL_NAME_NAME]), + $this->makeColumnNameForSelect([$parking, Parking::COL_NAME_PARKING_MANAGEMENT_CODE], ColumnName::PARKING_MANAGEMENT_CODE), + $this->makeColumnNameForSelect([$parking, Parking::COL_NAME_PARKING_NAME], "parking_name"), + ]; + + return $columns; + } +} diff --git a/app/Repositories/QRServiceParkingGroupRepositoryData.php b/app/Repositories/QRServiceParkingGroupRepositoryData.php new file mode 100644 index 0000000..7ede304 --- /dev/null +++ b/app/Repositories/QRServiceParkingGroupRepositoryData.php @@ -0,0 +1,14 @@ +group(function () { // 運営会社ルート Route::middleware(RouteHelper::role([UserRole::CUSTOMER]))->group(function () { - RouteHelper::post('/role/switch/shop', App\Http\Controllers\Web\Auth\SwitcShophController::class); + RouteHelper::get('/parking/list', App\Http\Controllers\Web\Parking\ParkingListController::class); + RouteHelper::post('/role/switch/shop', App\Http\Controllers\Web\Auth\SwitchShopController::class); RouteHelper::post('/login-user/shop/register', App\Http\Controllers\Web\LoginUser\ShopRegisterController::class); RouteHelper::post('/shop/register', App\Http\Controllers\Web\Shop\ShopRegisterController::class); RouteHelper::get('/shop/list', App\Http\Controllers\Web\Shop\ShopListController::class); RouteHelper::post('/shop/deposit/charge', App\Http\Controllers\Web\Shop\DepositChargeController::class); - RouteHelper::post('/shop/config', App\Http\Controllers\Web\Shop\ShopConfigController::class); + RouteHelper::post('/shop/config', App\Http\Controllers\Web\Shop\Config\ShopConfigController::class); + RouteHelper::get('/qr-service/parking-group/list', App\Http\Controllers\Web\QRService\Group\QRServiceGroupListController::class); + RouteHelper::post('/qr-service/parking-group/register', App\Http\Controllers\Web\QRService\Group\QRServiceGroupRegisterController::class); + RouteHelper::post('/qr-service/parking-group/parking/add', App\Http\Controllers\Web\QRService\Group\QRServiceGroupAddController::class); + RouteHelper::post('/qr-service/parking-group/parking/remove', App\Http\Controllers\Web\QRService\Group\QRServiceGroupRemoveController::class); }); // 店舗ルート