diff --git a/app/common/dao/store/StoreActivityDao.php b/app/common/dao/store/StoreActivityDao.php old mode 100644 new mode 100755 index ef529164..7e269c1b --- a/app/common/dao/store/StoreActivityDao.php +++ b/app/common/dao/store/StoreActivityDao.php @@ -16,6 +16,7 @@ namespace app\common\dao\store; use app\common\dao\BaseDao; use app\common\dao\store\product\CloudProductDao; use app\common\model\store\product\CloudProduct; +use app\common\model\store\product\Product; use app\common\model\store\StoreActivity; use app\common\model\store\StoreActivityOrderProduct; use app\common\repositories\store\product\SpuRepository; @@ -77,6 +78,10 @@ class StoreActivityDao extends BaseDao $canBuy = 1; if ($products['list']) { $list = $products['list']; + $productList = array_column($list->toArray(), 'product'); + $oldProductIds = array_column($productList, 'old_product_id'); + $oldProductList = Product::whereIn('product_id', $oldProductIds)->field('product_id,stock')->select()->toArray(); + $oldProductList = reset_index($oldProductList, 'product_id'); foreach ($cloud_product_arr as $key => $value) { if (!empty($userId)) { $buyRecord = $this->canBuy($userId, $value['product_id']); @@ -87,6 +92,11 @@ class StoreActivityDao extends BaseDao foreach ($list as $k => $v) { if ($activityId == 2) { $list[$k]['limited_price'] = '2.00'; + if (isset($oldProductList[$v['product']['old_product_id']])) { + $list[$k]['product']['stock'] = $oldProductList[$v['product']['old_product_id']]['stock']; + $list[$k]['stock'] = $oldProductList[$v['product']['old_product_id']]['stock']; + $list[$k]['product']['image'] = $list[$k]['product']->sellOutImage; + } } if ($value['product_id'] == $v['product_id']) { if ($value['mer_labels'] == ',5,') { diff --git a/app/common/dao/store/consumption/CommissionDao.php b/app/common/dao/store/consumption/CommissionDao.php index 017ce323..afba4b43 100644 --- a/app/common/dao/store/consumption/CommissionDao.php +++ b/app/common/dao/store/consumption/CommissionDao.php @@ -156,7 +156,7 @@ class CommissionDao $result = $curl->post($url, ['timestamp' => $timestamp, 'data' => $encrypt]); $result = json_decode($result, true); if ($result['code'] != 1) { - Log::error('发送佣金失败:', $result); + Log::error('发送佣金失败:' . var_export($result, true)); } } diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index 5253f102..29c53a93 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -74,7 +74,7 @@ class StoreOrderDao extends BaseDao } $query->where('is_del', 0); }); - if (isset($where['source']) && $where['source'] == 103) { + if (isset($where['source']) && ($where['source'] == 103||$where['source'] == 105)) { $wheres['activity_type'] = [0,98]; $wheres['source'] = [0,2,103,105]; $query->where($wheres); diff --git a/app/common/model/store/product/Product.php b/app/common/model/store/product/Product.php index 98a424e0..805d192c 100644 --- a/app/common/model/store/product/Product.php +++ b/app/common/model/store/product/Product.php @@ -38,6 +38,9 @@ class Product extends BaseModel protected $deleteTime = 'is_del'; protected $defaultSoftDelete = 0; + /** @var string $sellOutImage 售罄图片 */ + public $sellOutImage = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/7300e202401251053563156.png'; + const IS_SHOW = 1; //上架 const IS_NOT_SHOW = 0; //下架 diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index a1e11193..c40c227e 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1137,7 +1137,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository } $product_source_id = 0; $product_mer_id = 0; - if ($cart['source'] == 103) { + if ($cart['source'] == 103 ||$cart['source'] == 105) { $old_product_id = Db::name('store_product')->where('product_id', $cart['product_id'])->value('old_product_id'); if ($old_product_id) { $old_mer_id = Db::name('store_product')->where('product_id', $old_product_id)->value('mer_id'); diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index fade4dae..e3fa3f76 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -17,6 +17,7 @@ use app\common\dao\store\order\StoreCartDao; use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrderProduct; use app\common\model\store\product\CloudProduct; +use app\common\model\store\product\Product; use app\common\model\store\product\ProductAttrValue; use app\common\model\store\product\ProductLabel; use app\common\model\store\product\PurchaseRecord; @@ -1284,8 +1285,16 @@ class ProductRepository extends BaseRepository $attr = $this->detailAttr($res['attr']); $attrValue = (in_array($res['product_type'], [3, 4])) ? $res['oldAttrValue'] : $res['attrValue']; + $oldProduct = Product::where('product_id', $res['old_product_id'])->field('product_id,stock')->find(); + $activityId = CloudProduct::where('product_id', $res['product_id'])->value('activity_id'); $sku = $this->detailAttrValue($attrValue, $userInfo, $productType, $activityId); - + if ($activityId == 2 && isset($oldProduct['stock'])) { + $res['stock'] = $oldProduct['stock']; + $res['slider_image'] = $res->sellOutImage; + foreach ($sku as &$skuItem) { + $skuItem['stock'] = $oldProduct['stock']; + } + } $res['isRelation'] = $isRelation ?? false; $care = false; if ($userInfo) { @@ -1689,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/controller/api/store/order/StoreProcessing.php b/app/controller/api/store/order/StoreProcessing.php index ad605190..7f180d5a 100644 --- a/app/controller/api/store/order/StoreProcessing.php +++ b/app/controller/api/store/order/StoreProcessing.php @@ -29,7 +29,7 @@ class StoreProcessing extends BaseController $group_order_id = Db::name('store_group_order_other')->strict(false)->insertGetId($store_group_order); } $select = Db::name('store_order_product')->where('order_id', $order['order_id'])->select(); - if ($order['source'] == 103 && $select) { + if ($order['source'] == 103 ||$order['source'] == 105 && $select) { // $financialRecordRepository = app()->make(FinancialRecordRepository::class); // $financeSn = $financialRecordRepository->getSn(); $arr = $select->toArray(); diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index a6423693..dce7c908 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -91,7 +91,7 @@ class StoreSpu extends BaseController unset($where['type_id'], $where['street_id'],$where['type_code'],$where['village_id']); $where['is_gift_bag'] = 0; - $where['product_type'] = $where['product_type']??0; + $where['product_type'] = $where['product_type'] != '' ? $where['product_type'] : 0; $where['order'] = $where['order'] ?: 'star'; if ($where['is_trader'] != 1) unset($where['is_trader']); if($where['category_id']!=''){ 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); - } } }