| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- 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 = $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' => $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' => $customOrderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'subject' => $subject,
- ];
- $response = $laResource->cashierPay($cashParams);
- if (isset($response['code']) == false || $response['code'] != '000000') {
- util::fail('支付失败了');
- }
- $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
- if (empty($url)) {
- util::fail('支付失败');
- }
- util::success(['url' => $url]);
- } else {
- util::fail('暂不支持的付款方式');
- }
- }
- }
|