gorden пре 5 месеци
родитељ
комит
87b8cd42b9

+ 4 - 4
app/admin/service/coupon/CouponService.php

@@ -185,7 +185,7 @@ class CouponService
     public static function autoSendCouponByGoods($params)
     {
         try {
-
+            $gettype = $params['gettype'] ?? '';
             $goods = Goods::where('goods_id', $params['join_sheet_goods_id'])->select('goods_attribute_json')->first();
             if (!empty($goods) && !empty($goods->goods_attribute_json)) {
                 $goodsAttributeJson = json_decode($goods->goods_attribute_json, true);
@@ -202,7 +202,7 @@ class CouponService
                         // 发周期券
                         if ($couponModel->coupon_is_period == 'Y') {
                             // 发券参数
-                            $couponSendParams = ['gettype' => 'PARTNER', 'coupon_id' => $key, 'member_id' => $params['member_id']];
+                            $couponSendParams = ['gettype' => $gettype, 'coupon_id' => $key, 'member_id' => $params['member_id']];
                             Log::info("发周期券参数", $couponSendParams);
                             CouponDetailService::sendPeriodCoupon($couponSendParams);
                             continue;
@@ -223,7 +223,7 @@ class CouponService
                         }
                         // 发券参数
                         $couponSendParams = [
-                            'gettype' => 'PARTNER',
+                            'gettype' => $gettype,
                             'coupon_id' => $key,
                             'chooseCouponNbr' => $coupon['num'],
                             'member_id' => $params['member_id'],
@@ -243,7 +243,7 @@ class CouponService
                 }
             }
         }catch (\Exception $e){
-            dump($e->getMessage());
+            Log::info("优惠券发放失败:".$e->getMessage());
             throw new BusinessException("优惠券发放失败");
         }
     }

+ 37 - 6
app/admin/service/member/MemberService.php

@@ -24,6 +24,7 @@ use app\model\SysSerial;
 use app\model\SysUser;
 use support\Db;
 use support\exception\BusinessException;
+use support\Log;
 use support\Request;
 use support\Response;
 
@@ -957,7 +958,7 @@ class MemberService
 //            ->toArray();
 
         $memberAccountList = MemberAccountList::where('join_member_account_list_member_id', $memberId)
-            ->where('member_account_list_status','ACTIVED')
+            ->where('member_account_list_status', 'ACTIVED')
             ->selectRaw('
                 member_account_list_extend_json as join_pay_object_json,
                 join_member_account_list_member_id as join_pay_member_id,
@@ -1026,7 +1027,7 @@ class MemberService
                 $item['balance_type'] = 'cut';
             }
             if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE'])) {
