|
|
@@ -2,15 +2,69 @@
|
|
|
|
|
|
namespace open\controllers;
|
|
|
|
|
|
+use biz\saas\services\RenewService;
|
|
|
+use biz\saas\services\SetMealService;
|
|
|
+use common\components\configDict;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
|
|
|
class RenewController extends BaseController
|
|
|
{
|
|
|
-
|
|
|
- public function action()
|
|
|
+
|
|
|
+ //微信支付 shish 2019.12.23
|
|
|
+ public function actionWxPay()
|
|
|
{
|
|
|
-
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ $setId = Yii::$app->request->get('setId', 1);
|
|
|
+ $set = SetMealService::getById($setId);
|
|
|
+ if (empty($set)) {
|
|
|
+ util::fail('没有找到套餐');
|
|
|
+ }
|
|
|
+ $post['userId'] = $this->userId;
|
|
|
+ $price = $set['price'];
|
|
|
+ $post['prePrice'] = $price;
|
|
|
+ $post['actPrice'] = $price;
|
|
|
+ $post['payWay'] = 0;
|
|
|
+ $now = time();
|
|
|
+ $expireTime = $now + 300;//订单5分钟后过期
|
|
|
+ $post['createTime'] = date("Y-m-d H:i:s", $now);
|
|
|
+ $post['deadline'] = $expireTime;
|
|
|
+ $renew = RenewService::add($post);
|
|
|
+ $orderId = $renew['orderSn'];
|
|
|
+ $name = $set['name'] . '购买续费';
|
|
|
+ $totalFee = $price;
|
|
|
+ $user = $this->user;
|
|
|
+ $openId = $user['openId'];
|
|
|
+ $typeList = configDict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhOrder']['id'];
|
|
|
+ $attach = 'capitalType=' . $capitalType . '&couponId=0';//将流水类型、优惠卷传过去
|
|
|
+ $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($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($this->frontUrl . '/notice/weixin-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = $this->merchantExtend;
|
|
|
+ if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
+ $input->SetSub_openid($openId);
|
|
|
+ } else {
|
|
|
+ $input->SetOpenid($openId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
+ $tools = new \JsApiPay();
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
+ $newParams = json_decode($jsApiParameters, true);
|
|
|
+ $newParams['orderId'] = $orderId;
|
|
|
+ util::success($newParams);
|
|
|
}
|
|
|
|
|
|
}
|