From fc9eff478e26b5f96a77adb776afe700eb5965f8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 1 Jun 2024 15:32:11 +0800 Subject: [PATCH] =?UTF-8?q?(=E4=BD=A0=E7=9A=84=E6=8F=90=E4=BA=A4=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=EF=BC=9A=20=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=9D=A5=E6=BA=90=E6=9F=A5=E8=AF=A2=E9=97=A8=E5=BA=97=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system_store/SystemStoreController.php | 11 +++ .../lists/store_product/StoreProductLists.php | 8 +- .../system_store/SystemStoreSourceLists.php | 76 ++++++++++++++++ .../logic/store_product/StoreProductLogic.php | 87 ++++++++++++------- .../SystemStoreStorage.php | 22 +++++ app/queue/redis/CopyProductSend.php | 34 ++++++++ 6 files changed, 206 insertions(+), 32 deletions(-) create mode 100644 app/admin/lists/system_store/SystemStoreSourceLists.php create mode 100644 app/common/model/system_store_storage/SystemStoreStorage.php create mode 100644 app/queue/redis/CopyProductSend.php diff --git a/app/admin/controller/system_store/SystemStoreController.php b/app/admin/controller/system_store/SystemStoreController.php index c01ef820e..bb4badff3 100644 --- a/app/admin/controller/system_store/SystemStoreController.php +++ b/app/admin/controller/system_store/SystemStoreController.php @@ -5,6 +5,7 @@ namespace app\admin\controller\system_store; use app\admin\controller\BaseAdminController; use app\admin\lists\system_store\SystemStoreLists; +use app\admin\lists\system_store\SystemStoreSourceLists; use app\admin\logic\system_store\SystemStoreLogic; use app\admin\validate\system_store\SystemStoreValidate; @@ -28,6 +29,16 @@ class SystemStoreController extends BaseAdminController { return $this->dataLists(new SystemStoreLists()); } + /** + * @notes 根据商品源获取门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function source_product_store_lists() + { + return $this->dataLists(new SystemStoreSourceLists()); + } /** diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index bab5ce954..08f1a8c93 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -8,6 +8,7 @@ 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; +use app\common\model\system_store\SystemStore; /** * 商品列表列表 @@ -44,12 +45,17 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function lists(): array { return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase']) + ->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','store_id','bar_code']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->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'); + if($item['store_id'] == 0){ + $item['system_store_name'] = '平台'; + }else{ + $item['system_store_name'] = '门店:'.SystemStore::where('id', $item['store_id'])->value('name'); + } return $item; }) ->toArray(); diff --git a/app/admin/lists/system_store/SystemStoreSourceLists.php b/app/admin/lists/system_store/SystemStoreSourceLists.php new file mode 100644 index 000000000..169264c14 --- /dev/null +++ b/app/admin/lists/system_store/SystemStoreSourceLists.php @@ -0,0 +1,76 @@ + ['name', 'phone'], + ]; + } + + + /** + * @notes 获取门店列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 17:45 + */ + public function lists(): array + { + $store_arr=StoreProduct::where('source_id',$this->request->get('product_id'))->column('store_id'); + if($store_arr){ + $this->searchWhere[]=['id', 'in', $store_arr]; + }else{ + return []; + } + return SystemStore::where($this->searchWhere) + ->field(['id', 'name', 'phone', 'detailed_address', 'image']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取门店数量 + * @return int + * @author admin + * @date 2024/05/31 17:45 + */ + public function count(): int + { + if($this->searchWhere){ + return SystemStore::where($this->searchWhere)->count(); + }else{ + return 0; + } + } + +} \ 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 b11f3d0ac..456bc4d93 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -9,8 +9,9 @@ use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_attr_value\StoreProductAttrValue; +use app\common\model\system_store\SystemStore; use think\facade\Db; - +use Webman\RedisQueue\Redis; /** * 商品列表逻辑 @@ -61,6 +62,17 @@ class StoreProductLogic extends BaseLogic StoreCategory::where('id', $params['cate_id'])->inc('three')->update(); Db::commit(); + + if ($params['is_store_all'] == 1) { + $store_arr = SystemStore::where('is_show', 1)->column('id'); + Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]); + } else { + if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { + Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]); + } + } + + return true; } catch (\Exception $e) { Db::rollback(); @@ -159,36 +171,49 @@ class StoreProductLogic extends BaseLogic /** * 复制商品到门店 */ - public static function copy($id,$store_id){ - $find= StoreProduct::where('id',$id)->findOrEmpty(); - $store_find= StoreProduct::where(['source_id',$id,'store_id'=>$store_id])->findOrEmpty(); - if($find && !$store_find){ - $attr_value=StoreProductAttrValue::where('product_id',$id)->findOrEmpty(); - $res=StoreProduct::create($find); - $product=[ - 'product_id'=>$res['id'], - 'image'=>$res['image'], - 'store_name'=>$res['store_name'], - 'store_info'=>$res['store_info'], - 'keyword'=>$res['keyword'], - 'bar_code'=>$res['bar_code'], - 'cate_id'=>$res['cate_id'], - 'store_id'=>$store_id, - 'sales'=>$res['sales'], - 'stock'=>$res['stock'], - ]; - StoreBranchProduct::create($product); - $arr=[ - 'product_id'=>$id, - 'store_id'=>$store_id, - 'unique'=>$attr_value['unique'], - 'sales'=>0, - 'stock'=>0, - 'type'=>0, - 'bar_code'=>$attr_value['bar_code'] - ]; - StoreBranchProductAttrValue::create($arr); + public static function copy($id, $store_id) + { + $find = StoreProduct::where('id', $id)->findOrEmpty()->toArray(); + $store_find = StoreProduct::where(['source_id' => $id, 'store_id' => $store_id])->findOrEmpty()->toArray(); + if ($find && !$store_find) { + $attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty(); + Db::startTrans(); + try { + unset($find['create_time'], $find['update_time'], $find['id'],$find['stock']); + $find['store_id'] = $store_id; + $find['source_id'] = $id; + $res = StoreProduct::create($find); + $product = [ + 'product_id' => $res['id'], + 'image' => $res['image'], + 'store_name' => $res['store_name'], + 'store_info' => $res['store_info'], + 'keyword' => $res['keyword'], + 'bar_code' => $res['bar_code'], + 'cate_id' => $res['cate_id'], + 'store_id' => $store_id, + 'sales' => 0, + 'stock' =>0, + ]; + StoreBranchProduct::create($product); + $arr = [ + 'product_id' => $id, + 'store_id' => $store_id, + 'unique' => setUnique($res['id'], '', 0), + 'sales' => 0, + 'stock' => 0, + 'type' => 0, + 'bar_code' => $attr_value['bar_code'] + ]; + StoreBranchProductAttrValue::create($arr); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + d($e); + self::setError($e->getMessage()); + return false; + } } - } } diff --git a/app/common/model/system_store_storage/SystemStoreStorage.php b/app/common/model/system_store_storage/SystemStoreStorage.php new file mode 100644 index 000000000..0aa7c363a --- /dev/null +++ b/app/common/model/system_store_storage/SystemStoreStorage.php @@ -0,0 +1,22 @@ + $id) { + StoreProductLogic::copy($data['product_id'],$id); + } + } + public function onConsumeFailure(\Throwable $e, $package) + { + $package['max_attempts']=0; + Log::error('复制商品失败product_id:'.$package['data']['product_id']); + return $package; + } +} \ No newline at end of file