-                if (!empty($item['pay_extend_json']) && !in_array($item['join_pay_order_id'],['PARTNER', 'COMBINE'])) {
+                if (!empty($item['pay_extend_json']) && !in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE'])) {
                     $extendJson = json_decode($item['pay_extend_json'], true);
                     if (!isset($extendJson['added_amount'])) {
                         $extendJson['added_amount'] = 0;
@@ -1047,7 +1048,7 @@ class MemberService
                     }
                     $balance = $balance - $extendJson['added_amount'];
                 }
-                if (in_array($item['join_pay_order_id'],['PARTNER', 'COMBINE'])){
+                if (in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE'])) {
                     $addedAmount = 0;
                     if (!isset($payObjectJson['recharge_config'])) {
                         $addedAmount = 0;
@@ -1076,7 +1077,7 @@ class MemberService
             }
 
             if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER', 'COMBINE', 'IN'])) {
-                if (!empty($item['pay_extend_json']) && !in_array($item['join_pay_order_id'],['PARTNER', 'COMBINE'])) {
+                if (!empty($item['pay_extend_json']) && !in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE'])) {
                     $extendJson = json_decode($item['pay_extend_json'], true);
                     if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
                         $data[] = [
@@ -1090,7 +1091,7 @@ class MemberService
                         $balance = $balance - $extendJson['added_amount'];
                     }
                 }
-                if (in_array($item['join_pay_order_id'],['PARTNER', 'COMBINE'])){
+                if (in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE'])) {
                     $addedAmount = 0;
                     if (!isset($payObjectJson['recharge_config'])) {
                         $addedAmount = 0;
@@ -1136,7 +1137,7 @@ class MemberService
             return json_fail('暂无数据');
         }
         $balance = $account->member_account_surplus + $account->member_account_added;
-        $points = ClientPoints::where('join_client_points_member_id', $memberId)->orderBy('client_points_addtimes','DESC')->get()->toArray();
+        $points = ClientPoints::where('join_client_points_member_id', $memberId)->orderBy('client_points_addtimes', 'DESC')->get()->toArray();
         $nowPoint = 0;
         foreach ($points as $key => &$point) {
             $point['goods_category'] = '其他';
@@ -1708,4 +1709,34 @@ class MemberService
             return 'NON';
         }
     }
+
+    /**
+     * @Desc 会员合伙人过期
+     * @Author Gorden
+     * @Date 2024/10/10 9:50
+     *
+     * @return void
+     */
+    public static function partnerExpired()
+    {
+        $members = Member::where('member_is_partner', 'Y')->get()->toArray();
+        foreach ($members as $member) {
+            $partnerJson = [];
+            if (!empty($member['member_partner_json'])) {
+                $partnerJson = json_decode($member['member_partner_json'], true);
+            }
+            if (isset($partnerJson['duedate'])) {
+                $duedateUnix = strtotime($partnerJson['duedate'] . ' 23:59:59');
+                if ($duedateUnix > time()) {
+                    continue;
+                }
+            }
+
+            Member::where('member_id', $member['member_id'])->update(['member_is_partner' => 'N', 'member_partner_json' => '[]']);
+
+            _syslog("会员合伙人过期", "取消身份", false, $partnerJson, 1001);
+
+            Log::info("会员【" . $member['member_id'] . '】会员合伙人身份已过期', $partnerJson);
+        }
+    }
 }

+ 1 - 4
app/event/order/PartnerEvent.php

@@ -73,16 +73,13 @@ class PartnerEvent
             CommissionService::commission($configParams, $params['member_id'], $params['orderId'], $params['order_amount_pay'], '推荐会员合伙人');
 
             //发放优惠券
+            $params['gettype'] = 'PARTNER';
             CouponService::autoSendCouponByGoods($params);
 
         } catch (BusinessException $e) {
-            dump($e->getMessage());
-//            Db::rollBack();
             _syslog('会员合伙人', '会员合伙人处理失败:' . $e->getMessage());
             throw new BusinessException("会员合伙人处理失败");
         } catch (\Exception $e) {
-            dump($e->getMessage());
-//            Db::rollBack();
             Log::info('PARTNER_DISPOSE_ERROR:' . $e->getMessage(), $params);
             _syslog('会员合伙人', '会员合伙人处理失败');
             throw new BusinessException("会员合伙人处理失败");

+ 1 - 0
app/event/order/ReferrerEvent.php

@@ -36,6 +36,7 @@ class ReferrerEvent
             CommissionService::commission($configParams, $params['member_id'], $params['orderId'], $params['order_amount_pay'], '推荐康养推荐官');
 
             //发放优惠券
+            $params['gettype'] = 'REFERRER';
             CouponService::autoSendCouponByGoods($params);
 
         } catch (BusinessException $e) {

+ 9 - 4
process/Task.php

@@ -6,6 +6,7 @@ use app\admin\controller\notify\RechargeController;
 use app\admin\service\client\MessageService;
 use app\admin\service\coupon\CouponService;
 use app\admin\service\goods\GoodsService;
+use app\admin\service\member\MemberService;
 use app\admin\service\order\OrderService;
 use app\admin\service\order\PayDetailService;
 use Workerman\Crontab\Crontab;
@@ -32,18 +33,22 @@ class Task
 
             // 优惠券自动过期
             CouponService::checkCouponExpired();
-            // 发放周期券
-//            CouponService::sendPeriodCoupon();
+            // 会员合伙人自动过期
+//            MemberService::partnerExpired();
         });
 
+        // 每天的0点1分执行,注意这里省略了秒位
+//        new Crontab('1 0 * * *', function () {
+//            // 会员合伙人自动过期
+//            MemberService::partnerExpired();
+//        });
+
         // 每天的2点执行,注意这里省略了秒位
         new Crontab('0 2 * * *', function () {
             // 签收后7天自动确认收货(已完成)
             OrderService::AutomaticReceipt();
             // 发货后15天自动完成
             OrderService::AutomaticComplete();
-            // 发放周期券
-//            CouponService::sendPeriodCoupon();
         });
     }
 }