| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace ghs\controllers;
- use biz\set\classes\SetClass;
- 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 bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- 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);
- }
- //微信支付购买 ssh 2020.1.11
- public function actionWxPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $shopAdminId = $this->shopAdminId;
- $addData['shopAdminId'] = $shopAdminId;
- $shopAdmin = $this->shopAdmin->attributes;
- $adminName = $shopAdmin['name'] ?? '';
- $sjId = $shopAdmin['sjId'];
- $addData['shopAdminName'] = $adminName;
- $set = SetClass::getByCondition(['style' => SetClass::SET_STYLE_GHS], true, 'id asc');
- if (empty($set)) {
- util::fail('没有找到套餐');
- }
- $price = $set->price;
- $prePrice = $price;
- $actPrice = $price;
- $setId = $set->id;
- $addData['actPrice'] = $actPrice;
- $addData['prePrice'] = $prePrice;
- $addData['sjId'] = $this->sjId;
- $now = time();
- $expireTime = $now + 300;//订单5分钟后过期
- $addData['deadline'] = date("Y-m-d H:i:s", $expireTime);
- $order = RenewService::addOrder($addData);
- $orderId = $order['id'];
- $orderSn = $order['orderSn'];
- $couponId = 0;
- $name = $set->name . '开通及续费';
- $totalFee = $actPrice;
- $admin = $this->admin->attributes;
- //小程序使用miniOpenId
- $openId = $admin['ghsMiniOpenId'];
- $capitalType = dict::getDict('capitalType', 'xhRenew', 'id');
- //将流水类型、优惠卷传过去
- $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&setId=' . $setId . '&sjId=' . $sjId;
- $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(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("JSAPI");
- //花卉宝代为申请的微信支付
- $sjExtend = WxOpenClass::getGhsWxInfo();
- if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //小程序使用miniAppId
- if (httpUtil::isMiniProgram()) {
- $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
- }
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
- $newParams = json_decode($jsApiParameters, true);
- $newParams['orderId'] = $orderId;
- $newParams['sjId'] = $this->sjId;
- util::success($newParams);
- }
- }
|