ouyang 1 день назад
Родитель
Сommit
812bfff800

+ 35 - 11
app-hd/controllers/ApplyController.php

@@ -77,13 +77,18 @@ class ApplyController extends BaseController
 
     /**
      * 花店注册页:会员费、邀请减免、应付(未登录可访问)
+     * 已登录时传入 mainId,用于拦截自己的邀请码减免
      */
     public function actionRegisterFeePreview()
     {
         $get = Yii::$app->request->get();
         $inviteCode = trim($get['inviteCode'] ?? '');
         $allowInviteBenefit = $this->canUseRegisterInviteBenefit();
-        $data = MainInviteClass::resolveRegisterFeePreview($inviteCode, $allowInviteBenefit);
+        $data = MainInviteClass::resolveRegisterFeePreview(
+            $inviteCode,
+            $allowInviteBenefit,
+            (int) $this->mainId
+        );
         util::success($this->appendInviteBenefitFlags($data));
     }
 
@@ -146,9 +151,17 @@ class ApplyController extends BaseController
         }
         $post = Yii::$app->request->post();
         $inviteCode = trim((string) ($post['inviteCode'] ?? ''));
-        $fee = MainInviteClass::resolveRegisterFeeSubmit($inviteCode, true);
-        if ($inviteCode !== '' && !empty($fee['inviteNotFound'])) {
-            util::fail('邀请人不存在');
+        $fee = MainInviteClass::resolveRegisterFeeSubmit($inviteCode, true, (int) $this->mainId);
+        // 自邀 / 无效 / 不存在:清空邀请码落库,无减免无佣金,仍允许支付
+        if (
+            $inviteCode !== '' && (
+                !empty($fee['inviteNotFound']) ||
+                !empty($fee['inviteSelf']) ||
+                !empty($fee['inviteInvalid'])
+            )
+        ) {
+            $inviteCode = '';
+            $fee = MainInviteClass::resolveRegisterFeeSubmit('', true, (int) $this->mainId);
         }
         $hdDiscountAmount = round((float) ($fee['hdDiscountAmount'] ?? 0), 2);
         $inviteCommissionAmount = round((float) ($fee['inviteCommissionAmount'] ?? 0), 2);
@@ -157,7 +170,7 @@ class ApplyController extends BaseController
             'hdDiscountAmount' => $hdDiscountAmount,
             'inviteCommissionAmount' => $inviteCommissionAmount,
         ]);
