diff --git a/app/Controller/v3/NotifyController.php b/app/Controller/v3/NotifyController.php index fb6cc66..b1cb2de 100644 --- a/app/Controller/v3/NotifyController.php +++ b/app/Controller/v3/NotifyController.php @@ -7,6 +7,8 @@ use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; use App\Constants\v3\Payment; use App\Controller\BaseController; +use App\Model\v3\Goods; +use App\Model\v3\GoodsActivity; use App\Model\v3\Order; use App\Model\v3\OrderGoods; use App\Model\v3\OrderMain; @@ -347,10 +349,19 @@ class NotifyController extends BaseController // 处理特价商品缓存 $orderChildren = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); $orderGoods = OrderGoods::query() - ->where(['activity_type' => 2]) + // ->where(['activity_type' => 2]) ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get(); foreach ($orderGoods as $key => &$item) { - $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + + if ($item['activity_type'] == 2) { # 活动商品 + $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + $goods = GoodsActivity::find($item['goods_id']); + } else { + $goods = Goods::find($item['goods_id']); + } + $goods->inventory = $goods->inventory + $item['number']; + $goods->sales = $goods->sales - $item['number']; + $goods->save(); } // 添加用户的流水 diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index d55b658..dd7cdec 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -691,18 +691,18 @@ class OrderOnlineService implements OrderOnlineServiceInterface $orderIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('id'); $orderGoods = OrderGoods::query()->whereIn('order_id', $orderIds)->get()->toArray(); - // 释redis库存 - $redis = ApplicationContext::getContainer()->get(Redis::class); - foreach ($orderGoods as $k => &$goodsItem) { - // 拼接activity_type和goods_id - $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, 0); - } else { - $redis->decrBy($inventoryKey, intval($goodsItem['number'])); - } - } + // // 释redis库存 + // $redis = ApplicationContext::getContainer()->get(Redis::class); + // foreach ($orderGoods as $k => &$goodsItem) { + // // 拼接activity_type和goods_id + // $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; + // // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + // if (!$redis->exists($inventoryKey)) { + // $redis->set($inventoryKey, 0); + // } else { + // $redis->decrBy($inventoryKey, intval($goodsItem['number'])); + // } + // } // 微信退款 if ($orderMain->pay_type == Payment::WECHAT) {