From 37fa6d93c6f14e872411a2446fc6d076978e0824 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 31 May 2024 15:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AF=B4=E6=98=8E=EF=BC=9A?= =?UTF-8?q?=20=E7=A7=BB=E9=99=A4=20'task'=20=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=E4=BB=A5=E9=81=BF=E5=85=8D=E6=BD=9C=E5=9C=A8=E7=9A=84=E6=B7=B7?= =?UTF-8?q?=E6=B7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreCategoryController.php | 95 ++++++++++++++++ .../StoreProductAttrValueController.php | 95 ++++++++++++++++ .../store_category/StoreCategoryLists.php | 65 +++++++++++ .../lists/store_product/StoreProductLists.php | 14 ++- .../StoreProductAttrValueLists.php | 65 +++++++++++ .../store_category/StoreCategoryLogic.php | 102 ++++++++++++++++++ .../logic/store_product/StoreProductLogic.php | 60 ++++++++++- .../StoreProductAttrValueLogic.php | 94 ++++++++++++++++ .../store_category/StoreCategoryValidate.php | 86 +++++++++++++++ .../StoreProductAttrValueValidate.php | 82 ++++++++++++++ app/common/cache/AdminAccountSafeCache.php | 3 +- .../model/store_category/StoreCategory.php | 22 ++++ .../StoreProductAttrValue.php | 22 ++++ .../store_product_unit/StoreProductUnit.php | 22 ++++ app/functions.php | 14 +++ 15 files changed, 832 insertions(+), 9 deletions(-) create mode 100644 app/admin/controller/store_category/StoreCategoryController.php create mode 100644 app/admin/controller/store_product_attr_value/StoreProductAttrValueController.php create mode 100644 app/admin/lists/store_category/StoreCategoryLists.php create mode 100644 app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php create mode 100644 app/admin/logic/store_category/StoreCategoryLogic.php create mode 100644 app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php create mode 100644 app/admin/validate/store_category/StoreCategoryValidate.php create mode 100644 app/admin/validate/store_product_attr_value/StoreProductAttrValueValidate.php create mode 100644 app/common/model/store_category/StoreCategory.php create mode 100644 app/common/model/store_product_attr_value/StoreProductAttrValue.php create mode 100644 app/common/model/store_product_unit/StoreProductUnit.php diff --git a/app/admin/controller/store_category/StoreCategoryController.php b/app/admin/controller/store_category/StoreCategoryController.php new file mode 100644 index 000000000..381ab139a --- /dev/null +++ b/app/admin/controller/store_category/StoreCategoryController.php @@ -0,0 +1,95 @@ +dataLists(new StoreCategoryLists()); + } + + + /** + * @notes 添加商品分类 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function add() + { + $params = (new StoreCategoryValidate())->post()->goCheck('add'); + $result = StoreCategoryLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreCategoryLogic::getError()); + } + + + /** + * @notes 编辑商品分类 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function edit() + { + $params = (new StoreCategoryValidate())->post()->goCheck('edit'); + $result = StoreCategoryLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreCategoryLogic::getError()); + } + + + /** + * @notes 删除商品分类 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function delete() + { + $params = (new StoreCategoryValidate())->post()->goCheck('delete'); + StoreCategoryLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品分类详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function detail() + { + $params = (new StoreCategoryValidate())->goCheck('detail'); + $result = StoreCategoryLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/store_product_attr_value/StoreProductAttrValueController.php b/app/admin/controller/store_product_attr_value/StoreProductAttrValueController.php new file mode 100644 index 000000000..a7d009411 --- /dev/null +++ b/app/admin/controller/store_product_attr_value/StoreProductAttrValueController.php @@ -0,0 +1,95 @@ +dataLists(new StoreProductAttrValueLists()); + } + + + /** + * @notes 添加商品属性值 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function add() + { + $params = (new StoreProductAttrValueValidate())->post()->goCheck('add'); + $result = StoreProductAttrValueLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreProductAttrValueLogic::getError()); + } + + + /** + * @notes 编辑商品属性值 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function edit() + { + $params = (new StoreProductAttrValueValidate())->post()->goCheck('edit'); + $result = StoreProductAttrValueLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreProductAttrValueLogic::getError()); + } + + + /** + * @notes 删除商品属性值 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function delete() + { + $params = (new StoreProductAttrValueValidate())->post()->goCheck('delete'); + StoreProductAttrValueLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品属性值详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function detail() + { + $params = (new StoreProductAttrValueValidate())->goCheck('detail'); + $result = StoreProductAttrValueLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/store_category/StoreCategoryLists.php b/app/admin/lists/store_category/StoreCategoryLists.php new file mode 100644 index 000000000..614a72197 --- /dev/null +++ b/app/admin/lists/store_category/StoreCategoryLists.php @@ -0,0 +1,65 @@ + ['name','pid'], + ]; + } + + + /** + * @notes 获取商品分类列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 11:33 + */ + public function lists(): array + { + return StoreCategory::where($this->searchWhere) + ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品分类数量 + * @return int + * @author admin + * @date 2024/05/31 11:33 + */ + public function count(): int + { + return StoreCategory::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 79b94fbdd..bab5ce954 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -6,7 +6,8 @@ namespace app\admin\lists\store_product; use app\admin\lists\BaseAdminDataLists; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; - +use app\common\model\store_category\StoreCategory; +use app\common\model\store_product_unit\StoreProductUnit; /** * 商品列表列表 @@ -43,10 +44,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function lists(): array { return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_name', 'cate_id', 'price', 'unit_name', 'sales', 'stock', 'is_show', 'is_new', 'add_time', 'is_postage', 'is_del', 'cost']) + ->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function ($item) { + $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); + $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); + return $item; + }) ->toArray(); } @@ -61,5 +66,4 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa { return StoreProduct::where($this->searchWhere)->count(); } - -} \ No newline at end of file +} diff --git a/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php b/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php new file mode 100644 index 000000000..685ec1c04 --- /dev/null +++ b/app/admin/lists/store_product_attr_value/StoreProductAttrValueLists.php @@ -0,0 +1,65 @@ + ['product_id'], + ]; + } + + + /** + * @notes 获取商品属性值列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 14:10 + */ + public function lists(): array + { + return StoreProductAttrValue::where($this->searchWhere) + ->field(['id', 'product_id']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品属性值数量 + * @return int + * @author admin + * @date 2024/05/31 14:10 + */ + public function count(): int + { + return StoreProductAttrValue::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/store_category/StoreCategoryLogic.php b/app/admin/logic/store_category/StoreCategoryLogic.php new file mode 100644 index 000000000..ba0b1c08b --- /dev/null +++ b/app/admin/logic/store_category/StoreCategoryLogic.php @@ -0,0 +1,102 @@ + $params['pid'], + 'name' => $params['name'], + 'data' => $params['data'], + 'pic' => $params['pic'], + 'sort' => $params['sort'] + ]); + + 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/05/31 11:33 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreCategory::where('id', $params['id'])->update([ + 'pid' => $params['pid'], + 'name' => $params['name'], + 'data' => $params['data'], + 'pic' => $params['pic'], + 'sort' => $params['sort'] + ]); + + 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/05/31 11:33 + */ + public static function delete(array $params): bool + { + return StoreCategory::destroy($params['id']); + } + + + /** + * @notes 获取商品分类详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 11:33 + */ + public static function detail($params): array + { + return StoreCategory::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 1e8c2fdc5..927b33641 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -5,6 +5,8 @@ namespace app\admin\logic\store_product; use app\common\model\store_product\StoreProduct; use app\common\logic\BaseLogic; +use app\common\model\store_category\StoreCategory; +use app\common\model\store_product_attr_value\StoreProductAttrValue; use think\facade\Db; @@ -28,9 +30,33 @@ class StoreProductLogic extends BaseLogic { Db::startTrans(); try { - StoreProduct::create([ - 'store_name' => $params['store_name'] + $data = [ + 'store_name' => $params['store_name'], + 'image' => $params['image'], + 'bar_code' => $params['bar_code'] ?? '', + 'cate_id' => $params['cate_id'], + 'unit' => $params['unit'], + 'stock' => $params['stock'], + 'cost' => $params['cost'], + 'purchase' => $params['purchase'], + 'rose' => $params['rose'], + ]; + $rose_price = bcmul($params['cost'], $params['rose'], 2); + $data['price'] = bcadd($params['cost'], $rose_price, 2); + $res = StoreProduct::create($data); + StoreProductAttrValue::create([ + "bar_code" => $params["bar_code"] ?? '', + "image" => $params["image"] ?? '', + "cost" => $params['cost'], + "purchase" => $params['purchase'], + "unit" => $params["unit"], + "price" => $data['price'], + "stock" => $params['stock'], + "product_id" => $res['id'], + "unique" => setUnique($res['id'], '', 0), + 'sales' => 0, ]); + StoreCategory::where('id', $params['cate_id'])->inc('three')->update(); Db::commit(); return true; @@ -52,7 +78,12 @@ class StoreProductLogic extends BaseLogic public static function edit(array $params): bool { Db::startTrans(); + $StoreProduct = StoreProduct::where('id', $params['id'])->find(); try { + if ($StoreProduct['cate_id'] != $params['cate_id']) { + StoreCategory::where('id', $params['cate_id'])->inc('three')->update(); + StoreCategory::where('id', $StoreProduct['cate_id'])->dec('three')->update(); + } StoreProduct::where('id', $params['id'])->update([ 'store_name' => $params['store_name'] ]); @@ -91,4 +122,27 @@ class StoreProductLogic extends BaseLogic { return StoreProduct::findOrEmpty($params['id'])->toArray(); } -} \ No newline at end of file + + /** + * 更新商品分类 + */ + public static function updateGoodsclass($id, $type = 0) + { + $pid = StoreCategory::where('id', $id)->value('pid'); + if ($pid) { + $goodsclass = StoreCategory::where('id', $pid)->field('pid,children')->find(); + if ($goodsclass) { + if (count($goodsclass['children']) >= 1) { + if (!in_array($id, $goodsclass['children'])) { + $arr = $goodsclass['children']; + array_push($arr, $id); + StoreCategory::where('id', $pid)->update(['children' => $arr]); + if ($goodsclass['pid'] != 0 && $type == 0) { + self::updateGoodsclass($pid, 1); + } + } + } + } + } + } +} diff --git a/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php b/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php new file mode 100644 index 000000000..32f3370dd --- /dev/null +++ b/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php @@ -0,0 +1,94 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑商品属性值 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 14:10 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreProductAttrValue::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/05/31 14:10 + */ + public static function delete(array $params): bool + { + return StoreProductAttrValue::destroy($params['id']); + } + + + /** + * @notes 获取商品属性值详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 14:10 + */ + public static function detail($params): array + { + return StoreProductAttrValue::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/store_category/StoreCategoryValidate.php b/app/admin/validate/store_category/StoreCategoryValidate.php new file mode 100644 index 000000000..036e3411f --- /dev/null +++ b/app/admin/validate/store_category/StoreCategoryValidate.php @@ -0,0 +1,86 @@ + 'require', + 'pid' => 'require', + 'name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'pid' => '所属ID', + 'name' => '分类名称', + ]; + + + /** + * @notes 添加场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneAdd() + { + return $this->only(['pid','name']); + } + + + /** + * @notes 编辑场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneEdit() + { + return $this->only(['id','pid','name']); + } + + + /** + * @notes 删除场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/store_product_attr_value/StoreProductAttrValueValidate.php b/app/admin/validate/store_product_attr_value/StoreProductAttrValueValidate.php new file mode 100644 index 000000000..5d0e7e58a --- /dev/null +++ b/app/admin/validate/store_product_attr_value/StoreProductAttrValueValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/cache/AdminAccountSafeCache.php b/app/common/cache/AdminAccountSafeCache.php index c6a8530d4..e354867f2 100644 --- a/app/common/cache/AdminAccountSafeCache.php +++ b/app/common/cache/AdminAccountSafeCache.php @@ -15,7 +15,8 @@ class AdminAccountSafeCache extends BaseCache { parent::__construct(); $ip = \request()->getLocalIp(); - $this->key = $this->tagName . $ip; + // $this->key = $this->tagName . $ip; + $this->key = 'admin_' . $ip; } /** diff --git a/app/common/model/store_category/StoreCategory.php b/app/common/model/store_category/StoreCategory.php new file mode 100644 index 000000000..d4ed4ab05 --- /dev/null +++ b/app/common/model/store_category/StoreCategory.php @@ -0,0 +1,22 @@ +