| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace hd\controllers;
- use biz\sj\services\MerchantExtendService;
- use biz\sj\services\MerchantService;
- use bizHd\saas\services\RenewService;
- use bizHd\saas\services\SetMealService;
- use bizHd\user\services\UserService;
- use common\components\configDict;
- use common\components\httpUtil;
- use common\components\util;
- use Yii;
- class RenewController extends BaseController
- {
- public function actionList()
- {
- $where = [];
- $list = RenewService::getRenewList($where);
- util::success($list);
- }
- //微信支付购买 shish 2020.1.11
- public function actionWxPay()
- {
- util::fail('即将开通...');
- ini_set('date.timezone', 'Asia/Shanghai');
- $merchantId = Yii::$app->request->get('merchantId', 0);
- $merchant = MerchantService::getMerchantById($merchantId);
- if (empty($merchant)) {
- util::fail('没有找到商家');
- }
- $setId = isset($merchant['setId']) ? $merchant['setId'] : 0;
- $set = SetMealService::getById($setId);
- if (empty($set)) {
- util::fail('没有找到套餐');
- }
- $userId = $this->adminId;
- $addData['userId'] = $userId;
- $price = $set['price'];
- $prePrice = $price;
- $actPrice = $price;
- $addData['actPrice'] = $actPrice;
- $addData['prePrice'] = $prePrice;
- $addData['merchantId'] = $merchantId;
- $now = time();
- $expireTime = $now + 300;//订单5分钟后过期
- $addData['deadline'] = $expireTime;
- $order = RenewService::addOrder($addData);
- $orderId = $order['id'];
- $orderSn = $order['orderSn'];
- $couponId = 0;
- $name = $set['name'] . '开通续费';
- $totalFee = $actPrice;
- $userId = $addData['userId'];
- $user = UserService::getById($userId);
- //小程序使用miniOpenId
- if (httpUtil::isMiniProgram()) {
- $openId = $user['miniOpenId'];
- } else {
- $openId = $user['openId'];
- }
- $typeList = configDict::getConfig('capitalType');
- $capitalType = $typeList['xhRenew']['id'];
- $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
- $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));//设置订单有效期5分钟
- $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
- $input->SetTrade_type("JSAPI");
- //花卉宝代为申请的微信支付
- $merchantExtend = MerchantExtendService::getByMerchantId($this->sjId);
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //小程序使用miniAppId
- if (httpUtil::isMiniProgram()) {
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
- }
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
- $newParams = json_decode($jsApiParameters, true);
- $newParams['orderId'] = $orderId;
- $newParams['merchantId'] = $merchantId;
- util::success($newParams);
- }
- }
|