| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- namespace hd\controllers;
- use bizGhs\custom\classes\AccountMoneyClass;
- 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\noticeUtil;
- use common\components\orderSn;
- use common\components\util;
- use bizHd\wx\classes\WxOpenClass;
- 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 = $post['payWay'] ?? 0;
- $actPrice = $post['actPrice'] ?? 0;
- if ($actPrice <= 0) {
- util::fail('请输入数值');
- }
- $actPrice = floor($actPrice * 100) / 100;//只保留2位小数
- $totalFee = $actPrice;
- $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('供货商信息不完整那');
- }
- // 花店自助充值建单前:挂账并入净 balance
- AccountMoneyClass::ensureCustomMoneyReady($custom, true);
- AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
- $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();
- $subject = '充值销账 单号' . $customOrderSn;
- if ($payWay == 0) {
- $openId = '';
- if (isset($post['currentMiniOpenId']) && !empty($post['currentMiniOpenId'])) {
- $openId = $post['currentMiniOpenId'];
- }
- if (empty($openId)) {
- if (isset($this->admin) && !empty($this->admin)) {
- if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
- $openId = $this->admin->miniOpenId;
- }
- }
- }
- if (empty($openId)) {
- $currentShop = ShopClass::getById($customShopId, true);
- $currentShopName = $currentShop->merchantName . ' ' . $currentShop->shopName;
- $currentMobile = $currentShop->mobile ?? '';
- noticeUtil::push("花店向供货商充值时,发现没有openId。{$currentShopName} {$currentMobile}", '15280215347');
- util::fail('用户信息不完整');
- }
- $merchantExtend = WxOpenClass::getWxInfo();
- $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->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
- $wxParams = [
- 'orderSn' => $customOrderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'wxAppId' => $merchantExtend['miniAppId'],
- 'openId' => $openId,
- 'subject' => $subject,
- 'couponId' => 0,
- ];
- $response = $laResource->driveWxPay($wxParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push('编号19881507:' . $errMsg . ' | ' . $ghsName . ' | ' . $customName . ' | ' . $actPrice, '15280215347');
- util::fail('支付失败');
- }
- $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
- $appId = $newParams['app_id'] ?? '';
- $nonceStr = $newParams['nonce_str'] ?? '';
- $paySign = $newParams['pay_sign'] ?? '';
- $package = $newParams['package'] ?? '';
- $signType = $newParams['sign_type'] ?? '';
- $timeStamp = $newParams['time_stamp'] ?? '';
- $new = [
- 'id' => $gRechargeId,
- 'appId' => $appId,
- 'nonceStr' => $nonceStr,
- 'paySign' => $paySign,
- 'package' => $package,
- 'signType' => $signType,
- 'timeStamp' => $timeStamp,
- 'orderSn' => $customOrderSn,
- ];
- util::success($new);
- } elseif ($payWay == 1) {
- $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('暂不支持的付款方式');
- }
- }
- }
|