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\ExpressLogTrait;
use app\traits\order\ExpressTrait; use app\traits\order\ExpressTrait;
use app\traits\order\ShoppingCartTrait; use app\traits\order\ShoppingCartTrait;
use app\traits\spu\SkuTrait;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use Exception; use Exception;
@ -56,6 +57,7 @@ class OrderRepository extends Repository
use ExpressTrait; use ExpressTrait;
use ExpressLogTrait; use ExpressLogTrait;
use ActivityTrait; use ActivityTrait;
use SkuTrait;
/** 订单状态 **/ /** 订单状态 **/
public const STATUS_ORDER_PLACED = Order::STATUS_ORDER_PLACED;//已下单 (已付款待发货) public const STATUS_ORDER_PLACED = Order::STATUS_ORDER_PLACED;//已下单 (已付款待发货)
@ -330,15 +332,21 @@ class OrderRepository extends Repository
//商品减库存 //商品减库存
$updateSkuStock = [];//规格库存 $updateSkuStock = [];//规格库存
$updateSpuStock = [];
foreach ($skuList as $sku) { foreach ($skuList as $sku) {
$arr = []; $arr = [];
$arr['id'] = $sku['id']; $arr['id'] = $sku['id'];
$arr['stock'] = Db::raw('`stock` - '.($dataSku[$sku['coding']] ?? 1));; $arr['stock'] = Db::raw('`stock` - '.($dataSku[$sku['coding']] ?? 1));;
$updateSkuStock[] = $arr; $updateSkuStock[] = $arr;
$updateSpuStock["spu_id"] = $sku['spu_id'];
} }
(new Sku())->saveAll($updateSkuStock); (new Sku())->saveAll($updateSkuStock);
foreach ($updateSpuStock as $spuItem) {
$this->updateStockById($spuItem);
}
// $freight = 0;//运费(元) // $freight = 0;//运费(元)
// // 邮寄方式 // // 邮寄方式
// if ($data['pick_self'] == Order::COMMON_OFF) { // if ($data['pick_self'] == Order::COMMON_OFF) {

View File

@ -126,4 +126,11 @@ trait SkuTrait
// ->order('id', 'asc') // ->order('id', 'asc')
// ->select(); // ->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' // }, align: 'center'
// }, // },
{field: 'price', title: '价格(¥)'}, {field: 'price', title: '价格(¥)'},
// {field: 'stock', title: '总库存', minWidth: 100}, {field: 'stock', title: '总库存', minWidth: 100},
// {field: 'amount', title: '销量(含初始销量)', minWidth: 100}, // {field: 'amount', title: '销量(含初始销量)', minWidth: 100},
// {field: 'init_amount', title: '初始销量', minWidth: 100}, // {field: 'init_amount', title: '初始销量', minWidth: 100},
// {field: 'saleable_text', title: '状态', width: 150}, // {field: 'saleable_text', title: '状态', width: 150},