Merge branch 'dev' of https://gitea.lihaink.cn/mkm/multi-store into dev
This commit is contained in:
commit
0fa71e2fe8
@ -99,6 +99,21 @@ class OrderController extends BaseApiController
|
||||
return $this->data($res);
|
||||
}
|
||||
|
||||
public function checkInventory()
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('cart');
|
||||
$res = OrderLogic::checkLeft($params, $this->userId);
|
||||
if (!$res) {
|
||||
$msg = OrderLogic::getError();
|
||||
if ($msg == '购物车为空') {
|
||||
return $this->data([]);
|
||||
}
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
return $this->data($res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*/
|
||||
|
@ -216,6 +216,7 @@ class OrderLogic extends BaseLogic
|
||||
$_order['pay_type'] = $orderInfo['order']['pay_type'];
|
||||
$_order['verify_code'] = $verify_code;
|
||||
$_order['reservation_time'] = null;
|
||||
$_order['reservation'] = $params['reservation']??0;//是否需要预约
|
||||
if (isset($params['reservation_time']) && $params['reservation_time']) {
|
||||
$_order['reservation_time'] = $params['reservation_time'];
|
||||
$_order['reservation'] = YesNoEnum::YES;
|
||||
@ -264,6 +265,52 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检验丢失
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function checkLeft($params,$uid)
|
||||
{
|
||||
$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'=>$v['store_id'],
|
||||
'product_id'=>$v['product_id'],
|
||||
])->field('id,store_name,stock')->withTrashed()->find();
|
||||
if($store['stock'] < $v['cart_num']){
|
||||
//缺失
|
||||
$newArr[] = [
|
||||
'uid'=>$uid,
|
||||
'store_id'=>$v['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
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单号
|
||||
|
@ -23,6 +23,7 @@ class OrderValidate extends BaseValidate
|
||||
'id' => 'require|number',
|
||||
'old_cart_id' => 'require|array',
|
||||
'refund_type' => 'require|number',
|
||||
'cart_id' => 'require',
|
||||
];
|
||||
|
||||
|
||||
@ -37,8 +38,14 @@ class OrderValidate extends BaseValidate
|
||||
'id' => '订单id',
|
||||
'old_cart_id' => '购物车id',
|
||||
'refund_type' => '退款申请类型',
|
||||
'cart_id' => '购物车id',
|
||||
];
|
||||
|
||||
public function sceneCart()
|
||||
{
|
||||
return $this->only(['cart_id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
|
Loading…
x
Reference in New Issue
Block a user