处理收银机和小程序扣除库存相关逻辑
This commit is contained in:
parent
f5dc2f7331
commit
e913dcb2ca
@ -48,7 +48,7 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
/** 计算价格 */
|
/** 计算价格 */
|
||||||
$check = DictType::where('type', 'activities')->find();
|
$check = DictType::where('type', 'activities')->find();
|
||||||
foreach ($cart_select as $k => $v) {
|
foreach ($cart_select as $k => $v) {
|
||||||
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field('store_name,image,unit,price,cost,product_id')->find();
|
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field('id branch_product_id,store_name,image,unit,price,cost,product_id')->find();
|
||||||
if (!$find) {
|
if (!$find) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -84,6 +84,7 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
// }
|
// }
|
||||||
$cartInfo['vip_price'] = 0;//$cart_select[$k]['total'] - $vipPrice ?? 0;
|
$cartInfo['vip_price'] = 0;//$cart_select[$k]['total'] - $vipPrice ?? 0;
|
||||||
$cart_select[$k]['cart_info'] = json_encode($cartInfo);
|
$cart_select[$k]['cart_info'] = json_encode($cartInfo);
|
||||||
|
$cart_select[$k]['branch_product_id'] = $find['branch_product_id'];
|
||||||
//理论上每笔都是拆分了
|
//理论上每笔都是拆分了
|
||||||
$cart_select[$k]['name'] = $find['store_name'];
|
$cart_select[$k]['name'] = $find['store_name'];
|
||||||
$cart_select[$k]['imgs'] = $find['image'];
|
$cart_select[$k]['imgs'] = $find['image'];
|
||||||
@ -100,7 +101,7 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
//成本价 收益
|
//成本价 收益
|
||||||
$order = [
|
$order = [
|
||||||
'create_time' => time(),
|
'create_time' => time(),
|
||||||
'order_id' => getNewOrderId('PF'),
|
'order_id' =>$params['order_id'] ?? getNewOrderId('PF'),
|
||||||
'total_price' => self::$total_price, //总价
|
'total_price' => self::$total_price, //总价
|
||||||
'cost' => self::$cost,//成本价
|
'cost' => self::$cost,//成本价
|
||||||
'profit' => self::$profit,//利润
|
'profit' => self::$profit,//利润
|
||||||
@ -133,8 +134,11 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
static public function createOrder($cartId, $addressId, $user = null, $params = [])
|
static public function createOrder($cartId, $addressId, $user = null, $params = [])
|
||||||
{
|
{
|
||||||
$verify_code = verificationCode();
|
$order_id = getNewOrderId('PF');
|
||||||
$params['verify_code'] = $verify_code;
|
$code = rand(1,10).'-'.substr($order_id, -5);
|
||||||
|
$verify_code = createCode($code);
|
||||||
|
$params['order_id'] = $order_id;
|
||||||
|
$params['verify_code'] =$verify_code;
|
||||||
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
||||||
if (!$orderInfo) {
|
if (!$orderInfo) {
|
||||||
return false;
|
return false;
|
||||||
@ -156,9 +160,16 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
$goods_list[$k]['uid'] = 0;
|
$goods_list[$k]['uid'] = 0;
|
||||||
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
||||||
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
|
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
|
||||||
|
$stock = StoreBranchProduct::where('id',$v['branch_product_id'])->value('stock');
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $v['branch_product_id'],
|
||||||
|
'stock' => $stock-$v['cart_num'],
|
||||||
|
'sales' => ['inc', $v['cart_num']]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
(new StoreOrderCartInfo())->saveAll($goods_list);
|
(new StoreOrderCartInfo())->saveAll($goods_list);
|
||||||
$where = ['is_pay' => 0];
|
$where = ['is_pay' => 0];
|
||||||
|
(new StoreBranchProduct())->saveAll($updateData);
|
||||||
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return $order;
|
return $order;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user