master
wangxinglong 2022-06-10 17:41:56 +08:00
parent 418a0eccd4
commit 7fd388be9b
3 changed files with 16 additions and 1 deletions

View File

@ -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) {

View File

@ -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]);
}
}

View File

@ -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},