Przeglądaj źródła

Merge branch 'redesign‌-260706' into dev

shish 12 godzin temu
rodzic
commit
06e1fcb272

+ 4 - 0
app-ghs/controllers/MainController.php

@@ -256,6 +256,8 @@ class MainController extends BaseController
         $txBalance = $main->txBalance ?? 0.00;
         $money = $main->money ?? 0;
         $cashAccount = $main->cashAccount ?? '';
+        $walletBalance = $main->walletBalance ?? '0.00';
+        $mainId = $main->id ?? ($this->mainId ?? 0);
         $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
 
         $shopImg = imgUtil::groupImg('');
@@ -287,6 +289,7 @@ class MainController extends BaseController
         $data = [
             'balance' => $balance,
             'txBalance' => $txBalance,
+            'walletBalance' => $walletBalance,
             'deadline' => $deadline,
             'adminName' => $adminName,
             'adminMobile' => $mobile,
@@ -300,6 +303,7 @@ class MainController extends BaseController
             'sjId' => $this->sjId,
             'adminId' => $this->adminId,
             'money' => $money,
+            'mainId' => $mainId,
             'shopInfo' => $shop,
             'lookMoney' => $lookMoney,
             'fast1' => '17189513228',

+ 124 - 0
app-ghs/controllers/MainWalletController.php

@@ -0,0 +1,124 @@
+<?php
+/**
+ * ghsApp 中央钱包(可用余额)接口
+ * 用途:我的-可用余额-变动明细、微信充值;业务与 hd 共用 xhMain.walletBalance / xhMainWallet*
+ */
+namespace ghs\controllers;
+
+use bizHd\shop\classes\MainWalletChangeClass;
+use bizHd\shop\classes\MainWalletRechargeClass;
+use bizHd\wx\classes\WxOpenClass;
+use common\components\dateUtil;
+use common\components\dict;
+use common\components\util;
+use Yii;
+
+class MainWalletController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    /**
+     * 钱包变动明细分页 + 区间汇总
+     * GET:page、searchTime、startTime、endTime、capitalType(可选)
+     */
+    public function actionChangeList()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $this->mainId;
+
+        if (isset($get['capitalType']) && $get['capitalType'] !== '') {
+            $where['capitalType'] = (int) $get['capitalType'];
+        }
+
+        $searchTime = $get['searchTime'] ?? 'today';
+        if (!empty($searchTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
+            $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+
+        $list = MainWalletChangeClass::getChangeList($where);
+        $summaryAmount = MainWalletChangeClass::getSummaryAmount($where);
+        $main = $this->main;
+        $walletBalance = $main->walletBalance ?? '0.00';
+
+        $list['summary'] = [
+            'totalRecharge' => $summaryAmount['recharge'],
+            'totalConsume' => $summaryAmount['consume'],
+            'walletBalance' => round((float) $walletBalance, 2),
+        ];
+
+        util::success($list);
+    }
+
+    /**
+     * 中央钱包微信充值:建未支付单并返回 JSAPI 支付参数
+     * POST:amount、miniOpenId(可选,缺省取当前 admin)
+     */
+    public function actionRecharge()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $post = Yii::$app->request->post();
+        $amount = isset($post['amount']) ? floor(((float) $post['amount']) * 100) / 100 : 0;
+        if ($amount <= 0) {
+            util::fail('请输入充值金额');
+        }
+
+        $admin = !empty($this->admin) ? $this->admin->attributes : [];
+        $openId = trim((string) ($post['miniOpenId'] ?? ($admin['miniOpenId'] ?? '')));
+        if ($openId === '') {
+            // 前端可据此走 uni.login 补 openId 后重试
+            util::success(['hasNoMiniOpenId' => 1]);
+        }
+
+        $recharge = MainWalletRechargeClass::createPending(
+            (int) $this->mainId,
+            (int) $this->shopId,
+            $amount
+        );
+        $orderId = (int) ($recharge->id ?? 0);
+        $orderSn = (string) ($recharge->orderSn ?? '');
+        if ($orderId <= 0 || $orderSn === '') {
+            util::fail('创建充值单失败');
+        }
+
+        $capitalType = dict::getDict('capitalType', 'mainWalletRecharge', 'id');
+        $attach = 'capitalType=' . $capitalType . '&mainId=' . (int) $this->mainId;
+
+        $now = time();
+        $expireTime = $now + 300;
+
+        $wx = Yii::getAlias('@vendor/weixin');
+        require_once $wx . '/lib/WxPay.Api.php';
+        require_once $wx . '/example/WxPay.JsApiPay.php';
+        $input = new \WxPayUnifiedOrder();
+        $input->SetBody('中央钱包充值');
+        $input->SetOut_trade_no($orderSn);
+        $input->SetTotal_fee((int) round($amount * 100));
+        $input->SetTime_start(date('YmdHis', $now));
+        $input->SetAttach($attach);
+        $input->SetTime_expire(date('YmdHis', $expireTime));
+        $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
+        $input->SetTrade_type('JSAPI');
+
+        $merchantExtend = WxOpenClass::getWxInfo();
+        $input->SetOpenid($openId);
+        $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $tools = new \JsApiPay();
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $newParams = json_decode($jsApiParameters, true) ?: [];
+        $newParams['orderId'] = $orderId;
+        $newParams['orderSn'] = $orderSn;
+        $newParams['needPay'] = 1;
+        $newParams['paid'] = 0;
+        $newParams['amount'] = $amount;
+        $newParams['hasNoMiniOpenId'] = 0;
+        util::success($newParams);
+    }
+
+}

