瀏覽代碼

1. 设置 rechargeRemark 字段与添加返回 rechargeRemark 2. 创建xhShopExt表添加 rechargeRemark 字段的数据迁移

shizhongqi 2 月之前
父節點
當前提交
c58e4d678f

+ 10 - 2
app-hd/controllers/ShopController.php

@@ -543,13 +543,14 @@ class ShopController extends BaseController
     {
         $shopId = $this->shop->id;
         $shop = ShopClass::getById($shopId, false, 'rechargeWeal');
-        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'reachVip');
+        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'reachVip,rechargeRemark');
 
         $return = [
             'rechargeRule' => $shop['rechargeWeal'] == 3 ? 2 : $shop['rechargeWeal'],
             'isVipMember' => $shopExt['reachVip'] > 0 ? 1 : 0,
             'vipAmount' => $shopExt['reachVip'],
             'hbPayable' => $shop['rechargeWeal'] == 2 ? 1 : 0,
+            'rechargeRemark' => $shopExt['rechargeRemark'],
         ];
 
         util::success($return);
@@ -570,6 +571,10 @@ class ShopController extends BaseController
         if ($rechargeWeal == 2 && $hbPayable == 0) {
             $rechargeWeal = 3;
         }
+        $rechargeRemark = trim($data['rechargeRemark']);
+        $rechargeRemark = function_exists('mb_substr')
+            ? mb_substr($rechargeRemark, 0, 200, 'UTF-8')
+            : substr($rechargeRemark, 0, 200);
 
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
@@ -577,7 +582,10 @@ class ShopController extends BaseController
         }
         $shopId = $this->shop->id;
         ShopClass::updateById($shopId, ['rechargeWeal' => $rechargeWeal]);
-        ShopExtClass::updateByCondition(['shopId' => $shopId], ['reachVip' => $reachVip]);
+        ShopExtClass::updateByCondition(['shopId' => $shopId], [
+            'reachVip' => $reachVip,
+            'rechargeRemark' => $rechargeRemark,
+        ]);
 
         util::complete('充值设置成功');
     }

+ 18 - 3
app-mall/controllers/HdController.php

@@ -5,6 +5,7 @@ namespace mall\controllers;
 use bizHd\recharge\classes\RechargeShbClass;
 use bizHd\recharge\classes\RechargeSqClass;
 use bizMall\hd\classes\HdClass;
+use bizMall\shop\classes\ShopExtClass;
 use common\components\imgUtil;
 use common\components\util;
 use bizHd\custom\classes\CustomClass;
@@ -96,10 +97,13 @@ class HdController extends BaseController
                 $custom = \bizMall\custom\classes\CustomClass::getById($customId, true);
             }
 
+            $itemType = '';
+            $itemList = [];
+            $rechargeRemark = '';
+
             // 根据 xhShop 中的 `rechargeWeal`来选择返回快捷充值选项
             if ($shop->rechargeWeal == 1) {
                 $itemType = 'money'; //送钱
-                $itemList = [];
                 $weal = RechargeSqClass::getAllByCondition(['mainId' => $shop->mainId], 'recharge asc', '*', null, true);
                 if (!empty($weal)) {
                     foreach ($weal as $key => $val) {
@@ -113,7 +117,18 @@ class HdController extends BaseController
                 $itemList = RechargeShbClass::getList('*', ['shopId' => $shop->id]);
             }
 
-            util::success(['hd' => $hd, 'custom' => $custom, 'itemType' => $itemType, 'itemList' => $itemList]);
+            if (in_array(intval($shop->rechargeWeal), [1, 2, 3])) {
+                $shopExt = ShopExtClass::getByCondition(['shopId' => $shop->id], false, false, 'rechargeRemark');
+                $rechargeRemark = $shopExt['rechargeRemark'] ?? '';
+            }
+
+            util::success([
+                'hd' => $hd,
+                'custom' => $custom,
+                'itemType' => $itemType,
+                'itemList' => $itemList,
+                'rechargeRemark' => $rechargeRemark,
+            ]);
         }
     }
 
@@ -128,4 +143,4 @@ class HdController extends BaseController
         util::success($respond);
     }
 
-}
+}

+ 26 - 0
console/migrations/m260513_000001_add_rechargeRemark_to_xhShopExt.php

@@ -0,0 +1,26 @@
+<?php
+
+use yii\db\Migration;
+
+class m260513_000001_add_rechargeRemark_to_xhShopExt extends Migration
+{
+    public function safeUp()
+    {
+        $table = '{{%xhShopExt}}';
+        if ($this->db->getTableSchema($table, true)->getColumn('rechargeRemark') !== null) {
+            return;
+        }
+
+        $this->addColumn($table, 'rechargeRemark', $this->string(200)->notNull()->defaultValue('')->comment('充值备注说明')->after('reachVip'));
+    }
+
+    public function safeDown()
+    {
+        $table = '{{%xhShopExt}}';
+        if ($this->db->getTableSchema($table, true)->getColumn('rechargeRemark') === null) {
+            return;
+        }
+
+        $this->dropColumn($table, 'rechargeRemark');
+    }
+}