feat : sts
This commit is contained in:
@@ -129,6 +129,8 @@ class SkuService extends BaseService
|
||||
$insertModel->is_add_staple_food = $this->request->input('is_add_staple_food');
|
||||
$insertModel->code_number = $this->request->input('code_number');
|
||||
$insertModel->sort = $this->request->input('sort');
|
||||
$insertModel->origin_sku_id = 0;
|
||||
$insertModel->favorable = GoodCode::NOT_FAVORABLE;
|
||||
|
||||
if (!$insertModel->save()) throw new ErrException('添加失败');
|
||||
|
||||
@@ -167,19 +169,38 @@ class SkuService extends BaseService
|
||||
$spuInfo = $this->spuModel->getInfoById($skuInfo->spu_id);
|
||||
if (empty($spuInfo)) throw new ErrException('数据出错');
|
||||
|
||||
$originSkuInfo = null;
|
||||
if ($skuInfo->favorable == GoodCode::IS_FAVORABLE) {
|
||||
$originSkuInfo = $this->skuModel->find($skuInfo->origin_sku_id);
|
||||
if (empty($originSkuInfo)) throw new ErrException('原sku数据不存在,无法修改');
|
||||
}
|
||||
|
||||
$stock = $this->request->input('stock');
|
||||
$forceCleanStockCache = 0;
|
||||
|
||||
if ($skuInfo->order_num > 0) { //已产生订单 修改库存需要强制删除库存缓存
|
||||
$forceCleanStockCache = 1;
|
||||
|
||||
$originTotalStock = $skuInfo->total_stock;
|
||||
if ($skuInfo->total_stock < $stock) $skuInfo->total_stock = $stock;
|
||||
if ($skuInfo->total_stock > $stock) {
|
||||
else {
|
||||
$skuInfo->total_stock = $stock;
|
||||
if ($skuInfo->order_num >= $stock) throw new ErrException('库存不能小于已下单量');
|
||||
}
|
||||
}
|
||||
|
||||
$skuInfo->surplus_stock = $skuInfo->total_stock - $skuInfo->order_num;
|
||||
if ($originSkuInfo && $skuInfo->total_stock > $originSkuInfo->total_stock) throw new ErrException('修改后的库存不能大于原商品库存');
|
||||
|
||||
$skuInfo->surplus_stock = $skuInfo->total_stock - $skuInfo->order_num;
|
||||
if ($originSkuInfo) {
|
||||
$originSkuInfo->total_stock = $originSkuInfo->total_stock - $originTotalStock + ($originTotalStock - $skuInfo->order_num);
|
||||
$originSkuInfo->surplus_stock = $originSkuInfo->surplus_stock - $originTotalStock + ($originTotalStock - $skuInfo->order_num);
|
||||
|
||||
if ($originSkuInfo->total_stock < 0 || $originSkuInfo->surplus_stock < 0) throw new ErrException('秒杀库存数据过多,原商品库存不足');
|
||||
}
|
||||
|
||||
} else {
|
||||
$skuInfo->total_stock = $stock;
|
||||
$skuInfo->surplus_stock = $stock;
|
||||
}
|
||||
|
||||
if ($skuInfo->order_num > 0 && $skuInfo->price != $this->request->input('price')) throw new ErrException('已有订单不可改价,退单后即可操作');
|
||||
else $skuInfo->price = $this->request->input('price');
|
||||
@@ -199,7 +220,7 @@ class SkuService extends BaseService
|
||||
$skuInfo->sub_title = $this->request->input('sub_title');
|
||||
$skuInfo->param = $this->request->input('param','');
|
||||
$skuInfo->extra = $this->request->input('extra','');
|
||||
$skuInfo->total_stock = $this->request->input('stock');
|
||||
// $skuInfo->total_stock = $this->request->input('stock');
|
||||
$skuInfo->saleable = $this->request->input('saleable');
|
||||
$skuInfo->title = $this->request->input('title');
|
||||
$skuInfo->sort = $this->request->input('sort');
|
||||
|
||||
Reference in New Issue
Block a user