wesmiler 2 дней назад
Родитель
Сommit
fab1bcea78

+ 2 - 1
app/Http/Controllers/Api/v1/GoodsController.php

@@ -32,8 +32,9 @@ class GoodsController extends webApp
     {
         $params =request()->post();
         $goods = isset($params['goods']) && $params['goods'] ? $params['goods'] : [];
+        $couponId = isset($params['coupon_id']) && $params['coupon_id'] ? $params['coupon_id'] : 0;
         $ids = $goods ? array_column($goods, 'id') : [];
-        if($datas = GoodsService::make()->getOrderGoods($ids, $goods, $this->userId)){
+        if($datas = GoodsService::make()->getOrderGoods($ids, $goods, $this->userId,'',0,$couponId)){
             return message(1010, true, $datas);
         }else{
             $error = GoodsService::make()->getError();

+ 30 - 8
app/Services/Api/OrderService.php

@@ -232,6 +232,7 @@ class OrderService extends BaseService
     {
         $addressId = isset($params['address_id']) && $params['address_id'] ? $params['address_id'] : 0;
         $couponId = isset($params['coupon_id']) && $params['coupon_id'] ? $params['coupon_id'] : 0;
+        $payType = isset($params['pay_type']) && $params['pay_type'] ? $params['pay_type'] : 10;
         $submitType = isset($params['submit_type']) && $params['submit_type'] ? $params['submit_type'] : 0;
         $goods = isset($params['goods']) && $params['goods'] ? $params['goods'] : [];
         $ids = $goods ? array_column($goods, 'id') : [];
@@ -255,12 +256,13 @@ class OrderService extends BaseService
 
         // 用户信息
         RedisService::set($cacheLockKey, ['params' => $params, 'user_id' => $userId], rand(3, 5));
-        $userInfo = MemberModel::where(['id' => $userId, 'mark' => 1])
+        $userInfo = MemberModel::with(['levelData'])->where(['id' => $userId, 'mark' => 1])
             ->select(['id', 'openid', 'discount_point', 'status'])
             ->first();
         $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
         $openid = isset($userInfo['openid']) ? $userInfo['openid'] : 0;
-        $discountPoint = isset($userInfo['discount_point']) ? $userInfo['discount_point'] : 0; // 折扣
+        $vipExpired = isset($userInfo['vip_expired']) ? $userInfo['vip_expired'] : 0;
+        $levelData = isset($userInfo['level_data']) ? $userInfo['level_data'] : [];
         if (empty($userInfo) || $status != 1) {
             $this->error = 1045;
             return false;
@@ -271,9 +273,15 @@ class OrderService extends BaseService
             return false;
         }
 
+        // 有效会员和折扣
+        $discountPoint = 0;
+        if($vipExpired != 0){
+            $discountPoint = isset($levelData['discount']) ? $levelData['discount'] : 0; // 会员折扣
+        }
+
         // 商品数据
         $orderNo = get_order_num('JK');
-        $result = GoodsService::make()->getOrderGoods($ids, $goods, $userId, $orderNo,$discountPoint);
+        $result = GoodsService::make()->getOrderGoods($ids, $goods, $userId, $orderNo,$discountPoint,$couponId);
         if (empty($result)) {
             RedisService::clear($cacheLockKey);
             $this->error = GoodsService::make()->getError();
@@ -285,7 +293,6 @@ class OrderService extends BaseService
         $orderTotal = isset($result['order_total']) ? $result['order_total'] : 0; // 订单结算金额(折后)
         $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 会员折扣金额
         $couponTotal = isset($result['coupon_total']) ? $result['coupon_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; // 企业/商家
@@ -337,6 +344,7 @@ class OrderService extends BaseService
             'store_id' => $storeId,
             'total' => $goodsTotal, // 商品总价
             'num' => $orderCount,
+            'pay_type' => $payType, // 支付方式
             'pay_total' => $orderTotal, // 折扣后商品总价(不含运费)
             'discount_point' => $discountPoint, //会员折扣
             'discount_total' => $discountTotal, // 会员折扣金额
@@ -373,6 +381,15 @@ class OrderService extends BaseService
             return false;
         }
 
+        // 商家佣金和收益计算
+        $order['id'] = $orderId;
+        if(!$commission = SettleService::make()->commissionCount($order, $orderGoods, $userInfo)){
+            Db::rollBack();
+            $this->error = '订单处理失败';
+            return false;
+        }
+
+
         // 获取支付参数
         /* TODO 支付处理 */
         $payOrder = [
@@ -387,7 +404,6 @@ class OrderService extends BaseService
         // 调起支付
         $payment = PaymentService::make()->minPay($userInfo, $payOrder, 'store');
         if (empty($payment)) {
-//                DB::rollBack();
             RedisService::clear($cacheLockKey);
             $this->error = PaymentService::make()->getError();
             return false;
@@ -440,7 +456,7 @@ class OrderService extends BaseService
      * @param $id
      * @return array|false
      */
-    public function pay($userId, $id)
+    public function pay($userId, $id, $payType=10)
     {
         if ($id <= 0) {
             $this->error = '请选择支付订单';
@@ -448,7 +464,7 @@ class OrderService extends BaseService
         }
 
         // 缓存锁
-        $cacheLockKey = "caches:orders:pay_lock:{$userId}_{$id}";
+        $cacheLockKey = "caches:orders:pay_lock:{$userId}_{$id}_{$payType}";
         if (RedisService::get($cacheLockKey)) {
             $this->error = '订单处理中~';
             return false;
@@ -495,6 +511,7 @@ class OrderService extends BaseService
             return false;
         }
 
+        DB::beginTransaction();
         // 获取支付参数
         /* TODO 支付处理 */
         $payOrder = [
@@ -514,6 +531,11 @@ class OrderService extends BaseService
             return false;
         }
 
+        // 更新支付方式
+        $info->pay_type = $payType;
+        $info->update_time = time();
+        $info->save();
+
         // 用户操作记录
         DB::commit();
         $this->error = '支付请求成功,请前往支付~';
@@ -522,7 +544,7 @@ class OrderService extends BaseService
             'order_id' => $id,
             'payment' => $payment,
             'total' => $payOrder['pay_money'],
-            'pay_type' => 10,
+            'pay_type' => $payType,
         ];
     }
 

+ 292 - 65
app/Services/Api/SettleService.php

@@ -13,8 +13,10 @@ namespace App\Services\Api;
 
 use App\Models\AccountLogModel;
 use App\Models\CouponModel;
-use App\Models\MeetingModel;
 use App\Models\MemberCouponModel;
+use App\Models\MemberModel;
+use App\Models\OrderCommissionModel;
+use App\Models\OrderModel;
 use App\Models\StoreModel;
 use App\Services\BaseService;
 use App\Services\ConfigService;
@@ -52,56 +54,281 @@ class SettleService extends BaseService
     }
 
     /**
-     * 商家收益结
-     * @param $storeId
-     * @param $money 收益
-     * @param $order 订单数据
-     * @return array|false|int
+     * 佣金奖励计
+     * @param $order 订单信息
+     * @param $orderGoods 订单商品
+     * @param $userInfo 用户信息
+     * @param $settle 是否直接结算
      */
-    public function storeBonus($storeId, $money, $order)
+    public function commissionCount($order, $orderGoods, $userInfo, $settle = false)
     {
-        $orderNo = isset($order['order_no'])? $order['order_no'] : '';
-        if($money<=0 && $storeId<=0){
-            $this->error = '无企业佣金可结算';
-            return false;
-        }
+        $userId = isset($order['user_id']) ? $order['user_id'] : 0;
+        $storeId = isset($order['store_id']) ? $order['store_id'] : 0;
+        $orderId = isset($order['id']) ? $order['id'] : 0;
+        $orderNo = isset($order['order_no']) ? $order['order_no'] : '';
+        $orderTotal = isset($order['pay_total']) ? $order['pay_total'] : 0;
+        $data = [
+            'order_id' => $orderId,
+            'user_id' => $userId,
+            'order_no' => $orderNo,
+            'store_id' => $storeId,
+            'total' => $orderTotal,
+            'create_time' => time(),
+            'status' => 2,
+            'mark' => 1,
+        ];
+        $errors = [];
+        /* TODO 计算商家佣金 */
+        if ($storeId > 0) {
+            $storeInfo = StoreModel::where(['id' => $storeId])->first();
+            $bonusRate = isset($storeInfo['bonus_rate']) ? floatval($storeInfo['bonus_rate']) : 0;
+            $storeBonusRate = ConfigService::make()->getConfigByCode('store_bonus_rate', 0);
+            $storeBonusRate = $storeBonusRate > 0 && $storeBonusRate <= 100 ? $storeBonusRate : 0;
+            $bonusRate = $bonusRate > 0 && $bonusRate <= 100 ? $bonusRate : $storeBonusRate;
+            $bonus = moneyFormat($orderTotal * $bonusRate / 100, 2);
 
-        $storeInfo = StoreModel::where(['id'=> $storeId,'mark'=>1])->first();
-        $balance = isset($storeInfo['bonus_total'])? $storeInfo['bonus_total'] : 0;
-        $storeUserId = isset($storeInfo['user_id'])? $storeInfo['user_id'] : 0;
-        if($storeUserId<=0){
-            $this->error = '企业账号错误';
-            return false;
+            $data['bonus'] = $bonus;
+            $data['bonus_rate'] = $bonusRate;
         }
 
-        if(!StoreModel::where(['id'=> $storeId])->update(['bonus_total'=>DB::raw("bonus_total + {$money}"),'update_time'=>time()])){
-            $this->error = '收货错误,企业结算错误,请联系客服处理';
-            return -1;
+        /* TODO 计算分销奖励  */
+        $parents = isset($userInfo['parents']) ? $userInfo['parents'] : '';
+        $parents = $parents ? explode(',', $parents) : [];
+        $parents = array_filter($parents);
+        $parents = array_reverse($parents); // 由下到上1-3层
+        $rewardLevel = ConfigService::make()->getConfigByCode('commission_level', 2);
+        $parents = array_splice($parents, 0, $rewardLevel);
+
+        // 分销奖励计算
+        if ($parents) {
+            $userList = MemberModel::with(['levelData'])->whereIn('id', $parents)
+                ->select(['id', 'nickname', 'mobile', 'member_level', 'status', 'mark'])
+                ->orderBy(DB::raw("FIELD(id, " . implode(',', $parents) . ")"))
+                ->get();
+
+            $bonusRows = ConfigService::make()->getConfigByGroup(11);
+            foreach ($userList as $k => $user) {
+                // 默认只分2层
+                $layer = $k + 1;
+                if ($layer > $rewardLevel) {
+                    continue;
+                }
+
+                // 处理奖励数据
+                $pid = isset($point['id']) ? $point['id'] : 0;
+                $pMark = isset($point['mark']) ? $point['mark'] : 0;
+                $data["bonus_level{$layer}_uid"] = $pid;
+                $bonus = isset($bonusRows['bonus_rate_level' . $layer]) ? $bonusRows['bonus_rate_level' . $layer] : 0;
+                $bonusData = [
+                    'id' => $pid,
+                    'nickname' => isset($point['nickname']) ? $point['nickname'] : '',
+                    'mobile' => isset($point['mobile']) ? $point['mobile'] : '',
+                    'layer' => $layer,
+                    'bonus' => 0,
+                ];
+                if ($pMark == 1) {
+                    $bonusData['bonus'] = $bonus;
+                } else {
+                    $bonusData["error"] = "{$layer}级分销用户不存在";
+                }
+
+                // 数据
+                $data["bonus_level{$layer}_data"] = json_encode($bonusData, 256);
+            }
         }
 
-        $log = [
-            'user_id'=> $storeUserId,
-            'store_id'=> $storeId,
-            'source_order_no'=> isset($order['order_no'])? $order['order_no'] : '',
-            'type'=> 7,
-            'money'=> $money,
-            'after_money'=> moneyFormat($balance+$money,2),
-            'date'=>date('Y-m-d'),
-            'create_time'=>time(),
-            'remark'=> '收益',
-            'status'=>1
-        ];
-        if(!$id = $this->model->insertGetId($log)){
-            $this->error = '企业收益结算失败,请联系客服处理';
-            return -1;
+        // 佣金数据入库
+        if (!$cid = OrderCommissionModel::where(['order_no' => $orderNo])->value('id')) {
+            $cid = OrderCommissionModel::insertGetId($data);
+        } else {
+            OrderCommissionModel::where(['id' => $cid])->update($data);
         }
 
-        $result = ['id'=>$id,'store_id'=>$storeId,'bonus'=>$money];
-        if(env('APP_DEBUG')){
-            RedisService::set("caches:settle:{$orderNo}:store_{$storeId}", $result, 7200);
+        // 是否直接结算
+        if($settle){
+            return $this->commissionSettle($orderId);
         }
 
-        return $result;
+        $this->error = '佣金计算成功';
+        $data['id'] = $cid;
+        return $data;
+    }
+
+    /**
+     * 订单佣金结算
+     * @param $orderId 订单ID
+     * @return array|false
+     */
+    public function commissionSettle($orderId)
+    {
+        try {
+            $info = OrderModel::with(['commission', 'user'])
+                ->where(['id' => $orderId, 'mark' => 1])
+                ->select(['id', 'order_no', 'user_id', 'total', 'pay_total', 'pay_status', 'status', 'refund_status'])
+                ->first();
+            $info = $info ? $info->toArray() : [];
+            if (empty($info)) {
+                $this->error = '结算订单不存在';
+                return false;
+            }
+
+            if ($info['status'] <= 1 || $info['pay_status'] == 10) {
+                $this->error = '订单未支付';
+                return false;
+            }
+
+            if (in_array($info['refund_status'], [1, 2, 3])) {
+                $this->error = '订单已退款';
+                return false;
+            }
+
+            $orderNo = isset($info['order_no']) ? $info['order_no'] : '';
+            $orderUserId = isset($info['user_id']) ? $info['user_id'] : 0;
+            $user = isset($info['user']) ? $info['user'] : [];
+            $mobile = isset($user['mobile']) ? $user['mobile'] : $orderUserId;
+            $commission = isset($info['commission']) ? $info['commission'] : [];
+            $commissionId = isset($commission['id']) ? $commission['id'] : 0;
+            if (empty($commission) || $commissionId <= 0) {
+                $this->error = '结算订单收益参数错误';
+                return false;
+            }
+
+            if ($commission['status'] == 1) {
+                $this->error = '订单收益已结算';
+                return false;
+            }
+
+            $cacheKey = "caches:ordersCommission:{$orderNo}_{$orderUserId}:";
+            if (RedisService::get("{$cacheKey}lock")) {
+                $this->error = '订单结算中';
+                return false;
+            }
+
+            //  创业订单
+            $logs = [];
+            RedisService::set("{$cacheKey}lock", $info, 300);
+
+            // TODO 商家结算
+            $storeInfo = isset($commission['store']) ? $commission['store'] : [];
+            $storeId = isset($commission['store_id']) ? $commission['store_id'] : 0;
+            $storeBonus = isset($commission['bonus']) ? $commission['bonus'] : 0;
+            $storeUserId = isset($storeInfo['user_id']) ? $storeInfo['user_id'] : 0;
+            $storeBalance = isset($storeInfo['balance']) ? $storeInfo['balance'] : 0;
+            if ($storeId > 0 && $storeInfo && $storeBonus > 0) {
+                $updateData = [
+                    'balance' => DB::raw("balance + {$storeBonus}"),
+                    'income' => DB::raw("income + {$storeBonus}"),
+                    'update_time' => time()
+                ];
+                if (!StoreModel::where(['id' => $storeId])->update($updateData)) {
+                    $this->error = '商家提成结算失败';
+                    RedisService::clear("{$cacheKey}lock");
+                    return false;
+                }
+
+                $storeBalance = moneyFormat($storeBalance + $storeBonus, 2);
+                $data = [
+                    'user_id' => $storeUserId,
+                    'store_id' => $storeId,
+                    'source_order_no' => $orderNo,
+                    'user_type' => 2,
+                    'type' => 7,
+                    'bonus_type' => 0,
+                    'money' => $storeBonus,
+                    'after_money' => $storeBalance,
+                    'date' => date('Y-m-d'),
+                    'create_time' => time(),
+                    'remark' => '商家结算',
+                    'remark1' => "用户[{$mobile}]购买商品订单结算",
+                    'status' => 1,
+                    'mark' => 1
+                ];
+
+                $logs[] = $data;
+            }
+
+            // TODO 分销结算
+            $layer = 3;
+            $bonusUids = [];
+            for ($i = 1; $i <= $layer; $i++) {
+                $uid = isset($commission["bonus_level{$i}_uid"]) ? $commission["bonus_level{$i}_uid"] : 0;
+                if ($uid) {
+                    $bonusUids[] = $uid;
+                }
+            }
+
+            $bonusUsers = MemberModel::whereIn('id', $bonusUids)
+                ->select(['id', 'openid', 'balance', 'mobile', 'nickname', 'property', 'ls_score', 'status'])
+                ->get()
+                ->keyBy('id');
+            $bonusUsers = $bonusUsers ? $bonusUsers->toArray() : [];
+            for ($i = 1; $i <= $layer; $i++) {
+                $uid = isset($commission["bonus_level{$i}_uid"]) ? $commission["bonus_level{$i}_uid"] : 0;
+                $bonusData = isset($commission["bonus_level{$i}_data"]) ? $commission["bonus_level{$i}_data"] : '';
+                $bonusData = $bonusData ? json_decode($bonusData, true) : [];
+                $bonus = isset($bonusData['bonus']) ? $bonusData['bonus'] : 0;
+                $bonusUser = isset($bonusUsers[$uid]) ? $bonusUsers[$uid] : [];
+                $bonusUserBalance = isset($bonusUser['balance']) ? $bonusUser['balance'] : 0;
+                if ($uid && $bonusUser && $bonus > 0) {
+                    $updateData = [
+                        'balance' => DB::raw("balance + {$bonus}"),
+                        'bonus_total' => DB::raw("bonus_total + {$bonus}"),
+                        'update_time' => time()
+                    ];
+                    if (!MemberModel::where(['id' => $uid])->update($updateData)) {
+                        $this->error = '分销收益结算错误';
+                        RedisService::clear("{$cacheKey}lock");
+                        return false;
+                    }
+
+                    if ($bonus > 0) {
+                        $bonusUserBalance = moneyFormat($bonusUserBalance + $bonus, 2);
+                        $data = [
+                            'user_id' => $uid,
+                            'source_order_no' => $orderNo,
+                            'user_type' => 1,
+                            'type' => 8,
+                            'bonus_type' => 1,
+                            'money' => $bonus,
+                            'after_money' => $bonusUserBalance,
+                            'date' => date('Y-m-d'),
+                            'create_time' => time() + $i,
+                            'remark' => "分销奖励",
+                            'remark1' => "用户ID:{$orderUserId}购买商品{$i}级分销奖励",
+                            'status' => 1,
+                            'mark' => 1
+                        ];
+
+                        $logs[] = $data;
+                    }
+                }
+            }
+
+            // TODO 明细入表
+            RedisService::set("{$cacheKey}logs", $logs, 3600);
+            if ($logs && !AccountLogModel::insert($logs)) {
+                $this->error = '奖励明细结算处理错误';
+                RedisService::clear("{$cacheKey}lock");
+                return false;
+            }
+
+            // 订单结算状态更新
+            if (!OrderCommissionModel::where(['id' => $commissionId])->update(['status' => 1, 'arrival_at' => date('Y-m-d H:i:s'), 'update_time' => time()])) {
+                $this->error = '订单结算状态更新失败';
+                return false;
+            }
+
+            $this->error = '订单结算完成';
+            RedisService::clear("{$cacheKey}lock");
+            RedisService::clear("caches:orders:settleList");
+            RedisService::set("{$cacheKey}result", $info, 3600);
+            $result = ['id' => $orderId, 'user_id' => $orderUserId, 'logs' => $logs, 'commission' => $commission];
+            RedisService::set("caches:settles:{$orderId}_{$orderNo}_success", $result, 7200);
+            return $result;
+        } catch (\Exception $exception) {
+            RedisService::set("caches:settles:{$orderId}_error", ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()], 7200);
+            return false;
+        }
     }
 
     /**
@@ -111,52 +338,52 @@ class SettleService extends BaseService
      */
     public function registerReward($userId)
     {
-        $rewardOpen = ConfigService::make()->getConfigByCode('register_award_coupon',0);
-        $rewardCouponId = ConfigService::make()->getConfigByCode('register_reward_coupon_id',0);
-        if($rewardCouponId<=0 || $rewardOpen!= 1){
+        $rewardOpen = ConfigService::make()->getConfigByCode('register_award_coupon', 0);
+        $rewardCouponId = ConfigService::make()->getConfigByCode('register_reward_coupon_id', 0);
+        if ($rewardCouponId <= 0 || $rewardOpen != 1) {
             $this->error = '未开启或配置注册优惠券奖励';
             return true;
         }
 
-        $couponInfo = CouponModel::where(['id'=>$rewardCouponId,'mark'=>1])
+        $couponInfo = CouponModel::where(['id' => $rewardCouponId, 'mark' => 1])
             ->first();
-        $status = isset($couponInfo['status'])?$couponInfo['status']:0;
-        $num = isset($couponInfo['num'])?$couponInfo['num']:0;
-        $receivedNum = isset($couponInfo['received_num'])?$couponInfo['received_num']:0;
-        if(empty($couponInfo) || $status != 1){
+        $status = isset($couponInfo['status']) ? $couponInfo['status'] : 0;
+        $num = isset($couponInfo['num']) ? $couponInfo['num'] : 0;
+        $receivedNum = isset($couponInfo['received_num']) ? $couponInfo['received_num'] : 0;
+        if (empty($couponInfo) || $status != 1) {
             $this->error = '配置的注册奖励优惠券不存在或无效';
             return true;
         }
 
-        if($num>0 && $receivedNum>=$num){
+        if ($num > 0 && $receivedNum >= $num) {
             $this->error = '注册奖励优惠券已发放完~';
             return true;
         }
 
         $data = [
-            'coupon_id'=> $rewardCouponId,
-            'user_id'=> $userId,
-            'store_id'=> isset($couponInfo['store_id'])?$couponInfo['store_id']:0,
-            'name'=> isset($couponInfo['name'])?$couponInfo['name']:'',
-            'coupon_type'=> isset($couponInfo['coupon_type'])?$couponInfo['coupon_type']: 20,
-            'reduce_price'=> isset($couponInfo['reduce_price'])?$couponInfo['reduce_price']:0,
-            'discount'=> isset($couponInfo['discount'])?$couponInfo['discount']:0,
-            'min_price'=> isset($couponInfo['min_price'])?$couponInfo['min_price']:0,
-            'expire_day'=> isset($couponInfo['expire_day'])?$couponInfo['expire_day']:0,
-            'start_time'=> isset($couponInfo['start_time'])?$couponInfo['start_time']:0,
-            'end_time'=> isset($couponInfo['end_time'])?$couponInfo['end_time']:0,
-            'goods_ids'=> isset($couponInfo['goods_ids'])&&$couponInfo['goods_ids']?$couponInfo['goods_ids']:'',
-            'create_time'=> time(),
-            'status'=> 1,
+            'coupon_id' => $rewardCouponId,
+            'user_id' => $userId,
+            'store_id' => isset($couponInfo['store_id']) ? $couponInfo['store_id'] : 0,
+            'name' => isset($couponInfo['name']) ? $couponInfo['name'] : '',
+            'coupon_type' => isset($couponInfo['coupon_type']) ? $couponInfo['coupon_type'] : 20,
+            'reduce_price' => isset($couponInfo['reduce_price']) ? $couponInfo['reduce_price'] : 0,
+            'discount' => isset($couponInfo['discount']) ? $couponInfo['discount'] : 0,
+            'min_price' => isset($couponInfo['min_price']) ? $couponInfo['min_price'] : 0,
+            'expire_day' => isset($couponInfo['expire_day']) ? $couponInfo['expire_day'] : 0,
+            'start_time' => isset($couponInfo['start_time']) ? $couponInfo['start_time'] : 0,
+            'end_time' => isset($couponInfo['end_time']) ? $couponInfo['end_time'] : 0,
+            'goods_ids' => isset($couponInfo['goods_ids']) && $couponInfo['goods_ids'] ? $couponInfo['goods_ids'] : '',
+            'create_time' => time(),
+            'status' => 1,
         ];
 
-        if(!$id = MemberCouponModel::insertGetId($data)){
+        if (!$id = MemberCouponModel::insertGetId($data)) {
             $this->error = '奖励注册优惠券失败';
             return true;
         }
 
         // 更新发放统计
-        CouponModel::where(['id'=> $id])->update(['received_num'=>DB::raw("received_num+1"),'update_time'=>time()]);
+        CouponModel::where(['id' => $id])->update(['received_num' => DB::raw("received_num+1"), 'update_time' => time()]);
 
         $data['id'] = $id;
         $data['discount'] = floatval($data['discount']);

+ 0 - 1
app/Services/PaymentService.php

@@ -12,7 +12,6 @@
 namespace App\Services;
 
 use App\Models\AccountLogModel;
-use App\Models\AccountStatisticsModel;
 use App\Models\OrderModel;
 use App\Models\PaymentModel;
 use Illuminate\Support\Facades\DB;