From e2d21696cfb9f89c3071d4198d55a2ed79150d43 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 4 Jun 2024 15:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 16 ++++++++-------- app/functions.php | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 3b04aa3d..5ab8c46d 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -43,7 +43,7 @@ class OrderLogic extends BaseLogic static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = []) { - $where = ['is_pay' => 0, 'is_del' => 0]; + $where = ['is_pay' => 0, 'delete_time' => null]; $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('product_id as goods,cart_num')->select()->toArray(); if (empty($cart_select)) { self::setError('购物车为空'); @@ -59,10 +59,11 @@ class OrderLogic extends BaseLogic } $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 $cart_select[$k]['price'] = $find['price']; - $cart_select[$k]['product_id'] = $find['goods']; + $cart_select[$k]['product_id'] = $v['goods']; $cart_select[$k]['old_cart_id'] = implode(',', $cartId); $cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['verify_code'] = $params['verify_code']; + $cart_select[$k]['cart_info'] = json_encode($cart_select[$k]); //理论上每笔都是拆分了 // $cart_select[$k]['name'] = $find['store_name']; // $cart_select[$k]['imgs'] = $find['image']; @@ -95,7 +96,7 @@ class OrderLogic extends BaseLogic * @return Object|bool|array */ static public function createOrder($cartId, $addressId, $user = null, $params = []) - { + {\request()->userId = 8; $verify_code = generateUniqueVerificationCode(); $params['verify_code'] = $verify_code; $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params); @@ -116,11 +117,10 @@ class OrderLogic extends BaseLogic $user = User::where('id', \request()->userId)->find(); $_order['real_name'] = $user['real_name']; $_order['mobile'] = $user['mobile']; - $_order['pay_type'] = $user['pay_type']; $_order['verify_code'] = $verify_code; if ($addressId > 0) { - $address = UserAddress::where(['address_id' => $addressId, 'uid' => Request()->userId])->find(); + $address = UserAddress::where(['id' => $addressId, 'uid' => \request()->userId])->find(); if ($address) { $_order['real_name'] = $address['real_name']; $_order['user_phone'] = $address['phone']; @@ -133,6 +133,7 @@ class OrderLogic extends BaseLogic // if($params['pay_type']==PayEnum::CASH_PAY){ // $_order['money']=$_order['total']; // } + Db::startTrans(); try { $order = StoreOrder::create($_order); @@ -142,11 +143,10 @@ class OrderLogic extends BaseLogic $goods_list[$k]['uid'] = request()->userId; $goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['delivery_id'] = $params['store_id'];//商家id - } (new StoreOrderCartInfo())->saveAll($goods_list); - $where = ['is_pay' => 0, 'is_del' => 0]; - Cart::whereIn('cart_id', $cartId)->where($where)->update(['is_pay' => 1]); + $where = ['is_pay' => 0, 'delete_time' => null]; + Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); Db::commit(); return $order; } catch (\Exception $e) { diff --git a/app/functions.php b/app/functions.php index 04865a2b..45864868 100644 --- a/app/functions.php +++ b/app/functions.php @@ -351,11 +351,11 @@ if (!function_exists('generateUniqueVerificationCode')) { $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); // 生成一个随机数作为核销码的后缀 - $randomNumber = mt_rand(10000000, 99999999); // 假设核销码是8位数 + $randomNumber = mt_rand(100, 999); // 假设核销码是8位数 // 将前缀、毫秒时间戳和随机数连接起来 $type = rand(1, 10); // 生成一个1-10之间的随机数作为前缀 - return $type . $msectime . $randomNumber; + return $type .'-'. $msectime . $randomNumber; } }