| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\recharge\classes\RechargeClass;
- use biz\recharge\classes\RechargeHbClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\SjClass;
- use bizGhs\custom\classes\CustomClass;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- class RechargeController extends BaseController
- {
- //充值记录 ssh 2021.2.21
- public function actionList()
- {
- $where = ['shopId' => $this->shopId, 'payStatus' => RechargeClass::PAY_STATUS_HAS_PAY];
- $list = RechargeClass::getRechargeList($where);
- util::success($list);
- }
- //免费续期活动 ssh 2021.2.21
- public function actionRenew()
- {
- $sj = $this->sj->attributes;
- $shopId = $sj['parentShopId'] ?? 0;
- $shopName = '';
- $rechargeNum = getenv('RECHARGE_NUM') == false ? 268 : getenv('RECHARGE_NUM');
- if (!empty($shopId)) {
- $shop = ShopClass::getShopInfo($shopId);
- if (!empty($shop)) {
- $shopName = $shop['shopName'] ?? '';
- $num = $shop['rechargeNum'] ?? 0;
- $rechargeNum += $num;
- }
- }
- $data = [
- 'renew' => getenv('RENEW_PRICE') == false ? 1980 : getenv('RENEW_PRICE'),
- 'recharge' => getenv('RECHARGE_PRICE') == false ? 5980 : getenv('RECHARGE_PRICE'),
- 'shopName' => $shopName,
- 'userNum' => $rechargeNum
- ];
- util::success($data);
- }
- //续期充值付款 ssh 2021.2.21
- public function actionRenewPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $wxPay = dict::getDict('payWay', 'wxPay');
- $price = getenv('RECHARGE_PRICE') == false ? 5980 : getenv('RECHARGE_PRICE');
- $shopAdmin = $this->shopAdmin->attributes;
- $shopAdminName = $shopAdmin['name'] ?? '';
- $data = [
- 'amount' => $price,
- 'payWay' => $wxPay,
- 'sjId' => $this->sjId,
- 'sjStyle' => SjClass::STYLE_RETAIL,
- 'shopId' => $this->shopId,
- 'modPrice' => 0,
- 'remark' => '免费续期充值',
- 'shopAdminId' => $this->shopAdminId,
- 'shopAdminName' => $shopAdminName,
- ];
- $order = RechargeClass::addOrder($data, true);
- $orderSn = $order->orderSn;
- $name = $order->orderName ?? '充值';
- $totalFee = $order->amount;
- if (isset($this->shopAdmin['super']) == false || $this->shopAdmin['super'] != 1) {
- util::fail('超级管理员才有权限操作');
- }
- //强制使用小程序的miniOpenId
- $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
- if (empty($openId)) {
- util::fail('没有找到openId');
- }
- $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
- $wxPayType = 1;
- $ghsId = Yii::$app->request->get('ghsId', 0);
- $ghs = GhsClass::getById($ghsId);
- GhsClass::valid($ghs, $this->shopId);
- $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType . '&rechargeRenew=1&ghsId=' . $ghsId;
- //订单30分钟后过期
- $now = time();
- $expireTime = $now + 1800;
- $wx = Yii::getAlias("@vendor/weixin");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.JsApiPay.php');
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($name);
- $input->SetOut_trade_no($orderSn);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetTime_start(date("YmdHis", $now));
- $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
- $input->SetTime_expire(date("YmdHis", $expireTime));
- $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("JSAPI");
- $merchantExtend = WxOpenClass::getWxInfo();
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //强制使用小程序的AppId
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
- $newParams = json_decode($jsApiParameters, true);
- util::success($newParams);
- }
- //充值送红包 ssh 2021.2.21
- public function actionBalance()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $get = Yii::$app->request->get();
- $hbId = $get['id'] ?? 0;
- $ghsId = $get['ghsId'] ?? 0;
- $ghsInfo = GhsClass::getById($ghsId, true);
- if (empty($ghsInfo)) {
- util::fail('没有找到供货商');
- }
- GhsClass::valid($ghsInfo, $this->shopId);
- $ghsShopId = $ghsInfo['shopId'] ?? 0;
- $hbInfo = RechargeHbClass::getById($hbId, true);
- if (empty($hbInfo)) {
- util::fail('无效活动');
- }
- if ($hbInfo->shopId != $ghsShopId) {
- util::fail('供货商与充值红包活动不一致');
- }
- if ($hbInfo->delStatus == 1) {
- util::fail('红包已更新,请重新发起充值');
- }
- $amount = $hbInfo->amount ?? 0;
- if ($amount <= 0) {
- util::fail('充值金额有问题');
- }
- $customId = $ghsInfo['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- $customName = $custom->name ?? '';
- $wxPay = dict::getDict('payWay', 'wxPay');
- $shopAdmin = $this->shopAdmin->attributes;
- $shopAdminName = $shopAdmin['name'] ?? '';
- $data = [
- 'amount' => $amount,
- 'payWay' => $wxPay,
- 'sjId' => $this->sjId,
- 'sjStyle' => SjClass::STYLE_RETAIL,
- 'shopId' => $this->shopId,
- 'modPrice' => 0,
- 'remark' => '',
- 'shopAdminId' => $this->shopAdminId,
- 'shopAdminName' => $shopAdminName,
- 'hbId' => $hbInfo->id ?? 0,
- 'hbAmount' => $hbInfo->hbAmount ?? 0,
- 'hbNum' => $hbInfo->num,
- 'totalHb' => $hbInfo->totalHb,
- 'valid' => $hbInfo->valid,
- 'miniExpend' => $hbInfo->miniExpend,
- 'ghsId' => $ghsId,
- 'ghsShopId' => $ghsShopId,
- 'customId' => $customId,
- 'customName' => $customName,
- ];
- $order = RechargeClass::addOrder($data, true);
- $orderSn = $order->orderSn;
- $name = $order->orderName ?? '充值';
- $totalFee = $order->amount;
- //强制使用小程序的miniOpenId
- $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
- if (empty($openId)) {
- util::fail('没有找到openId');
- }
- $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
- $wxPayType = 1;
- $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
- //订单30分钟后过期
- $now = time();
- $expireTime = $now + 1800;
- $wx = Yii::getAlias("@vendor/weixin");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.JsApiPay.php');
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($name);
- $input->SetOut_trade_no($orderSn);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetTime_start(date("YmdHis", $now));
- $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
- $input->SetTime_expire(date("YmdHis", $expireTime));
- $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("JSAPI");
- $merchantExtend = WxOpenClass::getWxInfo();
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //强制使用小程序的AppId
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
- $newParams = json_decode($jsApiParameters, true);
- util::success($newParams);
- }
- //续期成功 ssh 2021.2.21
- public function actionRenewSuccess()
- {
- $sj = $this->sj->attributes;
- $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
- util::success(['deadline' => $deadline]);
- }
- }
|