diff --git a/app/common/dao/store/product/CloudProductDao.php b/app/common/dao/store/product/CloudProductDao.php new file mode 100644 index 00000000..bc0f6e8e --- /dev/null +++ b/app/common/dao/store/product/CloudProductDao.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + +namespace app\common\dao\store\product; + +use app\common\dao\BaseDao; +use app\common\model\store\product\CloudProduct; + +class CloudProductDao extends BaseDao +{ + + protected function getModel(): string + { + return CloudProduct::class; + } + + public function search(array $where) + { + } + +} diff --git a/app/common/model/store/product/CloudProduct.php b/app/common/model/store/product/CloudProduct.php new file mode 100644 index 00000000..27239f36 --- /dev/null +++ b/app/common/model/store/product/CloudProduct.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + +namespace app\common\model\store\product; + +use app\common\model\BaseModel; + +class CloudProduct extends BaseModel +{ + + public static function tablePk(): string + { + return 'mer_id'; + } + + public static function tableName(): string + { + return 'cloud_product'; + } + +} diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index 4881e983..451e8688 100644 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -28,6 +28,11 @@ use app\common\repositories\store\StoreActivityRepository; class Merchant extends BaseModel { + const TypeStore = 10; //镇街店铺 + const TypeCloudWarehouse = 11; //里海云仓 + const TypeSupplyChain = 12; //市级供应链 + const TypePlatform = 13; //供销平台 + /** * @return string * @author xaboy diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index dda43ccb..ee1f7a11 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -241,8 +241,8 @@ class ProductRepository extends BaseRepository $product['mer_labels'] = $data['mer_labels']; app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType); } - $product = $result; - event('product.create',compact('product')); +// $product = $result; +// event('product.create',compact('product')); return $result->product_id; }); } @@ -1568,6 +1568,7 @@ class ProductRepository extends BaseRepository Db::rollback(); throw new ValidateException('商品spu更新出错'); }else{ + event('product.sell', ['source_mer_id' => $merId, 'product_id' => $id, 'status' => $status]); if ($product->product_type==0){ $RedisCacheService = app()->make(RedisCacheService::class); if ($status==1){ diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 45c55c6b..4b91fda5 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -120,6 +120,9 @@ class StoreProduct extends BaseController $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1; $data['mer_id'] = $merId; $this->repository->edit($id, $data, $merId, 0, 1); + if ($data['status'] == 0) { + event('product.sell', ['source_mer_id' => $merId, 'product_id' => $id, 'status' => $data['status']]); + } return app('json')->success('编辑成功'); } diff --git a/app/event.php b/app/event.php index 06e044fe..0f53cf6b 100644 --- a/app/event.php +++ b/app/event.php @@ -65,6 +65,7 @@ return [ 'community_address'=>[\app\listener\CommunityAddress::class], // 'order.paySuccess'=>[\app\listener\OrderPaySuccess::class], 'product.create'=>[\app\listener\ProductCreate::class], + 'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架 ], 'subscribe' => [], diff --git a/app/listener/CloudProduct.php b/app/listener/CloudProduct.php new file mode 100644 index 00000000..db06db2a --- /dev/null +++ b/app/listener/CloudProduct.php @@ -0,0 +1,22 @@ +where('mer_id', $event['source_mer_id'])->find(); + $cloudMerchant = Merchant::getDB()->where(['type_id' => Merchant::TypeCloudWarehouse, 'category_id' => $merchant->category_id, 'status' => 1, 'mer_state' => 1])->value('mer_id'); + $where = ['mer_id' => $cloudMerchant, 'source_mer_id' => $event['source_mer_id'], 'product_id' => $event['product_id']]; + $cloudProduct = app()->make(CloudProductDao::class)->findOrCreate($where); + $cloudProduct->save(['status' => $event['status']]); + } + +}