+ 25 - 9
biz-hd/custom/observers/BuyAmountObserver.php

@@ -3,6 +3,8 @@
 namespace bizHd\custom\observers;
 
 use bizHd\custom\classes\CustomClass;
+use bizHd\custom\classes\HdClass;
+use bizHd\shop\classes\ShopClass;
 use bizHd\user\classes\UserIntegralClass;
 use yii\base\Behavior;
 use yii\db\ActiveRecord;
@@ -81,17 +83,31 @@ class BuyAmountObserver extends Behavior
 
 
         $mainId = $model->mainId;
-        if ($mainId > 0) {
-            $memberData = CustomClass::getCustomExpenseLevel($newGrowth, $mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
-            $model::updateAll([
-                'member' => (int) ($memberData['level'] ?? 0),
-                'memberName' => (string) ($memberData['name'] ?? ''),
-                'discount' => bcdiv(floatval($memberData['discount']), 10, 2)
-            ], ['id' => $model->getPrimaryKey()]);
-        }else{
-            throw new \Exception('mainId is required');
+        //历史遗留问题,如果没有mainId的,要补mainId ssh 20260818
+        if (empty($mainId)) {
+            $shopId = $model->shopId ?? 0;
+            $shopInfo = ShopClass::getById($shopId);
+            $mainId = $shopInfo['mainId'] ?? 0;
+            if (empty($mainId)) {
+                throw new \Exception('mainId is required');
+            }
+            $model->mainId = $mainId;
+            $model->save();
+            $hdId = $model->hdId ?? 0;
+            $hdInfo = HdClass::getById($hdId, true);
+            if(!empty($hdInfo)){
+                $hdInfo->mainId = $mainId;
+                $hdInfo->save();
+            }
         }
 
+        $memberData = CustomClass::getCustomExpenseLevel($newGrowth, $mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+        $model::updateAll([
+            'member' => (int) ($memberData['level'] ?? 0),
+            'memberName' => (string) ($memberData['name'] ?? ''),
+            'discount' => bcdiv(floatval($memberData['discount']), 10, 2)
+        ], ['id' => $model->getPrimaryKey()]);
+
 		if ($buyAmountDelta == 0 || $buyAmountDelta == 0.00) {
 			return;
 		}