| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace openend\controllers;
- use common\components\weixinUtil;
- use common\components\configDict;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use yii\web\Controller;
- use common\services\xhApplyOrderService;
- use common\services\xhInviteService;
- use common\services\xhMerchantService;
- use common\services\xhWxOpenService;
- class PayController extends OpenendController
- {
- public $withoutLogin = [];
- public function actionApply()
- {
- $get = Yii::$app->request->get();
- $orderId = isset($get['orderId']) ? $get['orderId'] : '';
- $apply = xhApplyOrderService::getById($orderId);
- $now = time();
- if(empty($apply)){
- util::stop('出错了');
- }
- if($apply['payStatus'] == 1){
- $this->redirect(['main/success']);
- util::end();
- }
- if($apply['userId'] != $this->userId){
- util::stop('非法访问');
- }
- $price = $apply['actPrice'];
- $merchantId = $apply['merchantId'];
- $merchant = xhMerchantService::getById($merchantId);
- return $this->renderPartial('apply',['apply'=>$apply,'price'=>$price,'merchant'=>$merchant]);
- }
- public function actionApplyGetParams()
- {
- ini_set('date.timezone','Asia/Shanghai');
- $post = Yii::$app->request->post();
- unset($post['_csrf']);
- $orderId = isset($post['orderId']) ? $post['orderId'] : '';
- $now = time();
- $expireTime = $now + 300;//订单5分钟后过期
- $payment = xhApplyOrderService::getById($orderId);
- if(empty($payment)){
- util::stop('订单不存在');
- }
- $name = '年服务费';
- $totalFee = $payment['actPrice'];
- $invitedMerchantId = $payment['invitedMerchantId'];
- $merchant = xhMerchantService::getById($invitedMerchantId);
- $openMerchant = xhWxOpenService::getMerchant();
- $openMerchantAccount = $openmerchant['id'];
- if(empty($merchant)){
- util::stop('商家信息未创建成功');
- }
- $inviteCode = $payment['inviteCode'];
- $invite = xhInviteService::getByCode($inviteCode);
- if(!empty($invite)){
- if($invite['takeStatus'] == 1){
- util::stop('您的邀请码已使用');
- }
- if($now > $invite['deadline']){
- util::stop('您的邀请码已失效');
- }
- }
- if($this->isWeixin == false){
- util::failInfo('请使用微信访问');
- }
- $userId = $this->userId;
- $user = $this->user;
- $openId = $user['openId'];
- $typeList = configDict::getConfig('capitalType');
- $capitalType = $typeList['xhApplyOrder']['id'];
- $attach = 'capitalType='.$capitalType.'&couponId=0';//将流水类型、代金劵传过去
- $weixin = Yii::getAlias("@vendor/weixin");
- require_once($weixin.'/lib/WxPay.Api.php');
- require_once($weixin.'/example/WxPay.JsApiPay.php');
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($name);
- $input->SetOut_trade_no($orderId);
- $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['openUrl'].'/notice/apply-weixin-callback/');
- $input->SetTrade_type("JSAPI");
-
-
- //服务商 代设置微信支付,要添加的参数设置
- if($this->merchantExtend['generalMerchant'] == 1){
- //$input->SetOpenid($openId);
- $input->SetSub_openid($openId);
- //自设置 微信支付
- }else{
- $input->SetOpenid($openId);
- }
-
- $wxOrder = \WxPayApi::unifiedOrder($input,6,$this->merchantExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder,$this->merchantExtend);
- $newParams = json_decode($jsApiParameters,true);
- $newParams['orderId'] = $orderId;
- $newParams['account'] = $openMerchantAccount;
- $newParams['newAccount'] = urlencode(stringUtil::authcode($merchant['id'],'ENCODE',300));
- util::successInfo('操作成功','A0001',$newParams);
- }
- public function actionApplySuccess()
- {
- return $this->renderPartial('applySuccess');
- }
- }
|