库存减少和创建扫码优化
This commit is contained in:
parent
3d55b3f505
commit
c0ee92c932
@ -26,6 +26,7 @@ use app\common\model\user\UserShip;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use taoser\exception\ValidateException;
|
||||
use think\db\Raw;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use Workerman\Events\Select;
|
||||
@ -68,7 +69,7 @@ class OrderLogic extends BaseLogic
|
||||
/** 计算价格 */
|
||||
$check = DictType::where('type', 'activities')->find();
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
@ -104,6 +105,7 @@ class OrderLogic extends BaseLogic
|
||||
// }
|
||||
$cartInfo['vip_price'] = 0; //$cart_select[$k]['total'] - $vipPrice ?? 0;
|
||||
$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]['imgs'] = $find['image'];
|
||||
@ -158,9 +160,9 @@ class OrderLogic extends BaseLogic
|
||||
//成本价 收益
|
||||
$order = [
|
||||
'create_time' => time(),
|
||||
'order_id' => getNewOrderId('PF'),
|
||||
'order_id' => $params['order_id']?:getNewOrderId('PF'),
|
||||
'total_price' => self::$total_price, //总价
|
||||
'cost' => self::$cost, //成本价
|
||||
'cost' => self::$cost, //成本价1-
|
||||
'profit' => self::$profit, //利润
|
||||
'pay_price' => $pay_price, //后期可能有降价抵扣
|
||||
'vip_price' => $vipPrice,
|
||||
@ -193,8 +195,11 @@ class OrderLogic extends BaseLogic
|
||||
*/
|
||||
static public function createOrder($cartId, $addressId, $user = null, $params = [])
|
||||
{
|
||||
$verify_code = verificationCode();
|
||||
$params['verify_code'] = $verify_code;
|
||||
$order_id = getNewOrderId('PF');
|
||||
$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);
|
||||
if (!$orderInfo) {
|
||||
return false;
|
||||
@ -227,13 +232,21 @@ class OrderLogic extends BaseLogic
|
||||
try {
|
||||
$order = StoreOrder::create($_order);
|
||||
$goods_list = $orderInfo['cart_list'];
|
||||
$updateData = [];
|
||||
foreach ($goods_list as $k => $v) {
|
||||
$goods_list[$k]['oid'] = $order->id;
|
||||
$goods_list[$k]['uid'] = request()->userId;
|
||||
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
||||
$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 StoreBranchProduct())->saveAll($updateData);
|
||||
$where = ['is_pay' => 0];
|
||||
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
||||
Db::commit();
|
||||
|
@ -375,6 +375,16 @@ if (!function_exists('verificationCode')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('createCode')) {
|
||||
function createCode($code) {
|
||||
$check = \app\common\model\store_order\StoreOrder::where('verify_code',$code)->count();
|
||||
if($check){
|
||||
$orderPickupCode = rand(1,10).'-'.str_pad(rand(0, 99999), 5, '0', STR_PAD_LEFT);
|
||||
return createCode($orderPickupCode);
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('haversineDistance')) {
|
||||
function haversineDistance($latitude1, $longitude1, $latitude2, $longitude2) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user