创建订单
This commit is contained in:
parent
9ba8995e4b
commit
e2d21696cf
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user