| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace mall\controllers;
- use bizHd\custom\classes\CustomClass;
- use bizHd\custom\classes\HdClass;
- use bizHd\merchant\classes\ShopClass;
- use bizHd\recharge\classes\RechargeClass;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- use common\components\lakala\Lakala;
- class RechargeController 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;
- $totalFee = $actPrice;
- $shopId = $this->shopId;
- if (empty($shopId)) {
- util::fail('没有找到花店');
- }
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('没有找到花店呢');
- }
- $mainId = $this->mainId;
- $hdId = $post['hdId'] ?? 0;
- $salt = $post['salt'] ?? '';
- $hd = HdClass::getById($hdId, true);
- if (empty($hd)) {
- util::fail('没有找到花店哦!');
- }
- if (empty($salt) || $hd->salt != $salt) {
- util::fail('不是你的花店哦');
- }
- $customId = $hd->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('花店客户缺失');
- }
- $customName = $custom->name;
- $hd = HdClass::getById($hdId, true);
- if (empty($hd)) {
- util::fail('花店信息缺失');
- }
- $hdName = $hd->name;
- $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
- $orderSn = orderSn::getRechargeSn();
- $rechargeData = [
- 'orderSn' => $orderSn,
- 'modPrice' => 0,
- 'payWay' => $payWay,
- 'returnCode' => '',
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'hdId' => $hdId,
- 'hdName' => $hdName,
- 'amount' => $actPrice,
- 'onlinePay' => 1,
- 'payStatus' => 0,
- 'status' => 0,
- 'customId' => $customId,
- 'customName' => $customName,
- ];
- $respond = RechargeClass::addRecharge($rechargeData);
- $rechargeId = $respond->id;
- $subject = '线上充值,单号' . $orderSn;
- if ($payWay == 0) {
- $openId = !empty($post['currentMiniOpenId']) ? $post['currentMiniOpenId'] : '';
- if (empty($openId)) {
- if (!empty($this->admin)) {
- if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
- $openId = $this->admin->miniOpenId;
- }
- }
- }
- $merchantExtend = WxOpenClass::getMallWxInfo();
- $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->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
- $wxParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'wxAppId' => $merchantExtend['miniAppId'],
- 'openId' => $openId,
- 'subject' => $subject,
- 'couponId' => 0,
- ];
- $response = $laResource->driveWxPay($wxParams);
- if ($response['code'] != 'BBS00000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push('编号666993:' . $errMsg, '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' => $rechargeId,
- 'appId' => $appId,
- 'nonceStr' => $nonceStr,
- 'paySign' => $paySign,
- 'package' => $package,
- 'signType' => $signType,
- 'timeStamp' => $timeStamp,
- 'orderSn' => $orderSn,
- ];
- util::success($new);
- } elseif ($payWay == 1) {
- util::fail('开发中');
- // $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('暂不支持的付款方式');
- }
- }
- }
|