From 4c366096bc3664f40e83aaae150865974c963857 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Nov 2023 09:55:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=91=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Common.php | 2 +- .../api/store/product/CloudWarehouse.php | 110 +++++++++++------- .../api/store/product/StoreMicro.php | 6 +- app/listener/ProductCreate copy.php | 58 +++++++++ app/listener/ProductCreate.php | 52 +++++---- 5 files changed, 156 insertions(+), 72 deletions(-) create mode 100644 app/listener/ProductCreate copy.php diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 951f9fcc..9ff9ec33 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -496,7 +496,7 @@ class Common extends BaseController //获取云店铺 public function get_cloud_shop($street_code){ //更新查询镇级供应链店铺 - $typeTownSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownSupplyChain'])->value('mer_type_id'); + // $typeTownSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownSupplyChain'])->value('mer_type_id'); /* $find=DB::name('merchant') ->alias('m') diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index adaf906e..edc7c85d 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -44,51 +44,71 @@ class CloudWarehouse extends BaseController * 指定类型的云仓商品列表 * @return mixed */ - public function index() - { - // 除了市级供应链都可以查询 - $typeIdArray = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->column('mer_type_id'); - $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword','page_num']); - $search = [ - // 'street_id' => $params['street_code'], - 'type_id' => $typeIdArray ?? [], - 'status' => 1, - 'is_del' => 0, - 'mer_state' => 1, - ]; - if (!empty($params['category_id'])) { - $search['category_id'] = $params['category_id']; - } - $merchantIds = $this->merchantDao->search($search)->column('mer_id'); - [$page, $limit] = $this->getPage(); - if(isset($params['page_num'])&&$params['page_num']!=''){ - $page=$params['page_num']; - } - if (empty($merchantIds)) { - return app('json')->success(['count' => 0, 'list' => []]); - } - // 隐藏镇级云仓 - // $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); - // $entryWhere = [ - // 'street_id' => $params['street_code'], - // 'type_id' => $typeCloudWarehouseId, - // 'status' => 1, - // 'is_del' => 0, - // 'mer_state' => 1, - // ]; - // if (!empty($params['category_id'])) { - // $entryWhere['category_id'] = $params['category_id']; - // } - // $where['entry_mer_id'] = $this->merchantDao->search($entryWhere)->value('mer_id'); + // public function index() + // { + // // 除了市级供应链都可以查询 + // $typeIdArray = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->column('mer_type_id'); + // $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword','page_num']); + // $search = [ + // // 'street_id' => $params['street_code'], + // 'type_id' => $typeIdArray ?? [], + // 'status' => 1, + // 'is_del' => 0, + // 'mer_state' => 1, + // ]; + // if (!empty($params['category_id'])) { + // $search['category_id'] = $params['category_id']; + // } + // $merchantIds = $this->merchantDao->search($search)->column('mer_id'); + // [$page, $limit] = $this->getPage(); + // if(isset($params['page_num'])&&$params['page_num']!=''){ + // $page=$params['page_num']; + // } + // if (empty($merchantIds)) { + // return app('json')->success(['count' => 0, 'list' => []]); + // } + // // 隐藏镇级云仓 + // // $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); + // // $entryWhere = [ + // // 'street_id' => $params['street_code'], + // // 'type_id' => $typeCloudWarehouseId, + // // 'status' => 1, + // // 'is_del' => 0, + // // 'mer_state' => 1, + // // ]; + // // if (!empty($params['category_id'])) { + // // $entryWhere['category_id'] = $params['category_id']; + // // } + // // $where['entry_mer_id'] = $this->merchantDao->search($entryWhere)->value('mer_id'); - $where['entry_mer_id'] = 0; - $where['keyword'] = $params['keyword']; - $where['mer_ids'] = $merchantIds; - $where['product_type'] = $params['product_type']; - $where['is_gift_bag'] = 0; - $where['order'] = $params['order'] ?: 'sort'; - $products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false); - return app('json')->success($products); - } + // $where['entry_mer_id'] = 0; + // $where['keyword'] = $params['keyword']; + // $where['mer_ids'] = $merchantIds; + // $where['product_type'] = $params['product_type']; + // $where['is_gift_bag'] = 0; + // $where['order'] = $params['order'] ?: 'sort'; + // $products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false); + // return app('json')->success($products); + // } + /** + * 云仓商品列表 + * @return mixed + */ + public function index($street_code,$page_num=1){ + $cloud_product=Db::name('cloud_product')->where('street_code',$street_code)->where('status',1)->page($page_num)->select(); + if(!$cloud_product){ + return app('json')->success(['count'=>0,'list'=>[]]); + } + $where=[ + 'is_show'=>1, + 'is_used'=>1, + 'status'=>1, + 'is_del'=>0, + 'mer_status'=>1, + ]; + $count=Db::name('cloud_product')->where('street_code',$street_code)->where('status',1)->count(); + $select=Db::name('store_product')->whereIn('product_id',$cloud_product)->where($where)->select(); + return app('json')->success(['count'=>$count,'list'=>$select]); + } } \ No newline at end of file diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php index d2ec7752..da7eab0b 100644 --- a/app/controller/api/store/product/StoreMicro.php +++ b/app/controller/api/store/product/StoreMicro.php @@ -89,9 +89,9 @@ class StoreMicro extends BaseController if ($find) { $exist = Db::name('store_product')->where('source_library_id', $id)->where('mer_id', $mer_id)->find(); - // if ($exist) { - // return app('json')->fail('已经导入过该商品了'); - // } + if ($exist) { + return app('json')->fail('已经导入过该商品了'); + } $find['attrValue']=[ ['image'=>$find['image'],'price'=>$price,'cost'=>$find['cost'],'ot_price'=>$find['ot_price'], 'svip_price'=>0,'stock'=>$stock,'bar_code'=>$find['bar_code'],'weight'=>0,'volume'=>0,'detail'=>'' diff --git a/app/listener/ProductCreate copy.php b/app/listener/ProductCreate copy.php new file mode 100644 index 00000000..97283db5 --- /dev/null +++ b/app/listener/ProductCreate copy.php @@ -0,0 +1,58 @@ +where('status', 1)->where('is_del', 0)->where('mer_id', $product['mer_id'])->find(); + if (empty($merchant)) { + return false; + } + // 根据支持同步到云商的商户进行同步操作 + $syncMerArray = Db::name('MerchantType')->where('is_sync_prod', 1)->column('mer_type_id'); + if (!in_array($merchant['type_id'], $syncMerArray)) { + return false; + } + + $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); + $typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id'); + if ($merchant['type_id'] == $typePlatformId || $merchant['type_id'] == $typeCloudWarehouseId) { + return false; + } + + //查询市级云仓 + $cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypePlatform)->find(); + if ($cityMerchant == null) { + return false; + } + $product_id = Db::name('store_product')->where('mer_id', $cityMerchant['mer_id'])->where('bar_code', $product['bar_code'])->value('product_id'); + if ($product_id) { + return false; + } + + $data['mer_id'] = $cityMerchant['mer_id']; + $data['status'] = $cityMerchant['is_audit'] ? 0 : 1; + $data['mer_status'] = ($cityMerchant['is_del'] || !$cityMerchant['mer_state'] || !$cityMerchant['status']) ? 0 : 1; + $data['rate'] = 3; + // $typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id'); + // $productType = $cityMerchant['type_id'] == $typeSupplyChainId ? 98 : 0; + $productType =0; + $data['update_time'] = date('Y-m-d H:i:s'); + app()->make(ProductRepository::class)->create($data, $productType, $contentType); + } +} diff --git a/app/listener/ProductCreate.php b/app/listener/ProductCreate.php index 59644a15..6876b435 100644 --- a/app/listener/ProductCreate.php +++ b/app/listener/ProductCreate.php @@ -14,42 +14,48 @@ class ProductCreate public function handle($event) { $product = $event['product']; - $data = $event['data']; - $contentType = $event['conType']; + // $data = $event['data']; + // $contentType = $event['conType']; + //查询当前商品的店铺 $merchant = Db::name('merchant')->where('status', 1)->where('is_del', 0)->where('mer_id', $product['mer_id'])->find(); if (empty($merchant)) { return false; } + if($merchant['type_id']!=Merchant::TypeTownSupplyChain){ + return false; + } // 根据支持同步到云商的商户进行同步操作 - $syncMerArray = Db::name('MerchantType')->where('is_sync_prod', 1)->column('mer_type_id'); - if (!in_array($merchant['type_id'], $syncMerArray)) { - return false; - } + // $syncMerArray = Db::name('MerchantType')->where('is_sync_prod', 1)->column('mer_type_id'); + // if (!in_array($merchant['type_id'], $syncMerArray)) { + // return false; + // } - $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); - $typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id'); - if ($merchant['type_id'] == $typePlatformId || $merchant['type_id'] == $typeCloudWarehouseId) { - return false; - } + // $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); + // $typePlatformId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->value('mer_type_id'); + // if ($merchant['type_id'] == $typePlatformId || $merchant['type_id'] == $typeCloudWarehouseId) { + // return false; + // } - //查询市级云仓 - $cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypePlatform)->find(); + //查询市级供应链 + $cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypeSupplyChain)->find(); if ($cityMerchant == null) { return false; } + //查询市级供应链商品 $product_id = Db::name('store_product')->where('mer_id', $cityMerchant['mer_id'])->where('bar_code', $product['bar_code'])->value('product_id'); if ($product_id) { return false; } - - $data['mer_id'] = $cityMerchant['mer_id']; - $data['status'] = $cityMerchant['is_audit'] ? 0 : 1; - $data['mer_status'] = ($cityMerchant['is_del'] || !$cityMerchant['mer_state'] || !$cityMerchant['status']) ? 0 : 1; - $data['rate'] = 3; - // $typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id'); - // $productType = $cityMerchant['type_id'] == $typeSupplyChainId ? 98 : 0; - $productType =0; - $data['update_time'] = date('Y-m-d H:i:s'); - app()->make(ProductRepository::class)->create($data, $productType, $contentType); + //添加到云仓 + $datas=[ + 'product_id'=>$product_id, + 'mer_id'=>$merchant['mer_id'], + 'source_mer_id'=>$cityMerchant['mer_id'], + 'street_code'=>$merchant['street_id'], + 'weight'=>1, + 'status'=>1, + 'create_time'=>date('Y-m-d H:i:s'), + ]; + Db::name('cloud_product')->insert($datas); } }