From 84fde23c252ce98887173e6eedabeb04e3a3725c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 3 Dec 2024 16:14:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E6=B7=BB=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E7=BB=84=E6=8A=A5=E4=BB=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 StoreProductGroupPriceController 控制器 - 新增 StoreProductGroupPriceLists 列表类 - 新增 StoreProductGroupPriceLogic 逻辑类 - 新增 StoreProductGroupPriceValidate 验证器 - 新增 StoreProductGroupPrice 模型 --- .../StoreProductGroupPriceController.php | 93 +++++++++++++ .../StoreProductGroupPriceLists.php | 70 ++++++++++ .../StoreProductGroupPriceLogic.php | 124 ++++++++++++++++++ .../StoreProductGroupPriceValidate.php | 82 ++++++++++++ .../StoreProductGroupPrice.php | 22 ++++ 5 files changed, 391 insertions(+) create mode 100644 app/admin/controller/store_product_group_price/StoreProductGroupPriceController.php create mode 100644 app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php create mode 100644 app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php create mode 100644 app/admin/validate/store_product_group_price/StoreProductGroupPriceValidate.php create mode 100644 app/common/model/store_product_group_price/StoreProductGroupPrice.php diff --git a/app/admin/controller/store_product_group_price/StoreProductGroupPriceController.php b/app/admin/controller/store_product_group_price/StoreProductGroupPriceController.php new file mode 100644 index 000000000..6f969d650 --- /dev/null +++ b/app/admin/controller/store_product_group_price/StoreProductGroupPriceController.php @@ -0,0 +1,93 @@ +dataLists(new StoreProductGroupPriceLists()); + } + + + /** + * @notes 添加分组报价 + * @return \think\response\Json + * @author admin + * @date 2024/12/02 15:42 + */ + public function add() + { + $params = (new StoreProductGroupPriceValidate())->post()->goCheck('add'); + $result = StoreProductGroupPriceLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreProductGroupPriceLogic::getError()); + } + + + /** + * @notes 编辑分组报价 + * @return \think\response\Json + * @author admin + * @date 2024/12/02 15:42 + */ + public function edit() + { + $params = $this->request->post(); + $result = StoreProductGroupPriceLogic::edit($params); + return $this->success('编辑成功', [], 1, 1); + + } + + + /** + * @notes 删除分组报价 + * @return \think\response\Json + * @author admin + * @date 2024/12/02 15:42 + */ + public function delete() + { + $params = (new StoreProductGroupPriceValidate())->post()->goCheck('delete'); + StoreProductGroupPriceLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取分组报价详情 + * @return \think\response\Json + * @author admin + * @date 2024/12/02 15:42 + */ + public function detail() + { + $params = $this->request->get(); + $result = StoreProductGroupPriceLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php b/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php new file mode 100644 index 000000000..db95f69cf --- /dev/null +++ b/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php @@ -0,0 +1,70 @@ + ['product_id'], + ]; + } + + + /** + * @notes 获取分组报价列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/12/02 15:42 + */ + public function lists(): array + { + return StoreProduct::where($this->searchWhere)->limit($this->limitOffset, $this->limitLength) + ->field('id,store_name,purchase,cost,vip_price,price,unit') + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item['lists'] =StoreProductGroupPrice::where('product_id',$item['id'])->field('id,group_id,price') + ->select()->each(function ($item_two){ + $item_two['group_name']=UserShip::where('id',$item_two['group_id'])->value('title'); + }); + }) + ->toArray(); + } + + + /** + * @notes 获取分组报价数量 + * @return int + * @author admin + * @date 2024/12/02 15:42 + */ + public function count(): int + { + return StoreProduct::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php b/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php new file mode 100644 index 000000000..a337b3d39 --- /dev/null +++ b/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php @@ -0,0 +1,124 @@ +getMessage()); + } + } + + + /** + * @notes 编辑分组报价 + * @param array $params + * @return bool + * @author admin + * @date 2024/12/02 15:42 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + foreach($params as $k=>$v){ + if($v['group_price_id']==0 && !empty($v['price'])){ + StoreProductGroupPrice::create([ + 'product_id'=>$v['product_id'], + 'group_id'=>$v['id'], + 'price_type'=>$v['price_type'], + 'base_rate'=>$v['base_rate'], + 'price'=>$v['price'], + ]); + }elseif($v['group_price_id']>0 && !empty($v['price'])){ + StoreProductGroupPrice::where('id', $v['group_price_id'])->update([ + 'price_type'=>$v['price_type'], + 'base_rate'=>$v['base_rate'], + 'price'=>$v['price'], + ]); + } + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除分组报价 + * @param array $params + * @return bool + * @author admin + * @date 2024/12/02 15:42 + */ + public static function delete(array $params): bool + { + return StoreProductGroupPrice::destroy($params['id']); + } + + + /** + * @notes 获取分组报价详情 + * @param $params + * @return array + * @author admin + * @date 2024/12/02 15:42 + */ + public static function detail($params): array + { + $arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray(); + $purchase=StoreProduct::where('id',$params['product_id'])->value('purchase'); + $arr_two=UserShip::where('id','>',4)->select()->toArray(); + foreach ($arr_two as $k=>$v){ + $arr_two[$k]['purchase']=$purchase; + $arr_two[$k]['product_id']=$params['product_id']; + $arr_two[$k]['group_price_id']=0; + foreach ($arr as $k_two=>$v_two){ + if($v['id']==$v_two['group_id']){ + $arr_two[$k]['price_type']=$v_two['price_type']; + $arr_two[$k]['base_rate']=$v_two['base_rate']; + $arr_two[$k]['price']=$v_two['price']; + $arr_two[$k]['group_price_id']=$v_two['id']; + } + } + } + return $arr_two; + } +} \ No newline at end of file diff --git a/app/admin/validate/store_product_group_price/StoreProductGroupPriceValidate.php b/app/admin/validate/store_product_group_price/StoreProductGroupPriceValidate.php new file mode 100644 index 000000000..b32c30433 --- /dev/null +++ b/app/admin/validate/store_product_group_price/StoreProductGroupPriceValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return StoreProductGroupPriceValidate + * @author admin + * @date 2024/12/02 15:42 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return StoreProductGroupPriceValidate + * @author admin + * @date 2024/12/02 15:42 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return StoreProductGroupPriceValidate + * @author admin + * @date 2024/12/02 15:42 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductGroupPriceValidate + * @author admin + * @date 2024/12/02 15:42 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/store_product_group_price/StoreProductGroupPrice.php b/app/common/model/store_product_group_price/StoreProductGroupPrice.php new file mode 100644 index 000000000..71cfe9841 --- /dev/null +++ b/app/common/model/store_product_group_price/StoreProductGroupPrice.php @@ -0,0 +1,22 @@ +