From 7fd388be9bff3fd4320cb3be4e517d9c3e091ab9 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Fri, 10 Jun 2022 17:41:56 +0800 Subject: [PATCH] setter --- app/repository/OrderRepository.php | 8 ++++++++ app/traits/spu/SkuTrait.php | 7 +++++++ public/static/manager/js/mall/spu.js | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/repository/OrderRepository.php b/app/repository/OrderRepository.php index 5651def..f95a494 100755 --- a/app/repository/OrderRepository.php +++ b/app/repository/OrderRepository.php @@ -27,6 +27,7 @@ use app\traits\order\AfterSaleTrait; use app\traits\order\ExpressLogTrait; use app\traits\order\ExpressTrait; use app\traits\order\ShoppingCartTrait; +use app\traits\spu\SkuTrait; use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use Exception; @@ -56,6 +57,7 @@ class OrderRepository extends Repository use ExpressTrait; use ExpressLogTrait; use ActivityTrait; + use SkuTrait; /** 订单状态 **/ public const STATUS_ORDER_PLACED = Order::STATUS_ORDER_PLACED;//已下单 (已付款待发货) @@ -330,15 +332,21 @@ class OrderRepository extends Repository //商品减库存 $updateSkuStock = [];//规格库存 + $updateSpuStock = []; foreach ($skuList as $sku) { $arr = []; $arr['id'] = $sku['id']; $arr['stock'] = Db::raw('`stock` - '.($dataSku[$sku['coding']] ?? 1));; $updateSkuStock[] = $arr; + $updateSpuStock["spu_id"] = $sku['spu_id']; } (new Sku())->saveAll($updateSkuStock); + foreach ($updateSpuStock as $spuItem) { + $this->updateStockById($spuItem); + } + // $freight = 0;//运费(元) // // 邮寄方式 // if ($data['pick_self'] == Order::COMMON_OFF) { diff --git a/app/traits/spu/SkuTrait.php b/app/traits/spu/SkuTrait.php index 02f8a5e..f80bb1a 100755 --- a/app/traits/spu/SkuTrait.php +++ b/app/traits/spu/SkuTrait.php @@ -126,4 +126,11 @@ trait SkuTrait // ->order('id', 'asc') // ->select(); // } + + + public function updateStockById($spuId) + { + $stock = SkuModel::where("spu_id",$spuId)->sum("stock"); + Spu::updateById($spuId,["stock"=>$stock]); + } } \ No newline at end of file diff --git a/public/static/manager/js/mall/spu.js b/public/static/manager/js/mall/spu.js index c0b0ed1..c94d8d8 100755 --- a/public/static/manager/js/mall/spu.js +++ b/public/static/manager/js/mall/spu.js @@ -50,7 +50,7 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate' // }, align: 'center' // }, {field: 'price', title: '价格(¥)'}, - // {field: 'stock', title: '总库存', minWidth: 100}, + {field: 'stock', title: '总库存', minWidth: 100}, // {field: 'amount', title: '销量(含初始销量)', minWidth: 100}, // {field: 'init_amount', title: '初始销量', minWidth: 100}, // {field: 'saleable_text', title: '状态', width: 150},