feat: #10000 店铺商品更新优化

This commit is contained in:
赵世界 2022-09-15 17:55:17 +08:00
parent 6d167df49d
commit 5b87ebcd22
2 changed files with 8 additions and 3 deletions

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers\Business;
use App\Events\StockUpdateEvent;
use App\Events\BusinessOrdersUpdate;
use App\Http\Controllers\Controller;
use App\Http\Resources\BusinessGoodsSkuResource;
use App\Models\BusinessGoodsSku;
@ -87,7 +87,7 @@ class BusinessGoodsSkusController extends Controller
if (empty($sku)) {
$this->setValidatorFailResponse('未找到对应的商品,请核实后再次同步或删除此平台商品');
} else {
event(new StockUpdateEvent($sku));
event(new BusinessOrdersUpdate($businessGoodsSku, 0));
$this->res['message'] = '库存同步请求发送成功,具体结果查看日志';
}
return response($this->res, $this->res['httpCode']);

View File

@ -49,7 +49,12 @@ class UpdateBusinessGoodsStock implements ShouldQueue
if ('下架' === $event->goodsSku->status) {
return;
}
$shops = Shop::query()->whereNotIn('status', [0, 3])->get(['id', 'plat_id']);
$builder = Shop::query()->whereNotIn('status', [0, 3]);
// 非订单影响库存变更,只更新本店铺下商品
if (!isset($event->businessGoods['business_order_id'])) {
$builder->where('id', $event->businessGoods['shop_id']);
}
$shops = $builder->get(['id', 'plat_id']);
if (empty($shops)) {
LogFile::info('可操作店铺为空');
return;