收银台下单库存校验
This commit is contained in:
parent
23bf1ecee8
commit
77c14d6508
@ -394,5 +394,53 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检查缺失
|
||||||
|
public static function checkLeft($params, $uid, $type = 0)
|
||||||
|
{
|
||||||
|
$where = [];
|
||||||
|
if (empty($type)) {
|
||||||
|
$where = ['is_pay' => 0];
|
||||||
|
}
|
||||||
|
$cart_select = Cart::whereIn('id', $params['cart_id'])
|
||||||
|
->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray();
|
||||||
|
if (empty($cart_select)) {
|
||||||
|
self::setError('购物车为空');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$newArr = [];
|
||||||
|
//检查购物车对比店铺得商品数量差异
|
||||||
|
foreach ($cart_select as $v) {
|
||||||
|
$store = StoreBranchProduct::where([
|
||||||
|
'store_id' => $params['store_id'],
|
||||||
|
'product_id' => $v['product_id'],
|
||||||
|
])->field('id,store_name,stock')->withTrashed()->find();
|
||||||
|
if (empty($store)) {
|
||||||
|
$store['stock'] = 0;
|
||||||
|
}
|
||||||
|
if ($store['stock'] < $v['cart_num']) {
|
||||||
|
//缺失
|
||||||
|
$newArr[] = [
|
||||||
|
'uid' => $uid,
|
||||||
|
'store_id' => $params['store_id'],
|
||||||
|
'product_id' => $v['product_id'],
|
||||||
|
'missing_quantity' => $v['cart_num'] - $store['stock']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($newArr) {
|
||||||
|
return [
|
||||||
|
'detail' => $newArr,
|
||||||
|
'reservation' => 1
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'detail' => [],
|
||||||
|
'reservation' => 0
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,13 +42,13 @@ class CartController extends BaseAdminController
|
|||||||
return $this->fail('购物车商品不能大于100个,请先结算');
|
return $this->fail('购物车商品不能大于100个,请先结算');
|
||||||
}
|
}
|
||||||
//数量下单判断
|
//数量下单判断
|
||||||
$stock = StoreBranchProduct::where(
|
// $stock = StoreBranchProduct::where(
|
||||||
['product_id'=>$params['product_id'],
|
// ['product_id'=>$params['product_id'],
|
||||||
'store_id'=>$params['store_id']
|
// 'store_id'=>$params['store_id']
|
||||||
])->value('stock')??0;
|
// ])->value('stock')??0;
|
||||||
if ($params['cart_num'] >$stock) {
|
// if ($params['cart_num'] >$stock) {
|
||||||
return $this->fail('库存数量不足');
|
// return $this->fail('库存数量不足');
|
||||||
}
|
// }
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$res = CartLogic::edit($params);
|
$res = CartLogic::edit($params);
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,6 +132,23 @@ class StoreOrderController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检查库存足够与否
|
||||||
|
public function checkInventory()
|
||||||
|
{
|
||||||
|
$params = (new StoreOrderValidate())->post()->goCheck('cart');
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id']??22;
|
||||||
|
$res = StoreOrderLogic::checkLeft($params, $params['uid']);
|
||||||
|
if (!$res) {
|
||||||
|
$msg = StoreOrderLogic::getError();
|
||||||
|
if ($msg == '购物车为空') {
|
||||||
|
return $this->data([]);
|
||||||
|
}
|
||||||
|
return $this->fail(StoreOrderLogic::getError());
|
||||||
|
}
|
||||||
|
return $this->data($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建订单
|
* 创建订单
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace app\store\logic\store_order;
|
namespace app\store\logic\store_order;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\order\Cart;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
@ -35,9 +35,15 @@ class StoreOrderValidate extends BaseValidate
|
|||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'verify_code' => '核销码',
|
'verify_code' => '核销码',
|
||||||
'type' => '发送短信类型',
|
'type' => '发送短信类型',
|
||||||
|
'cart_id' => '购物车id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function sceneCart()
|
||||||
|
{
|
||||||
|
return $this->only(['cart_id']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 添加场景
|
* @notes 添加场景
|
||||||
* @return StoreOrderValidate
|
* @return StoreOrderValidate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user