|
|
@@ -500,194 +500,226 @@ class OrderService extends BaseService
|
|
|
* @param $mealId 套餐ID
|
|
|
* @return array|false
|
|
|
*/
|
|
|
- public function replyBuy($userId, $mealId)
|
|
|
+ public function rebuyOrder($userId, $mealId)
|
|
|
{
|
|
|
- $type = isset($params['type']) && $params['type'] ? $params['type'] : 1;
|
|
|
- $goods = ["id_{$mealId}"=>['id'=>$mealId,'sku_id'=>0,'num'=>1]];
|
|
|
- $ids = [$mealId];
|
|
|
+ try {
|
|
|
+ $type = 2;
|
|
|
+ $goods = ["id_{$mealId}"=>['id'=>$mealId,'sku_id'=>0,'num'=>1]];
|
|
|
+ $ids = [$mealId];
|
|
|
+
|
|
|
+ // 缓存锁
|
|
|
+ $cacheLockKey = "caches:orders:submit_lock:{$userId}";
|
|
|
+ if (RedisService::get($cacheLockKey)) {
|
|
|
+ $this->error = '订单处理中~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 缓存锁
|
|
|
- $cacheLockKey = "caches:orders:submit_lock:{$userId}";
|
|
|
- if (RedisService::get($cacheLockKey)) {
|
|
|
- $this->error = '订单处理中~';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 用户信息
|
|
|
+ RedisService::set($cacheLockKey, ['mealId' => $mealId, 'user_id' => $userId], rand(3, 5));
|
|
|
+ $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
|
|
|
+ ->select(['id', 'openid','nickname','member_level','parent_id','point_id','points', 'buy_type','property','balance', 'bd_score', 'status'])
|
|
|
+ ->first();
|
|
|
+ $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
+ $openid = isset($userInfo['openid']) ? $userInfo['openid'] : 0;
|
|
|
+ $bdScore = isset($userInfo['bd_score']) ? $userInfo['bd_score'] : 0;
|
|
|
+ $balance = isset($userInfo['balance']) ? $userInfo['balance'] : 0;
|
|
|
+ $discountPoint = isset($userInfo['discount_point']) ? $userInfo['discount_point'] : 0; // 折扣
|
|
|
+ if (empty($userInfo) || $status != 1) {
|
|
|
+ $this->error = 1045;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 用户信息
|
|
|
- RedisService::set($cacheLockKey, ['params' => $params, 'user_id' => $userId], rand(3, 5));
|
|
|
- $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
|
|
|
- ->select(['id', 'openid','nickname','member_level','parent_id','point_id','points', 'buy_type','property','balance', 'bd_score', 'status'])
|
|
|
- ->first();
|
|
|
- $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
- $openid = isset($userInfo['openid']) ? $userInfo['openid'] : 0;
|
|
|
- $bdScore = isset($userInfo['bd_score']) ? $userInfo['bd_score'] : 0;
|
|
|
- $balance = isset($userInfo['balance']) ? $userInfo['balance'] : 0;
|
|
|
- $discountPoint = isset($userInfo['discount_point']) ? $userInfo['discount_point'] : 0; // 折扣
|
|
|
- if (empty($userInfo) || $status != 1) {
|
|
|
- $this->error = 1045;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if (empty($openid)) {
|
|
|
+ $this->error = 1042;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if (empty($openid)) {
|
|
|
- $this->error = 1042;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 商品数据
|
|
|
+ $orderNo = get_order_num('JK');
|
|
|
+ $result = GoodsService::make()->getOrderGoods($ids, $goods, $userId, $orderNo, $discountPoint);
|
|
|
+ if (empty($result)) {
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = GoodsService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 商品数据
|
|
|
- $orderNo = get_order_num('JK');
|
|
|
- $result = GoodsService::make()->getOrderGoods($ids, $goods, $userId, $orderNo, $discountPoint);
|
|
|
- if (empty($result)) {
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = GoodsService::make()->getError();
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $orderGoods = isset($result['goods']) ? $result['goods'] : [];
|
|
|
+ $goodsTotal = isset($result['goods_total']) ? $result['goods_total'] : 0; // 商品总价
|
|
|
+ $orderTotal = isset($result['order_total']) ? $result['order_total'] : 0; // 订单结算金额(折后)
|
|
|
+ $bdScoreTotal = isset($result['bd_score_total']) ? $result['bd_score_total'] : 0; // 报单积分
|
|
|
+ $profitTotal = isset($result['profit_total']) ? $result['profit_total'] : 0; // 利润
|
|
|
+ $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 折扣金额
|
|
|
+ $orderCount = isset($result['count']) ? $result['count'] : 0;
|
|
|
+ $deliveryFee = isset($result['delivery_fee']) ? $result['delivery_fee'] : 0; // 运费
|
|
|
+ $storeId = isset($result['store_id']) ? $result['store_id'] : 0; // 企业/商家
|
|
|
+ if (empty($orderGoods)) {
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = '获取订单商品错误~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- $orderGoods = isset($result['goods']) ? $result['goods'] : [];
|
|
|
- $goodsTotal = isset($result['goods_total']) ? $result['goods_total'] : 0; // 商品总价
|
|
|
- $orderTotal = isset($result['order_total']) ? $result['order_total'] : 0; // 订单结算金额(折后)
|
|
|
- $bdScoreTotal = isset($result['bd_score_total']) ? $result['bd_score_total'] : 0; // 报单积分
|
|
|
- $profitTotal = isset($result['profit_total']) ? $result['profit_total'] : 0; // 利润
|
|
|
- $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 折扣金额
|
|
|
- $orderCount = isset($result['count']) ? $result['count'] : 0;
|
|
|
- $deliveryFee = isset($result['delivery_fee']) ? $result['delivery_fee'] : 0; // 运费
|
|
|
- $storeId = isset($result['store_id']) ? $result['store_id'] : 0; // 企业/商家
|
|
|
- if (empty($orderGoods)) {
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '获取订单商品错误~';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if ($orderTotal <= 0) {
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = '订单金额错误~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if ($orderTotal <= 0) {
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '订单金额错误~';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if ($orderCount <= 0) {
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = '订单商品数量错误~';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if ($orderCount <= 0) {
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '订单商品数量错误~';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 报单积分是否够
|
|
|
+ if ($bdScore < $bdScoreTotal) {
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = '抱歉,您的报单积分不足';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 报单积分是否够
|
|
|
- if ($bdScore < $bdScoreTotal) {
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '抱歉,您的报单积分不足';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 是否购买过
|
|
|
+ $buyLimit = ConfigService::make()->getConfigByCode('business_buy_limit', 0);
|
|
|
+ $buyLimit = $buyLimit>0?$buyLimit:0;
|
|
|
+ if($buyLimit>0){
|
|
|
+ $checkOrderCount = $this->checkBusinessOrder($userId, $mealId);
|
|
|
+ if ($checkOrderCount >= $buyLimit) {
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = $buyLimit>1?"抱歉该创业礼包仅限购买{$buyLimit}次":'抱歉,您已经购买过该礼包';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 是否购买过
|
|
|
- $buyLimit = ConfigService::make()->getConfigByCode('business_buy_limit', 0);
|
|
|
- $buyLimit = $buyLimit>0?$buyLimit:0;
|
|
|
- if($buyLimit>0){
|
|
|
- $checkOrderCount = $this->checkBusinessOrder($userId, $mealId);
|
|
|
- if ($checkOrderCount >= $buyLimit) {
|
|
|
+ // 收货地址信息
|
|
|
+ $addressInfo = MemberAddressService::make()->getBindInfo($userId);
|
|
|
+ $realname = isset($addressInfo['realname']) ? $addressInfo['realname'] : '';
|
|
|
+ $mobile = isset($addressInfo['mobile']) ? $addressInfo['mobile'] : '';
|
|
|
+ $area = isset($addressInfo['area']) ? $addressInfo['area'] : '';
|
|
|
+ $address = isset($addressInfo['address']) ? $addressInfo['address'] : '';
|
|
|
+ if (empty($addressInfo) || empty($realname) || empty($mobile) || empty($area) || empty($address)) {
|
|
|
RedisService::clear($cacheLockKey);
|
|
|
- $this->error = $buyLimit>1?"抱歉该创业礼包仅限购买{$buyLimit}次":'抱歉,您已经购买过该礼包';
|
|
|
+ $this->error = '收货地址信息错误,请核对后重试~';
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 收货地址信息
|
|
|
- $addressInfo = MemberAddressService::make()->getBindInfo($userId);
|
|
|
- $realname = isset($addressInfo['realname']) ? $addressInfo['realname'] : '';
|
|
|
- $mobile = isset($addressInfo['mobile']) ? $addressInfo['mobile'] : '';
|
|
|
- $area = isset($addressInfo['area']) ? $addressInfo['area'] : '';
|
|
|
- $address = isset($addressInfo['address']) ? $addressInfo['address'] : '';
|
|
|
- if (empty($addressInfo) || empty($realname) || empty($mobile) || empty($area) || empty($address)) {
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '收货地址信息错误,请核对后重试~';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 是否开启分账功能
|
|
|
+ $payTotal = moneyFormat($orderTotal + $deliveryFee, 2); // 含运费支付金额
|
|
|
+ if($balance < $payTotal){
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = "自动复购失败,您的余额不足";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 是否开启分账功能
|
|
|
- $payTotal = moneyFormat($orderTotal + $deliveryFee, 2); // 含运费支付金额
|
|
|
- if($balance < $payTotal){
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = "自动复购失败,您的余额不足";
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 订单数据
|
|
|
+ $order = [
|
|
|
+ 'order_no' => $orderNo,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'store_id' => $storeId,
|
|
|
+ 'meal_id' => $mealId,
|
|
|
+ 'type' => $type,
|
|
|
+ 'total' => $goodsTotal, // 商品总价
|
|
|
+ 'num' => $orderCount,
|
|
|
+ 'bd_score' => $bdScoreTotal, // 折扣后商品总价(不含运费)
|
|
|
+ 'profit_total' => $profitTotal, // 折扣后商品总价(不含运费)
|
|
|
+ 'pay_money' => $orderTotal, // 折扣后商品总价(不含运费)
|
|
|
+ 'pay_total' => $type==2 && $bdScoreTotal>0?moneyFormat($orderTotal + $bdScoreTotal,2):$orderTotal, // 折扣后商品总价(不含运费)
|
|
|
+ 'pay_status' => 20, // 折扣后商品总价(不含运费)
|
|
|
+ 'transaction_id' => 'PAY' . time() . rand(1000, 9999),
|
|
|
+ 'discount_point' => $discountPoint,
|
|
|
+ 'discount_total' => $discountTotal, // 折扣金额
|
|
|
+ 'delivery_fee' => $deliveryFee, // 运费
|
|
|
+ 'receiver_name' => $realname,
|
|
|
+ 'receiver_mobile' => $mobile,
|
|
|
+ 'receiver_area' => $area,
|
|
|
+ 'receiver_address' => $address,
|
|
|
+ 'remark' => '自动复购',
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'update_time' => time(),
|
|
|
+ 'status' => 2,
|
|
|
+ 'mark' => 1,
|
|
|
+ ];
|
|
|
|
|
|
- // 订单数据
|
|
|
- $order = [
|
|
|
- 'order_no' => $orderNo,
|
|
|
- 'user_id' => $userId,
|
|
|
- 'store_id' => $storeId,
|
|
|
- 'meal_id' => $mealId,
|
|
|
- 'type' => $type,
|
|
|
- 'total' => $goodsTotal, // 商品总价
|
|
|
- 'num' => $orderCount,
|
|
|
- 'bd_score' => $bdScoreTotal, // 折扣后商品总价(不含运费)
|
|
|
- 'profit_total' => $profitTotal, // 折扣后商品总价(不含运费)
|
|
|
- 'pay_money' => $orderTotal, // 折扣后商品总价(不含运费)
|
|
|
- 'pay_total' => $type==2 && $bdScoreTotal>0?moneyFormat($orderTotal + $bdScoreTotal,2):$orderTotal, // 折扣后商品总价(不含运费)
|
|
|
- 'pay_status' => $type==2 && $bdScoreTotal>0? 30 : 10, // 折扣后商品总价(不含运费)
|
|
|
- 'discount_point' => $discountPoint,
|
|
|
- 'discount_total' => $discountTotal, // 折扣金额
|
|
|
- 'delivery_fee' => $deliveryFee, // 运费
|
|
|
- 'receiver_name' => $realname,
|
|
|
- 'receiver_mobile' => $mobile,
|
|
|
- 'receiver_area' => $area,
|
|
|
- 'receiver_address' => $address,
|
|
|
- 'create_time' => time(),
|
|
|
- 'update_time' => time(),
|
|
|
- 'status' => 1,
|
|
|
- 'mark' => 1,
|
|
|
- ];
|
|
|
+ // 订单处理
|
|
|
+ DB::beginTransaction();
|
|
|
+ if (!$orderId = $this->model->insertGetId($order)) {
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = '创建订单失败';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 订单处理
|
|
|
- DB::beginTransaction();
|
|
|
- if (!$orderId = $this->model->insertGetId($order)) {
|
|
|
- DB::rollBack();
|
|
|
- $this->error = '创建订单失败';
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 订单商品
|
|
|
+ if ($orderGoods && !OrderGoodsModel::insert($orderGoods)) {
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = '处理订单商品错误';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 订单商品
|
|
|
- if ($orderGoods && !OrderGoodsModel::insert($orderGoods)) {
|
|
|
- DB::rollBack();
|
|
|
- $this->error = '处理订单商品错误';
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 创业礼包分单
|
|
|
+ $data = $order;
|
|
|
+ $data['total'] = moneyFormat($data['total'] / 6);
|
|
|
+ $data['bd_score'] = moneyFormat($bdScoreTotal / 6, 2);
|
|
|
+ $data['profit_total'] = moneyFormat($profitTotal / 6, 2);
|
|
|
+ $data['pay_total'] = moneyFormat($orderTotal / 6, 2);
|
|
|
+ $data['pay_money'] = moneyFormat($order['pay_money'] / 6, 2);
|
|
|
|
|
|
- // 创业礼包分单
|
|
|
- $data = $order;
|
|
|
- $data['total'] = moneyFormat($data['total'] / 6);
|
|
|
- $data['bd_score'] = moneyFormat($bdScoreTotal / 6, 2);
|
|
|
- $data['profit_total'] = moneyFormat($profitTotal / 6, 2);
|
|
|
- $data['pay_total'] = moneyFormat($orderTotal / 6, 2);
|
|
|
- $data['pay_money'] = moneyFormat($order['pay_money'] / 6, 2);
|
|
|
-
|
|
|
- $subOrders = [];
|
|
|
- for ($i = 1; $i <= 6; $i++) {
|
|
|
- $data['order_no'] = get_order_num('BS');
|
|
|
- $data['main_no'] = $orderNo;
|
|
|
- if ($i == 6) {
|
|
|
- $data['total'] = round($order['total'] / 6, 2);
|
|
|
- $data['bd_score'] = round($bdScoreTotal / 6, 2);
|
|
|
- $data['profit_total'] = round($profitTotal / 6, 2);
|
|
|
- $data['pay_total'] = round($orderTotal / 6, 2);
|
|
|
- $data['pay_money'] = round($order['pay_money'] / 6, 2);
|
|
|
+ $subOrders = [];
|
|
|
+ for ($i = 1; $i <= 6; $i++) {
|
|
|
+ $data['order_no'] = get_order_num('BS');
|
|
|
+ $data['main_no'] = $orderNo;
|
|
|
+ if ($i == 6) {
|
|
|
+ $data['total'] = round($order['total'] / 6, 2);
|
|
|
+ $data['bd_score'] = round($bdScoreTotal / 6, 2);
|
|
|
+ $data['profit_total'] = round($profitTotal / 6, 2);
|
|
|
+ $data['pay_total'] = round($orderTotal / 6, 2);
|
|
|
+ $data['pay_money'] = round($order['pay_money'] / 6, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $subOrders[] = $data;
|
|
|
}
|
|
|
|
|
|
- $subOrders[] = $data;
|
|
|
- }
|
|
|
+ //
|
|
|
+ if ($subOrders && !$this->model->insert($subOrders)) {
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = '处理商品订单失败';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- //
|
|
|
- if ($subOrders && !$this->model->insert($subOrders)) {
|
|
|
- DB::rollBack();
|
|
|
- $this->error = '处理商品订单失败';
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 扣除报单积分
|
|
|
+ if($bdScoreTotal>0){
|
|
|
+ if(!MemberModel::where(['id'=>$userId])->update(['bd_score'=>DB::raw("bd_score - {$bdScoreTotal}"),'update_time'=>time()])){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = '报单积分扣除失败';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 扣除报单积分
|
|
|
- if($bdScoreTotal>0){
|
|
|
- if(!MemberModel::where(['id'=>$userId])->update(['bd_score'=>DB::raw("bd_score - {$bdScoreTotal}"),'update_time'=>time()])){
|
|
|
+ $data = [
|
|
|
+ 'user_id'=>$userId,
|
|
|
+ 'source_order_no'=>$orderNo,
|
|
|
+ 'user_type'=> 1,
|
|
|
+ 'account_type'=> 3, // 报单积分
|
|
|
+ 'type'=> 1,
|
|
|
+ 'money'=> -$bdScoreTotal,
|
|
|
+ 'after_money'=>moneyFormat($bdScore - $bdScoreTotal,2),
|
|
|
+ 'date'=>date('Y-m-d'),
|
|
|
+ 'create_time'=>time(),
|
|
|
+ 'remark'=> '创业礼包支付',
|
|
|
+ 'status'=>1,
|
|
|
+ 'mark'=>1
|
|
|
+ ];
|
|
|
+ if(!AccountLogModel::insertGetId($data)){
|
|
|
+ Db::rollBack();
|
|
|
+ $this->error = '付款处理失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 余额支付
|
|
|
+ if(!MemberModel::where(['id'=>$userId])->update(['balance'=>DB::raw("balance - {$payTotal}"),'update_time'=>time()])){
|
|
|
DB::rollBack();
|
|
|
- $this->error = '报单积分扣除失败';
|
|
|
+ $this->error = '余额支付失败';
|
|
|
RedisService::clear($cacheLockKey);
|
|
|
return false;
|
|
|
}
|
|
|
@@ -696,98 +728,73 @@ class OrderService extends BaseService
|
|
|
'user_id'=>$userId,
|
|
|
'source_order_no'=>$orderNo,
|
|
|
'user_type'=> 1,
|
|
|
- 'account_type'=> 3, // 报单积分
|
|
|
+ 'account_type'=> 1, // 余额支付
|
|
|
'type'=> 1,
|
|
|
- 'money'=> -$bdScoreTotal,
|
|
|
- 'after_money'=>moneyFormat($bdScore - $bdScoreTotal,2),
|
|
|
+ 'money'=> -$payTotal,
|
|
|
+ 'after_money'=>moneyFormat($balance - $payTotal,2),
|
|
|
'date'=>date('Y-m-d'),
|
|
|
'create_time'=>time(),
|
|
|
- 'remark'=> '创业礼包支付',
|
|
|
+ 'remark'=> '创业礼包自动复购支付',
|
|
|
'status'=>1,
|
|
|
'mark'=>1
|
|
|
];
|
|
|
if(!AccountLogModel::insertGetId($data)){
|
|
|
Db::rollBack();
|
|
|
- $this->error = '付款处理失败';
|
|
|
+ $this->error = '自动复购付款处理失败';
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 余额支付
|
|
|
- if(!MemberModel::where(['id'=>$userId])->update(['balance'=>DB::raw("balance - {$payTotal}"),'update_time'=>time()])){
|
|
|
- DB::rollBack();
|
|
|
- $this->error = '余额支付失败';
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
- $data = [
|
|
|
- 'user_id'=>$userId,
|
|
|
- 'source_order_no'=>$orderNo,
|
|
|
- 'user_type'=> 1,
|
|
|
- 'account_type'=> 1, // 余额支付
|
|
|
- 'type'=> 1,
|
|
|
- 'money'=> -$payTotal,
|
|
|
- 'after_money'=>moneyFormat($balance - $payTotal,2),
|
|
|
- 'date'=>date('Y-m-d'),
|
|
|
- 'create_time'=>time(),
|
|
|
- 'remark'=> '创业礼包自动复购支付',
|
|
|
- 'status'=>1,
|
|
|
- 'mark'=>1
|
|
|
- ];
|
|
|
- if(!AccountLogModel::insertGetId($data)){
|
|
|
- Db::rollBack();
|
|
|
- $this->error = '自动复购付款处理失败';
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 佣金数据
|
|
|
- $order['id'] = $orderId;
|
|
|
- if(!$commission = SettleService::make()->commissionCount($order,$orderGoods,$userInfo, $type)){
|
|
|
- Db::rollBack();
|
|
|
- $this->error = '订单结算处理失败';
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 结算
|
|
|
- if(!$settle = SettleService::make()->commissionSettle($orderId)){
|
|
|
- Db::rollBack();
|
|
|
- $this->error = '订单结算处理失败';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 佣金数据
|
|
|
+ $order['id'] = $orderId;
|
|
|
+ if(!$commission = SettleService::make()->commissionCount($order,$orderGoods,$userInfo, $type)){
|
|
|
+ Db::rollBack();
|
|
|
+ $this->error = '订单结算处理失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 商品库存扣除
|
|
|
- if ($orderGoods) {
|
|
|
- foreach ($orderGoods as $item) {
|
|
|
- $id = isset($item['goods_id']) ? $item['goods_id'] : 0;
|
|
|
- $num = isset($item['num']) ? $item['num'] : 0;
|
|
|
- $skuId = isset($item['sku_id']) ? $item['sku_id'] : 0;
|
|
|
- if ($id && !GoodsModel::where(['id' => $id])->update(['stock' => DB::raw("stock - {$num}"), 'update_time' => time()])) {
|
|
|
- DB::rollBack();
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '商品库存处理失败';
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 结算
|
|
|
+ if(!$settle = SettleService::make()->commissionSettle($orderId)){
|
|
|
+ Db::rollBack();
|
|
|
+ $this->error = '订单结算处理失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if ($skuId && !GoodsSkuModel::where(['id' => $skuId])->update(['stock' => DB::raw("stock - {$num}"), 'update_time' => time()])) {
|
|
|
- DB::rollBack();
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- $this->error = '商品库存处理失败';
|
|
|
- return false;
|
|
|
+ // 商品库存扣除
|
|
|
+ if ($orderGoods) {
|
|
|
+ foreach ($orderGoods as $item) {
|
|
|
+ $id = isset($item['goods_id']) ? $item['goods_id'] : 0;
|
|
|
+ $num = isset($item['num']) ? $item['num'] : 0;
|
|
|
+ $skuId = isset($item['sku_id']) ? $item['sku_id'] : 0;
|
|
|
+ if ($id && !GoodsModel::where(['id' => $id])->update(['stock' => DB::raw("stock - {$num}"), 'update_time' => time()])) {
|
|
|
+ DB::rollBack();
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = '商品库存处理失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($skuId && !GoodsSkuModel::where(['id' => $skuId])->update(['stock' => DB::raw("stock - {$num}"), 'update_time' => time()])) {
|
|
|
+ DB::rollBack();
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = '商品库存处理失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 用户操作记录
|
|
|
- DB::commit();
|
|
|
- $this->error = '自动复购成功~';
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- return [
|
|
|
- 'order_id' => $orderId,
|
|
|
- 'total' => $payTotal,
|
|
|
- 'pay_type' => 10,
|
|
|
- ];
|
|
|
+ // 用户操作记录
|
|
|
+ DB::commit();
|
|
|
+ $this->error = '自动复购成功~';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return [
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'total' => $payTotal,
|
|
|
+ 'pay_type' => 10,
|
|
|
+ ];
|
|
|
+ } catch (\Exception $exception){
|
|
|
+ $this->error = $exception->getMessage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -808,7 +815,6 @@ class OrderService extends BaseService
|
|
|
->where('status', '<=', 5)
|
|
|
->where('refund_status', '<=', 0)
|
|
|
->count('id');
|
|
|
- $data = $data ? $data->toArray() : [];
|
|
|
if ($data) {
|
|
|
RedisService::set($cacheKey, $data, rand(5, 10));
|
|
|
}
|
|
|
@@ -1187,7 +1193,6 @@ class OrderService extends BaseService
|
|
|
DB::commit();
|
|
|
$this->error = '确认收货成功';
|
|
|
RedisService::clear("caches:orders:completeList");
|
|
|
- RedisService::clear("caches:orders:revenueList");
|
|
|
return ['id' => $id, 'msg' => $this->error];
|
|
|
}
|
|
|
|