|
@@ -208,10 +208,29 @@ class OrderService extends BaseService
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 用户信息
|
|
|
|
|
+ RedisService::set($cacheLockKey, ['params' => $params, 'user_id' => $userId], rand(3, 5));
|
|
|
|
|
+ $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
|
|
|
|
|
+ ->select(['id', 'openid', 'mobile', 'nickname','discount_point', 'realname', 'balance', 'status'])
|
|
|
|
|
+ ->first();
|
|
|
|
|
+ $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
|
|
+ $openid = isset($userInfo['openid']) ? $userInfo['openid'] : '';
|
|
|
|
|
+ $discountPoint = isset($userInfo['discount_point']) ? $userInfo['discount_point'] : 0; // 折扣
|
|
|
|
|
+ if (empty($userInfo) || $status != 1) {
|
|
|
|
|
+ $this->error = 1045;
|
|
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($openid)) {
|
|
|
|
|
+ $this->error = '用户微信未授权,请重新授权登录';
|
|
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 商品数据
|
|
// 商品数据
|
|
|
$orderNo = get_order_num('JK');
|
|
$orderNo = get_order_num('JK');
|
|
|
- RedisService::set($cacheLockKey, ['params' => $params, 'user_id' => $userId], rand(3, 5));
|
|
|
|
|
- $result = GoodsService::make()->getOrderGoods($ids, $goods, $orderNo, $userId);
|
|
|
|
|
|
|
+ $result = GoodsService::make()->getOrderGoods($ids, $goods, $userId, $orderNo);
|
|
|
if (empty($result)) {
|
|
if (empty($result)) {
|
|
|
RedisService::clear($cacheLockKey);
|
|
RedisService::clear($cacheLockKey);
|
|
|
$this->error = GoodsService::make()->getError();
|
|
$this->error = GoodsService::make()->getError();
|
|
@@ -219,7 +238,9 @@ class OrderService extends BaseService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$orderGoods = isset($result['goods']) ? $result['goods'] : [];
|
|
$orderGoods = isset($result['goods']) ? $result['goods'] : [];
|
|
|
- $orderTotal = isset($result['total']) ? $result['total'] : 0;
|
|
|
|
|
|
|
+ $goodsTotal = isset($result['goods_total']) ? $result['goods_total'] : 0; // 商品总价
|
|
|
|
|
+ $orderTotal = isset($result['order_total']) ? $result['order_total'] : 0; // 订单结算金额(折后)
|
|
|
|
|
+ $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 折扣金额
|
|
|
$orderCount = isset($result['count']) ? $result['count'] : 0;
|
|
$orderCount = isset($result['count']) ? $result['count'] : 0;
|
|
|
$deliveryFee = isset($result['delivery_fee']) ? $result['delivery_fee'] : 0; // 运费
|
|
$deliveryFee = isset($result['delivery_fee']) ? $result['delivery_fee'] : 0; // 运费
|
|
|
$storeId = isset($result['store_id']) ? $result['store_id'] : 0; // 企业/商家
|
|
$storeId = isset($result['store_id']) ? $result['store_id'] : 0; // 企业/商家
|
|
@@ -241,25 +262,6 @@ class OrderService extends BaseService
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 用户信息
|
|
|
|
|
- $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
|
|
|
|
|
- ->select(['id', 'openid', 'mobile', 'nickname','discount_point', 'realname', 'balance', 'status'])
|
|
|
|
|
- ->first();
|
|
|
|
|
- $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
|
|
- $openid = isset($userInfo['openid']) ? $userInfo['openid'] : '';
|
|
|
|
|
- $discountPoint = isset($userInfo['discount_point']) ? $userInfo['discount_point'] : 0; // 折扣
|
|
|
|
|
- if (empty($userInfo) || $status != 1) {
|
|
|
|
|
- $this->error = 1045;
|
|
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (empty($openid)) {
|
|
|
|
|
- $this->error = '用户微信未授权,请重新授权登录';
|
|
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 收货地址信息
|
|
// 收货地址信息
|
|
|
$addressInfo = MemberAddressService::make()->getBindInfo($userId, $addressId);
|
|
$addressInfo = MemberAddressService::make()->getBindInfo($userId, $addressId);
|
|
|
$realname = isset($addressInfo['realname']) ? $addressInfo['realname'] : '';
|
|
$realname = isset($addressInfo['realname']) ? $addressInfo['realname'] : '';
|
|
@@ -280,25 +282,16 @@ class OrderService extends BaseService
|
|
|
$bonusRate = $bonusRate > 0 && $bonusRate <= 100 ? $bonusRate : $storeBonusRate;
|
|
$bonusRate = $bonusRate > 0 && $bonusRate <= 100 ? $bonusRate : $storeBonusRate;
|
|
|
$bonus = moneyFormat($orderTotal * $bonusRate / 100, 2);
|
|
$bonus = moneyFormat($orderTotal * $bonusRate / 100, 2);
|
|
|
|
|
|
|
|
- // 折扣
|
|
|
|
|
- $discountTotal = 0;
|
|
|
|
|
- $total = $orderTotal;
|
|
|
|
|
- if($discountPoint>0 && $discountPoint<1){
|
|
|
|
|
- $orderTotal = moneyFormat((1-$discountPoint) * $discountPoint,2);
|
|
|
|
|
- $discountTotal = moneyFormat($total - $orderTotal,2);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (env('PAY_DEBUG')) {
|
|
if (env('PAY_DEBUG')) {
|
|
|
$orderTotal = 0.1;
|
|
$orderTotal = 0.1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// 订单数据
|
|
// 订单数据
|
|
|
$order = [
|
|
$order = [
|
|
|
'order_no' => $orderNo,
|
|
'order_no' => $orderNo,
|
|
|
'user_id' => $userId,
|
|
'user_id' => $userId,
|
|
|
'store_id' => $storeId,
|
|
'store_id' => $storeId,
|
|
|
- 'total' => $total, // 商品总价
|
|
|
|
|
|
|
+ 'total' => $goodsTotal, // 商品总价
|
|
|
'num' => $orderCount,
|
|
'num' => $orderCount,
|
|
|
'pay_total' => $orderTotal, // 折扣后商品总价
|
|
'pay_total' => $orderTotal, // 折扣后商品总价
|
|
|
'discount_point' => $discountPoint,
|
|
'discount_point' => $discountPoint,
|