Procházet zdrojové kódy

Merge branch 'redesign‌-260706' into dev

shizhongqi před 2 týdny
rodič
revize
8a99283bad
2 změnil soubory, kde provedl 125 přidání a 14 odebrání
  1. 33 14
      app-mall/controllers/GroupBuyController.php
  2. 92 0
      sql/20260706_redesign.sql

+ 33 - 14
app-mall/controllers/GroupBuyController.php

@@ -12,7 +12,6 @@ use bizHd\shop\classes\ShopClass;
 use bizMall\hd\classes\HdClass;
 use common\components\business;
 use common\components\dict;
-use common\components\errCode;
 use common\components\orderSn;
 use common\components\stringUtil;
 use common\components\util;
@@ -128,14 +127,27 @@ class GroupBuyController extends BaseController
         }
         $detail['activityGoods'] = $landing;
 
-        $currentShopId = Yii::$app->request->get('account', 0);
-        $hd = HdClass::getByCondition(['shopId'=>$currentShopId, 'userId'=>$this->userId], false, null, 'id, customId');
+        $currentShopId = intval(Yii::$app->request->get('account', 0));
+        $hd = HdClass::getByCondition(['shopId' => $currentShopId, 'userId' => $this->userId], false, null, 'id, customId');
         if (empty($hd)) {
-            // 创建关系???
-            // util::fail('客户暂无关联此店');
-            util::error(errCode::GROUP_BUY_HD_NOT_BOUND, '客户暂无关联此店');
+            // util::error(errCode::GROUP_BUY_HD_NOT_BOUND, '客户暂无关联此店');
+
+            // 客户与当前门店无关系时,立即建立
+            if (empty($this->user)) {
+                util::fail('请先登录');
+            }
+            $shop = ShopClass::getById($currentShopId, true);
+            if (empty($shop)) {
+                util::fail('门店不存在');
+            }
+            $respond = CustomClass::buildRelation($shop, $this->user);
+            if (empty($respond) || empty($respond['hd'])) {
+                util::fail('关联门店失败');
+            }
+            $hdId = intval($respond['hd']->id);
+        } else {
+            $hdId = intval($hd['id']);
         }
-        $hdId = $hd['id'];
         $detail['hdId'] = $hdId;
 
         util::success($detail);
@@ -206,16 +218,23 @@ class GroupBuyController extends BaseController
         $form->loadAndValidate();
         $mainId = intval($this->mainId);
         $custom = $this->custom;
-        $currentShopId = Yii::$app->request->get('account', 0);
+        $currentShopId = intval(Yii::$app->request->get('account', 0));
         if (empty($custom)) {
-            //util::fail('请先登录');
-            $hd = HdClass::getByCondition(['shopId'=>$currentShopId, 'userId'=>$this->userId], false, null, 'id, customId');
+            $hd = HdClass::getByCondition(['shopId' => $currentShopId, 'userId' => $this->userId], false, null, 'id, customId');
             if (empty($hd)) {
-                // 创建关系???
-                util::fail('客户暂无关联此店');
+                // 客户与当前门店无关系时,立即建立
+                if (empty($this->user) || empty($this->shop)) {
+                    util::fail('请先登录');
+                }
+                $respond = CustomClass::buildRelation($this->shop, $this->user);
+                if (empty($respond) || empty($respond['custom'])) {
+                    util::fail('关联门店失败');
+                }
+                $custom = $respond['custom'];
+            } else {
+                $customId = $hd['customId'];
+                $custom = CustomClass::getById($customId, true);
             }
-            $customId = $hd['customId'];
-            $custom = CustomClass::getById($customId, true);
         }
         $customId = intval($custom->id);
         $groupBuyId = intval($form->groupBuyId);

+ 92 - 0
sql/20260706_redesign.sql

@@ -288,3 +288,95 @@ ALTER TABLE `xhOrder`
 
 -- # 分销延迟结算定时任务 ouyang 2026-7-24 18:27:52
 -- 0 * * * * cd /path/to/huahuibao && php yii distribution/settle-due --limit=100
