From ef7dfcb5aae671e46e66773e3ca77e1ef1fa998b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 26 Aug 2024 17:11:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=80=BC=E5=88=97=E8=A1=A8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=B7=BB=E5=8A=A0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductAttrValueController.php | 94 ++++++++++++++ .../store_product/StoreProductController.php | 1 - .../StoreBranchProductAttrValueLists.php | 65 ++++++++++ .../StoreProductAttrValueLists.php | 11 +- .../StoreBranchProductAttrValueLogic.php | 115 ++++++++++++++++++ .../logic/store_product/StoreProductLogic.php | 46 ++----- .../StoreBranchProductAttrValueValidate.php | 82 +++++++++++++ 7 files changed, 374 insertions(+), 40 deletions(-) create mode 100644 app/admin/controller/store_branch_product_attr_value/StoreBranchProductAttrValueController.php create mode 100644 app/admin/lists/store_branch_product_attr_value/StoreBranchProductAttrValueLists.php create mode 100644 app/admin/logic/store_branch_product_attr_value/StoreBranchProductAttrValueLogic.php create mode 100644 app/admin/validate/store_branch_product_attr_value/StoreBranchProductAttrValueValidate.php diff --git a/app/admin/controller/store_branch_product_attr_value/StoreBranchProductAttrValueController.php b/app/admin/controller/store_branch_product_attr_value/StoreBranchProductAttrValueController.php new file mode 100644 index 000000000..0463e4d05 --- /dev/null +++ b/app/admin/controller/store_branch_product_attr_value/StoreBranchProductAttrValueController.php @@ -0,0 +1,94 @@ +dataLists(new StoreBranchProductAttrValueLists()); + } + + + /** + * @notes 添加门店商品属性值辅助表 + * @return \think\response\Json + * @author admin + * @date 2024/08/26 16:17 + */ + public function add() + { + $params = (new StoreBranchProductAttrValueValidate())->post()->goCheck('add'); + $result = StoreBranchProductAttrValueLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreBranchProductAttrValueLogic::getError()); + } + + + /** + * @notes 编辑门店商品属性值辅助表 + * @return \think\response\Json + * @author admin + * @date 2024/08/26 16:17 + */ + public function status() + { + $params =$this->request->post(); + $result = StoreBranchProductAttrValueLogic::status($params); + if (true === $result) { + return $this->success('变更成功', [], 1, 1); + } + } + + + /** + * @notes 删除门店商品属性值辅助表 + * @return \think\response\Json + * @author admin + * @date 2024/08/26 16:17 + */ + public function delete() + { + $params = (new StoreBranchProductAttrValueValidate())->post()->goCheck('delete'); + StoreBranchProductAttrValueLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取门店商品属性值辅助表详情 + * @return \think\response\Json + * @author admin + * @date 2024/08/26 16:17 + */ + public function detail() + { + $params = (new StoreBranchProductAttrValueValidate())->goCheck('detail'); + $result = StoreBranchProductAttrValueLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 62357641e..3a5d34ea7 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -47,7 +47,6 @@ class StoreProductController extends BaseAdminController if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(StoreProductLogic::getError()); } diff --git a/app/admin/lists/store_branch_product_attr_value/StoreBranchProductAttrValueLists.php b/app/admin/lists/store_branch_product_attr_value/StoreBranchProductAttrValueLists.php new file mode 100644 index 000000000..685f6259e --- /dev/null +++ b/app/admin/lists/store_branch_product_attr_value/StoreBranchProductAttrValueLists.php @@ -0,0 +1,65 @@ + ['product_id', 'store_id'], + ]; + } + + + /** + * @notes 获取门店商品属性值辅助表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/26 16:17 + */ + public function lists(): array + { + return StoreBranchProductAttrValue::where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item->unit_name = StoreProductUnit::where('id', $item->unit)->value('name'); + }) + ->toArray(); + } + + + /** + * @notes 获取门店商品属性值辅助表数量 + * @return int + * @author admin + * @date 2024/08/26 16:17 + */ + public function count(): int + { + return StoreBranchProductAttrValue::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php b/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php index 685ec1c04..1261f72a8 100644 --- a/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php +++ b/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\store_product_attr_value; use app\admin\lists\BaseAdminDataLists; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\lists\ListsSearchInterface; - +use app\common\model\store_product_unit\StoreProductUnit; /** * 商品属性值列表 @@ -43,11 +43,11 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear public function lists(): array { return StoreProductAttrValue::where($this->searchWhere) - ->field(['id', 'product_id']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() - ->toArray(); + ->select()->each(function ($item) { + $item->unit_name = StoreProductUnit::where('id', $item->unit)->value('name'); + })->toArray(); } @@ -61,5 +61,4 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear { return StoreProductAttrValue::where($this->searchWhere)->count(); } - -} \ No newline at end of file +} diff --git a/app/admin/logic/store_branch_product_attr_value/StoreBranchProductAttrValueLogic.php b/app/admin/logic/store_branch_product_attr_value/StoreBranchProductAttrValueLogic.php new file mode 100644 index 000000000..2941646df --- /dev/null +++ b/app/admin/logic/store_branch_product_attr_value/StoreBranchProductAttrValueLogic.php @@ -0,0 +1,115 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑门店商品属性值辅助表 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/26 16:17 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreBranchProductAttrValue::where('id', $params['id'])->update([ + + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + /** + * @notes 更新状态 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/26 16:17 + */ + public static function status(array $params): bool + { + Db::startTrans(); + try { + StoreBranchProductAttrValue::where('id', $params['id'])->update(['status' => $params['status']]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除门店商品属性值辅助表 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/26 16:17 + */ + public static function delete(array $params): bool + { + return StoreBranchProductAttrValue::destroy($params['id']); + } + + + /** + * @notes 获取门店商品属性值辅助表详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/26 16:17 + */ + public static function detail($params): array + { + return StoreBranchProductAttrValue::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 1907d88ac..87d7b22e4 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -14,6 +14,7 @@ use app\common\model\store_product_cate\StoreProductCate; use app\common\model\system_store\SystemStore; use app\common\model\system_store_storage\SystemStoreStorage; use Illuminate\Support\Facades\Log; +use support\exception\BusinessException; use think\facade\Db; use Webman\RedisQueue\Redis; @@ -41,7 +42,7 @@ class StoreProductLogic extends BaseLogic 'store_name' => $params['store_name'], 'image' => $params['image'], 'store_info' => $params['store_info'] ?? '', - 'bar_code' =>$params['product_arr'][0] ?? '', + 'bar_code' =>$params['product_arr'][0]['bar_code'] ?? '', 'cate_id' => $params['cate_id'], 'unit' => $params['product_arr'][0]['unit'], 'stock' => 0, @@ -72,31 +73,11 @@ class StoreProductLogic extends BaseLogic (new StoreProductAttrValue())->saveAll($arr); Db::commit(); - if ($params['is_store_all'] == 1) { - $store_arr = SystemStore::where('is_show', 1)->column('id'); - foreach ($store_arr as $store_id) { - if ($store_id != 5) { - Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]); - } - } - } else { - if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { - foreach ($params['store_arr'] as $key => $store_id) { - if ($store_id != 5) { - Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]); - } - } - } - } - if (getenv('STORE_ID')) { - Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => getenv('STORE_ID'), 'stock_type' => 1, 'admin_id' => Request()->adminId]); - } - return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + d($e); + throw new BusinessException($e->getMessage()); } } @@ -295,7 +276,6 @@ class StoreProductLogic extends BaseLogic 'top_cate_id' => $dealCate['top_cate_id'], 'two_cate_id' => $dealCate['two_cate_id'], 'price' => $find['price'], - // 'cost' => $find['cost'], //v1.0 'cost' => $find['cost'], 'purchase' => $find['purchase'], 'vip_price' => $find['vip_price'], @@ -310,14 +290,14 @@ class StoreProductLogic extends BaseLogic 'rose' => $find['rose'], ]; $branch = StoreBranchProduct::create($product); - $arr = [ - 'product_id' => $product_arr['id'], - 'store_id' => $store_id, - 'sales' => 0, - 'type' => 0, - 'bar_code' => $find['bar_code'] - ]; - StoreBranchProductAttrValue::create($arr); + $select=StoreProductAttrValue::where('product_id', $find['id'])->select()->toArray(); + + + foreach($select as $k=>&$v){ + $v['store_id']=$store_id; + unset($v['id']); + } + (new StoreBranchProductAttrValue())->saveAll($select); return $branch; } diff --git a/app/admin/validate/store_branch_product_attr_value/StoreBranchProductAttrValueValidate.php b/app/admin/validate/store_branch_product_attr_value/StoreBranchProductAttrValueValidate.php new file mode 100644 index 000000000..58f6c4602 --- /dev/null +++ b/app/admin/validate/store_branch_product_attr_value/StoreBranchProductAttrValueValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return StoreBranchProductAttrValueValidate + * @author admin + * @date 2024/08/26 16:17 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return StoreBranchProductAttrValueValidate + * @author admin + * @date 2024/08/26 16:17 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return StoreBranchProductAttrValueValidate + * @author admin + * @date 2024/08/26 16:17 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreBranchProductAttrValueValidate + * @author admin + * @date 2024/08/26 16:17 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file