Kaynağa Gözat

用户充值

shish 2 yıl önce
ebeveyn
işleme
3abece6156
1 değiştirilmiş dosya ile 109 ekleme ve 7 silme
  1. 109 7
      app-hd/controllers/CustomRechargeController.php

+ 109 - 7
app-hd/controllers/CustomRechargeController.php

@@ -2,41 +2,144 @@
 
 namespace hd\controllers;
 
+use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\classes\CustomRechargeClass;
+use bizGhs\ghs\classes\GhsRechargeClass;
+use bizHd\ghs\classes\GhsClass;
+use bizHd\shop\classes\ShopClass;
 use common\components\lakala\Lakala;
 use common\components\dict;
+use common\components\orderSn;
 use common\components\util;
 use Yii;
 
 class CustomRechargeController extends BaseController
 {
 
+    public $guestAccess = ['recharge'];
 
+    //充值 ssh 20240507
     public function actionRecharge()
     {
         ini_set('date.timezone', 'Asia/Shanghai');
         $post = Yii::$app->request->post();
         $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
+        $actPrice = $post['actPrice'] ?? 0;
+        $ghsId = $post['ghsId'] ?? 0;
+        $salt = $post['salt'] ?? '';
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('没有找到供货商那');
+        }
+        if ($ghs->salt != $salt) {
+            util::fail('不是你的供货商那');
+        }
+        $customId = $ghs->customId ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('供货商信息不完整那');
+        }
+
         $capitalType = dict::getDict('capitalType', 'customRechargeToGhs', 'id');
+
+        $customOrderSn = orderSn::getGhsCustomRechargeSn();
+
+        $customShopId = $custom->shopId ?? 0;
+        $customMainId = $custom->mainId ?? 0;
+        $customBalance = $custom->balance ?? 0;
+        $customName = $custom->name ?? '';
+
+        $ghsShopId = $ghs->shopId ?? 0;
+        $ghsMainId = $ghs->mainId ?? 0;
+        $ghsBalance = $ghs->balance ?? 0;
+        $ghsName = $ghs->name ?? '';
+        $ghsShop = ShopClass::getById($ghsShopId, true);
+        if (empty($ghsShop)) {
+            util::fail('供货商信息不完全哦');
+        }
+
+        $customStaffId = 0;
+        $customStaffName = '';
+        if (isset($this->shopAdmin) && !empty($this->shopAdmin)) {
+            $staff = $this->shopAdmin;
+            $customStaffId = $staff->id ?? 0;
+            $customStaffName = $staff->name ?? '';
+        }
+
+        $cData = [
+            'orderSn' => $customOrderSn,
+            'onlinePay' => 2,
+            'payWay' => $payWay,
+            'shopId' => $ghsShopId,
+            'mainId' => $ghsMainId,
+            'amount' => $actPrice,
+            'balance' => $customBalance,
+            'side' => 0,
+            'staffId' => 0,
+            'staffName' => '',
+            'payStatus' => 0,
+            'status' => 0,
+            'remark' => '',
+            'ghsId' => $ghsId,
+            'ghsShopId' => $ghsShopId,
+            'ghsName' => $ghsName,
+            'customId' => $customId,
+            'customShopId' => $customShopId,
+            'customName' => $customName,
+            'remark' => '',
+        ];
+        $cRecharge = CustomRechargeClass::add($cData, true);
+        $cRechargeId = $cRecharge->id ?? 0;
+
+        $ghsOrderSn = orderSn::getGhsRechargeSn();
+        $gData = [
+            'orderSn' => $ghsOrderSn,
+            'onlinePay' => 2,
+            'payWay' => $payWay,
+            'shopId' => $customShopId,
+            'mainId' => $customMainId,
+            'amount' => $actPrice,
+            'balance' => $ghsBalance,
+            'side' => 0,
+            'staffId' => $customStaffId,
+            'staffName' => $customStaffName,
+            'payStatus' => 0,
+            'status' => 0,
+            'remark' => '',
+            'ghsId' => $ghsId,
+            'ghsShopId' => $ghsShopId,
+            'ghsName' => $ghsName,
+            'customId' => $customId,
+            'customShopId' => $customShopId,
+            'customName' => $customName,
+            'remark' => '',
+        ];
+        $gRecharge = GhsRechargeClass::add($gData, true);
+        $gRechargeId = $gRecharge->id ?? 0;
+        $cRecharge->ghsRechargeId = $gRechargeId;
+        $cRecharge->save();
+        $gRecharge->customRechargeId = $cRechargeId;
+        $gRecharge->save();
+
         if ($payWay == 0) {
 
         } elseif ($payWay == 1) {
-            $totalFee = $order['realPrice'];
-            $subject = '购买花材';
-            $shop = $this->shop;
+            $totalFee = $actPrice;
+            $subject = '充值销账 单号' . $customOrderSn;
             $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
             $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
             $params = [
                 'appid' => 'OP00002119',
                 'serial_no' => '018b08cfddbd',
-                'merchant_no' => $shop->lklSjNo,
-                'term_no' => $shop->lklB2BTermNo,
+                'merchant_no' => $ghsShop->lklSjNo,
+                'term_no' => $ghsShop->lklB2BTermNo,
                 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
                 'lklCertificatePath' => $lklCertificatePath,
             ];
             $laResource = new Lakala($params);
             $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
             $cashParams = [
-                'orderSn' => $orderSn,
+                'orderSn' => $customOrderSn,
                 'amount' => $totalFee,
                 'capitalType' => $capitalType,
                 'notifyUrl' => $notifyUrl,
@@ -56,5 +159,4 @@ class CustomRechargeController extends BaseController
         }
     }
 
-
 }