+
+
+
+-- -----------------------------------------------------------------------------
+-- 1. xhMain 增加钱包余额
+-- -----------------------------------------------------------------------------
+ALTER TABLE `xhMain`
+    ADD COLUMN `walletBalance` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '钱包余额' AFTER `balance`;
+
+
+-- -----------------------------------------------------------------------------
+-- 2. 中央钱包变动记录
+-- -----------------------------------------------------------------------------
+CREATE TABLE IF NOT EXISTS `xhMainWalletChange` (
+    `id` int(11) NOT NULL AUTO_INCREMENT,
+    `relateId` int(11) NOT NULL DEFAULT '0' COMMENT '关联订单id',
+    `ptStyle` tinyint(4) NOT NULL DEFAULT '1' COMMENT '平台类型 查看dict.php表',
+    `capitalType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '流水类型',
+    `amount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '变动金额',
+    `balance` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '当前钱包余额',
+    `io` tinyint(4) NOT NULL DEFAULT '0' COMMENT '类型 0减少 1增加',
+    `payWay` tinyint(4) NOT NULL DEFAULT '0' COMMENT '支付方式',
+    `fromType` tinyint(4) NOT NULL DEFAULT '1' COMMENT '来源 查看dict.php',
+    `event` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '事项',
+    `mainId` int(11) NOT NULL DEFAULT '0' COMMENT '中央id',
+    `remark` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
+    `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+    `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+    PRIMARY KEY (`id`) USING BTREE,
+    KEY `idx_mainId_addTime` (`mainId`, `addTime`) USING BTREE,
+    KEY `idx_relateId` (`relateId`) USING BTREE
+    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='中央钱包变动记录';
+
+-- -----------------------------------------------------------------------------
+-- 门店邀请(批发 / 花店)
+-- -----------------------------------------------------------------------------
+CREATE TABLE IF NOT EXISTS `xhMainInvite` (
+    `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
+    `mainId` int(11) NOT NULL DEFAULT '0' COMMENT '本店中央 id(xhMain.id)',
+    `inviteCode` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '本店唯一邀请码',
+    `totalCommission` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '累计佣金(本店作为邀请人)',
+    `inviteCount` int(11) NOT NULL DEFAULT '0' COMMENT '累计邀请数量(本店作为邀请人)',
+    `commissionAmount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '分佣金额(规则配置)',
+    `hdDiscountAmount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '花店优惠金额(规则配置)',
+    `inviterId` int(11) NOT NULL DEFAULT '0' COMMENT '邀请人 xhMain.id,0 表示无',
+    `inviteTime` datetime DEFAULT NULL COMMENT '本店被邀请绑定时间',
+    `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+    PRIMARY KEY (`id`) USING BTREE,
+    UNIQUE KEY `uk_inviteCode` (`inviteCode`) USING BTREE,
+    UNIQUE KEY `uk_mainId` (`mainId`) USING BTREE,
+    KEY `idx_inviterId` (`inviterId`) USING BTREE
+    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='门店邀请(批发/花店)';
+
+-- -----------------------------------------------------------------------------
+-- 门店邀请佣金分成明细
+-- -----------------------------------------------------------------------------
+CREATE TABLE IF NOT EXISTS `xhShopInviteCommission` (
+    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
+    `commissionSn` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分佣单号(如 FY202607210001)',
+    `inviterMainId` int(11) NOT NULL DEFAULT '0' COMMENT '获佣人中央 id(批发商 xhMain.id)',
+    `pfShopId` int(11) NOT NULL DEFAULT '0' COMMENT '批发店shopId',
+    `pfShopName` varchar(100) NOT NULL DEFAULT '0' COMMENT '批发店名称',
+    `lsShopId` int(11) NOT NULL DEFAULT '0' COMMENT '零售店shopId',
+    `lsShopName` varchar(100) NOT NULL DEFAULT '0' COMMENT '批发店名称',
+    `inviterShopName` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '获佣人门店名(快照)',
+    `inviteeMainId` int(11) NOT NULL DEFAULT '0' COMMENT '受邀花店中央 id(xhMain.id)',
+    `inviteeShopName` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '受邀花店名(快照)',
+    `inviteCode` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '邀请码(快照)',
+    `memberType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员类型,见 dict.php',
+    `memberTypeName` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '会员类型名(快照,如年度会员)',
+    `amount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '原价',
+    `memberPayAmount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '实付金额',
+    `commissionAmount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '分成金额(获佣人)',
+    `hdDiscountAmount` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '优惠金额',
+    `settleStatus` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '结算状态 0待结算 1已结算 2已失效',
+    `relateOrderId` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '关联会员/订单 id(业务定稿后写入)',
+    `payWay` tinyint(4) NOT NULL DEFAULT '0' COMMENT '支付方式 0微信 1支付宝 2余额',
+    `payTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '付款时间,确认时间',
+    `settleTime` datetime DEFAULT NULL COMMENT '结算时间',
+    `invalidTime` datetime DEFAULT NULL COMMENT '失效时间',
+    `invalidReason` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '失效原因',
+    `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+    PRIMARY KEY (`id`) USING BTREE,
+    UNIQUE KEY `uk_commissionSn` (`commissionSn`) USING BTREE,
+    KEY `idx_inviter_settle_occur` (`inviterMainId`, `settleStatus`, `occurTime`) USING BTREE,
+    KEY `idx_invitee_occur` (`inviteeShopId`, `occurTime`) USING BTREE,
+    KEY `idx_inviteCode` (`inviteCode`) USING BTREE,
+    KEY `idx_relateOrderId` (`relateOrderId`) USING BTREE
+    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='门店邀请记录';
+