| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?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 = [];
- //取消充值订单 ssh 20250721
- public function actionCancel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $recharge = \bizMall\recharge\classes\RechargeClass::getLockById($id);
- if (empty($recharge)) {
- util::fail('没有找到充值记录');
- }
- if ($recharge->userId != $this->userId) {
- util::fail('不是你的充值单');
- }
- if ($recharge->shopId != $this->shopId) {
- util::fail('不是你的充值记录');
- }
- if ($recharge->status == 1) {
- util::fail('已充值成功,不能取消');
- }
- if ($recharge->status == 2) {
- util::fail('已经取消过了');
- }
- $shop = $this->shop;
- \bizMall\recharge\classes\RechargeClass::cancelMyRecharge($recharge, $shop);
- util::complete('取消成功');
- }
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $hdId = $get['hdId'] ?? 0;
- $status = $get['status'] ?? -1;
- $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
- $where = ['mainId' => $this->mainId];
- if (!empty($hd)) {
- if ($hd->shopId != $this->shopId) {
- util::fail('不是你的门店');
- }
- $customId = $hd->customId ?? 0;
- $where['customId'] = $customId;
- }
- if ($status > -1) {
- $where['status'] = $status;
- }
- $list = \bizMall\recharge\classes\RechargeClass::getRechargeList($where);
- util::success($list);
- }
- //用微信支付进行充值 ssh 20250709
- public function actionWxPayRecharge()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? '';
- //避免重复提交
- util::checkRepeatCommit($id, 8);
- $recharge = RechargeClass::getById($id, true);
- if (empty($recharge)) {
- util::fail('没有充值单');
- }
- $userId = $this->userId;
- $shopId = $this->shopId;
- if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
- util::fail('不是你的充值单');
- }
- $shop = $this->shop;
- $user = $this->user;
- if (empty($shop)) {
- util::fail('没有门店信息');
- }
- $shop = $this->shop;
- $orderSn = $recharge->orderSn;
- $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
- if (empty($openId)) {
- $openId = !empty($user['miniOpenId']) ? $user['miniOpenId'] : '';
- }
- if (empty($openId)) {
- util::fail('没有找到openId');
- }
- //已经发起过支付,需要更换单号
- if ($recharge->payRequest == 1 || $recharge->payRequest == 2) {
- $closeOrderSn = $orderSn;
- //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
- $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);
- $closeParams = ['orderSn' => $closeOrderSn];
- if ($recharge->payRequest == 1) {
- //聚合支付关单
- $response = $laResource->close($closeParams);
- if (!isset($response['code']) || $response['code'] != 'BBS00000') {
- $msg = $response['msg'] ?? '';
- noticeUtil::push('重点注意,充值换单号没有成功,单号:' . $closeOrderSn . ',关单没有成功,' . $msg, '15280215347');
- util::fail('出错了哦,请重新操作哈');
- }
- } else {
- //收银台关单
- $response = $laResource->cashClose($closeParams);
- if (!isset($response['code']) || $response['code'] != '000000') {
- $msg = $response['msg'] ?? '';
- noticeUtil::push('重点注意,充值换单,收银台的单号:' . $closeOrderSn . ',关单没有成功,' . $msg, '15280215347');
- util::fail('出错了哦,请重新操作呢');
- }
- }
- //生成新的订单,避免重复
- $orderSn = orderSn::getRechargeSn();
- $recharge->orderSn = $orderSn;
- $recharge->save();
- }
- $name = '充值销账,单号' . $orderSn;
- $totalFee = $recharge->amount ?? 0;
- $orderId = $recharge->id;
- $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
- $sjExtend = 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' => $sjExtend['miniAppId'],
- 'openId' => $openId,
- 'subject' => $name,
- 'couponId' => 0,
- ];
- $response = $laResource->driveWxPay($wxParams);
- //0没有唤起过第三方支付,1唤起过聚合支付,2唤起过收银台。主要针对拉卡拉支付。
- $recharge->payRequest = 1;
- $recharge->save();
- if (!isset($response['code']) || $response['code'] != 'BBS00000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push($errMsg, '15280215347');
- util::fail('充值失败');
- }
- $respData = $response['resp_data'] ?? [];
- $accRespFields = $respData['acc_resp_fields'] ?? [];
- if (empty($accRespFields)) {
- util::fail('充值失败,没有找到支付数据');
- }
- $appId = $accRespFields['app_id'] ?? '';
- $nonceStr = $accRespFields['nonce_str'] ?? '';
- $paySign = $accRespFields['pay_sign'] ?? '';
- $package = $accRespFields['package'] ?? '';
- $signType = $accRespFields['sign_type'] ?? '';
- $timeStamp = $accRespFields['time_stamp'] ?? '';
- $new = [
- 'id' => $orderId,
- 'appId' => $appId,
- 'nonceStr' => $nonceStr,
- 'paySign' => $paySign,
- 'package' => $package,
- 'signType' => $signType,
- 'timeStamp' => $timeStamp,
- 'orderSn' => $orderSn,
- ];
- util::success($new);
- }
- //获取充值订单的详情 ssh 20250709
- public function actionGetDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $recharge = RechargeClass::getById($id, true);
- if (empty($recharge)) {
- util::fail('没有找到充值订单');
- }
- $userId = $this->userId;
- $shopId = $this->shopId;
- if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
- util::fail('不是你的单');
- }
- util::success($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;
- $userId = $this->userId;
- $salt = $post['salt'] ?? '';
- $hd = $this->hd;
- if (empty($hd)) {
- util::fail('没有找到花店哦!');
- }
- if (empty($salt)) {
- } else {
- if ($hd->salt != $salt) {
- util::fail('不是你的花店哦');
- }
- }
- $hdId = $hd->id;
- $customId = $hd->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('花店客户缺失');
- }
- $customName = $custom->name;
- $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,
- 'userId' => $userId,
- ];
- $respond = RechargeClass::addRecharge($rechargeData);
- $rechargeId = $respond->id;
- $respond->payRequest = 1;
- $respond->save();
- $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('开发中');
- } else {
- util::fail('暂不支持的付款方式');
- }
- }
- }
|