diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 519d4843..e3fa3f76 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -1698,7 +1698,7 @@ class ProductRepository extends BaseRepository throw new ValidateException('商品spu更新出错'); } else { if ($product->product_type == 0) { - event('product.sell', ['product_id' => [$id]]); + event('product.sell', ['product_id' => [$id],'status'=>$status]); } } Db::commit(); diff --git a/app/listener/CloudProduct.php b/app/listener/CloudProduct.php index 9c66566e..f59f197f 100644 --- a/app/listener/CloudProduct.php +++ b/app/listener/CloudProduct.php @@ -17,52 +17,10 @@ class CloudProduct public function handle($event) { $productIds = $event['product_id']; - $typeStoreId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeStore'])->value('mer_type_id'); - $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); - $products = Product::withTrashed()->whereIn('product_id', $productIds)->field('product_id,mer_id,status,is_del,is_show,mer_status,is_used')->select(); - /** @var CloudProductDao $repo */ - $repo = app()->make(CloudProductDao::class); - /** @var RedisCacheService $RedisCacheService */ - $RedisCacheService = app()->make(RedisCacheService::class); - $clearCache = []; - foreach ($products as $product) { - $categoryId = Merchant::getDB()->where('mer_id', $product['mer_id'])->where('type_id', $typeStoreId)->value('category_id'); - if (!$categoryId) { - continue; - } - $cloudMerchant = Merchant::getDB()->where(['type_id' => $typeCloudWarehouseId, 'category_id' => $categoryId, 'status' => 1, 'mer_state' => 1])->value('mer_id'); - if (empty($cloudMerchant)) { - continue; - } - $status = $product->isEnable() ? 1 : 0; - $exist = $repo->get($product['product_id']); - if (!$exist) { - $values = [ - 'mer_id' => $cloudMerchant, - 'source_mer_id' => $product['mer_id'], - 'product_id' => $product['product_id'], - 'status' => $status, - 'create_time' => date('Y-m-d H:i:s'), - ]; - $repo->create($values); - } else { - $repo->update((int)$product['product_id'], ['status' => $status]); - } + $status = $event['status']; + + Db::name('cloud_product')->whereIn('product_id',$productIds)->update(['status' => $status]); - $cacheKey = sprintf(CloudProductModel::CacheKey, $cloudMerchant); - $exist = $RedisCacheService->SISMEMBER($cacheKey, $product['product_id']); - if ($status == 1 && !$exist) { - $RedisCacheService->SADD($cacheKey, $product['product_id']); - $clearCache[] = $cloudMerchant; - } elseif ($status == 0) { - $RedisCacheService->SREM($cacheKey, $product['product_id']); - $clearCache[] = $cloudMerchant; - } - } - foreach ($clearCache as $item) { - $takenKey = sprintf(CloudProductModel::TakenKey, $item); - $RedisCacheService->del($takenKey); - } } }