-        $preview = MainInviteClass::resolveRegisterFeePreview($inviteCode, true);
+        $preview = MainInviteClass::resolveRegisterFeePreview($inviteCode, true, (int) $this->mainId);
         util::success($this->appendInviteBenefitFlags(array_merge($preview, [
             'applyId' => $applyId,
             'inviteCode' => $inviteCode,
@@ -321,11 +334,18 @@ class ApplyController extends BaseController
                 util::fail('申请失败');
             }
 
-            // 邀请码快照写入 xhApply(选填)
+            // 邀请码快照写入 xhApply(选填);自邀/无效/不存在则清空后落库,仍可注册支付
             $inviteCode = trim((string) ($post['inviteCode'] ?? ''));
-            $fee = MainInviteClass::resolveRegisterFeeSubmit($inviteCode);
-            if ($inviteCode !== '' && !empty($fee['inviteNotFound'])) {
-                util::fail('邀请人不存在');
+            $fee = MainInviteClass::resolveRegisterFeeSubmit($inviteCode, true, (int) $this->mainId);
+            if (
+                $inviteCode !== '' && (
+                    !empty($fee['inviteNotFound']) ||
+                    !empty($fee['inviteSelf']) ||
+                    !empty($fee['inviteInvalid'])
+                )
+            ) {
+                $inviteCode = '';
+                $fee = MainInviteClass::resolveRegisterFeeSubmit('', true, (int) $this->mainId);
             }
             ApplyClass::updateById($id, [
                 'inviteCode' => $inviteCode,
@@ -343,7 +363,11 @@ class ApplyController extends BaseController
             $onlyCg = $newShop->onlyCg ?? 1;
 
             ApplyClass::updateById($id, ['shopId' => $newShopId]);
-            $inviterMainId = MainInviteClass::resolveInviterMainIdByInviteCode($inviteCode);
+            $inviterMainId = (int) ($fee['inviterMainId'] ?? 0);
+            // 新店 mainId 与邀请人相同(极端自邀)时不挂邀请关系
+            if ($inviterMainId > 0 && $inviterMainId === (int) $newMainId) {
+                $inviterMainId = 0;
+            }
             MainInviteClass::createInviteeRecord($newMainId, $inviterMainId);
 
             $shareLogo = imgUtil::groupImg('buy_logo.jpg');
@@ -455,7 +479,7 @@ class ApplyController extends BaseController
             }
         }
         if (empty($apply) && $adminId > 0 && !empty($this->admin)) {
-            $mobile = $this->admin->mobile ?? '';
+            $mobile = $this->shop->mobile ?? '';
             if ($mobile !== '') {
                 $row = ApplyClass::getByCondition(['mobile' => $mobile], false);
                 if (!empty($row)) {

+ 8 - 1
app-hd/controllers/MainInviteController.php

@@ -17,11 +17,13 @@ class MainInviteController extends BaseController
 
     /**
      * 我的分佣首页:xhMainInvite + 待结算 + 最近佣金
+     * inviteCodeEligible:当前门店 hasRenew=1 且 deadline 未过期时才展示「我的邀请码」
      */
     public function actionIndex()
     {
         $mainId = (int) $this->mainId;
         $invite = MainInviteClass::ensureByMainId($mainId);
+        $inviteCodeEligible = MainInviteClass::isShopInviteEligible($this->shop) ? 1 : 0;
         $inviteData = [
             'inviteCode' => '',
             'inviteCodeMask' => '',
@@ -33,9 +35,13 @@ class MainInviteController extends BaseController
         ];
         if (!empty($invite)) {
             $code = $invite['inviteCode'] ?? '';
+            // 未续费或已到期:不回传邀请码,避免前端误分享
+            if (!$inviteCodeEligible) {
+                $code = '';
+            }
             $inviteData = [
                 'inviteCode' => $code,
-                'inviteCodeMask' => MainInviteCommissionClass::maskInviteCode($code),
+                'inviteCodeMask' => $code !== '' ? MainInviteCommissionClass::maskInviteCode($code) : '',
                 'totalCommission' => round((float) ($invite['totalCommission'] ?? 0), 2),
                 'ableCommission' => round((float) ($invite['ableCommission'] ?? 0), 2),
                 'commissionAmount' => round((float) ($invite['commissionAmount'] ?? 0), 2),
@@ -52,6 +58,7 @@ class MainInviteController extends BaseController
 
         util::success([
             'invite' => $inviteData,
+            'inviteCodeEligible' => $inviteCodeEligible,
             'recentList' => $recentList,
         ]);
     }

+ 80 - 4
biz-hd/shop/classes/MainInviteClass.php

@@ -71,10 +71,65 @@ class MainInviteClass extends BaseClass
         return self::getByCondition(['inviteCode' => $code], false);
     }
 
+    /**
+     * 邀请权益是否生效:xhShop.hasRenew=1 且 deadline 大于当前时间
+     * 按 mainId 查该账号下任意未删除门店,满足其一即可
+     *
+     * @param int $mainId xhMain.id
+     * @return bool
+     */
+    public static function isInviteShopActiveByMainId($mainId)
+    {
+        $mainId = (int) $mainId;
+        if ($mainId <= 0) {
+            return false;
+        }
+        $list = BizShopClass::getAllList('id,hasRenew,deadline', [
+            'mainId' => $mainId,
+            'delStatus' => 0,
+        ], 'id ASC');
+        if (empty($list) || !is_array($list)) {
+            return false;
+        }
+        $now = time();
+        foreach ($list as $shop) {
+            $hasRenew = (int) ($shop['hasRenew'] ?? 0);
+            $deadline = trim((string) ($shop['deadline'] ?? ''));
+            if ($hasRenew === 1 && $deadline !== '' && strtotime($deadline) > $now) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 单店判断:已续费且未到期(shopInviteHub 当前门店)
+     *
+     * @param array|object|null $shop xhShop
+     * @return bool
+     */
+    public static function isShopInviteEligible($shop)
+    {
+        if (empty($shop)) {
+            return false;
+        }
+        if (is_object($shop)) {
+            $hasRenew = (int) ($shop->hasRenew ?? 0);
+            $deadline = trim((string) ($shop->deadline ?? ''));
+        } else {
+            $hasRenew = (int) ($shop['hasRenew'] ?? 0);
+            $deadline = trim((string) ($shop['deadline'] ?? ''));
+        }
+        return $hasRenew === 1 && $deadline !== '' && strtotime($deadline) > time();
+    }
+
     /**
      * 花店注册页:会员价与邀请减免(dict + 可选邀请码)
+     * @param string $inviteCode 邀请码
+     * @param bool $allowInviteBenefit 是否仍可享首次付费邀请权益
+     * @param int $currentMainId 当前登录 xhMain.id;与邀请人相同则视为自邀(不带入减免)
      */
-    public static function resolveRegisterFeePreview($inviteCode = '', $allowInviteBenefit = true)
+    public static function resolveRegisterFeePreview($inviteCode = '', $allowInviteBenefit = true, $currentMainId = 0)
     {
         $config = dict::getDict('hdRegisterConfig');
         $price = round((float)($config['price'] ?? 0), 2);
@@ -86,6 +141,10 @@ class MainInviteClass extends BaseClass
             'inviteCode' => trim((string)$inviteCode),
             'inviteValid' => 0,
             'inviteNotFound' => 0,
+            /** 是否为自己的邀请码(前端不带入,可继续支付) */
+            'inviteSelf' => 0,
+            /** 邀请人未续费或已到期:界面提示无效,无减免,可继续支付 */
+            'inviteInvalid' => 0,
             'hdDiscountAmount' => 0,
             'showInviteDiscount' => 0,
             'payAmount' => $price,
@@ -106,6 +165,19 @@ class MainInviteClass extends BaseClass
             return $out;
         }
 
+        $inviterMainId = (int) ($invite['mainId'] ?? 0);
+        // 业务规则:自己的邀请码不带入减免
+        if ((int) $currentMainId > 0 && $inviterMainId > 0 && $inviterMainId === (int) $currentMainId) {
+            $out['inviteSelf'] = 1;
+            return $out;
+        }
+
+        // 业务规则:邀请人门店须 hasRenew=1 且 deadline 未过期,否则邀请码无效
+        if (!self::isInviteShopActiveByMainId($inviterMainId)) {
+            $out['inviteInvalid'] = 1;
+            return $out;
+        }
+
         $out['inviteValid'] = 1;
         $comm = (float)($invite['commissionAmount'] ?? 0);
         $rowDiscount = (float)($invite['hdDiscountAmount'] ?? 0);
@@ -128,10 +200,13 @@ class MainInviteClass extends BaseClass
 
     /**
      * 注册提交:费用 + 邀请人 mainId + 佣金快照
+     * @param string $inviteCode 邀请码
+     * @param bool $allowInviteBenefit 是否仍可享首次付费邀请权益
+     * @param int $currentMainId 当前登录 mainId,用于拦截自邀减免
      */
-    public static function resolveRegisterFeeSubmit($inviteCode = '', $allowInviteBenefit = true)
+    public static function resolveRegisterFeeSubmit($inviteCode = '', $allowInviteBenefit = true, $currentMainId = 0)
     {
-        $preview = self::resolveRegisterFeePreview($inviteCode, $allowInviteBenefit);
+        $preview = self::resolveRegisterFeePreview($inviteCode, $allowInviteBenefit, $currentMainId);
         $config = dict::getDict('hdRegisterConfig');
         $configComm = round((float) ($config['commissionAmount'] ?? 0), 2);
 
@@ -144,7 +219,8 @@ class MainInviteClass extends BaseClass
             return $preview;
         }
 
-        if (!empty($preview['inviteNotFound'])) {
+        // 自邀 / 无效 / 不存在:无佣金无减免,仍允许支付
+        if (!empty($preview['inviteNotFound']) || !empty($preview['inviteSelf']) || !empty($preview['inviteInvalid'])) {
             return $preview;
         }
         if (empty($preview['inviteValid'])) {

+ 3 - 0
sql/20260706_redesign.sql

@@ -438,3 +438,6 @@ ALTER TABLE xhPsMethod
     ADD column calcType       TINYINT NOT NULL DEFAULT 0 COMMENT '算运费方式 0 用跑腿 1用自定义' after `changeRate`,
     ADD COLUMN hsFreeKm decimal(8, 2) DEFAULT '0.00' COMMENT '花束包邮公里数',
     ADD COLUMN hsPerKmPrice   decimal(8, 2) DEFAULT '0.00' COMMENT '花束超出包邮每公里价格';
+
+ALTER TABLE `xhShop`
+    MODIFY COLUMN `hasRenew` tinyint(4) NOT NULL DEFAULT 0 COMMENT '已续费 0没有 1有' AFTER `beforeDeadline`;