|
|
@@ -15,6 +15,7 @@ use biz\saas\services\RegionService;
|
|
|
use biz\user\services\UserAssetService;
|
|
|
use biz\user\services\UserService;
|
|
|
use common\components\configDict;
|
|
|
+use common\components\httpUtil;
|
|
|
use common\components\stringUtil;
|
|
|
use common\services\xhPayToolService;
|
|
|
use Yii;
|
|
|
@@ -23,7 +24,7 @@ use common\components\util;
|
|
|
|
|
|
class OrderController extends BaseController
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
//商城下单操作 shish 2019.12.3
|
|
|
public function actionCreateOrder()
|
|
|
{
|
|
|
@@ -156,8 +157,8 @@ class OrderController extends BaseController
|
|
|
xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
|
|
|
util::success('支付成功');
|
|
|
}
|
|
|
-
|
|
|
- //获取商城下单要用的微信支付参数 shish 2019.21.3
|
|
|
+
|
|
|
+ //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
|
|
|
public function actionWxPay()
|
|
|
{
|
|
|
ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
@@ -171,7 +172,14 @@ class OrderController extends BaseController
|
|
|
|
|
|
$name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
|
|
|
$totalFee = $order['actPrice'];
|
|
|
- $openId = $this->user['openId'];
|
|
|
+
|
|
|
+ //小程序使用miniOpenId
|
|
|
+ if(httpUtil::isMiniProgram()){
|
|
|
+ $openId = $this->user['miniOpenId'];
|
|
|
+ }else{
|
|
|
+ $openId = $this->user['openId'];
|
|
|
+ }
|
|
|
+
|
|
|
$typeList = configDict::getConfig('capitalType');
|
|
|
$capitalType = $typeList['xhOrder']['id'];
|
|
|
//将流水类型、代金劵传过去
|
|
|
@@ -194,17 +202,21 @@ class OrderController extends BaseController
|
|
|
$input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
|
|
|
$input->SetTrade_type("JSAPI");
|
|
|
|
|
|
- //服务商 代设置微信支付,要添加的参数设置
|
|
|
- if ($this->merchantExtend['generalMerchant'] == 1) {
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = $this->merchantExtend;
|
|
|
+ if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
$input->SetSub_openid($openId);
|
|
|
- //自设置 微信支付
|
|
|
} else {
|
|
|
$input->SetOpenid($openId);
|
|
|
}
|
|
|
-
|
|
|
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->merchantExtend);
|
|
|
+ //小程序使用miniAppId
|
|
|
+ if(httpUtil::isMiniProgram()){
|
|
|
+ $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
$tools = new \JsApiPay();
|
|
|
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
$newParams = json_decode($jsApiParameters, true);
|
|
|
//已请求微信不能修改价格
|
|
|
$updateData = [];
|
|
|
@@ -257,7 +269,14 @@ class OrderController extends BaseController
|
|
|
$totalFee = $actPrice;
|
|
|
$userId = $post['userId'];
|
|
|
$user = UserService::getById($this->userId);
|
|
|
- $openId = $user['openId'];
|
|
|
+
|
|
|
+ //小程序使用miniOpenId
|
|
|
+ if(httpUtil::isMiniProgram()){
|
|
|
+ $openId = $user['miniOpenId'];
|
|
|
+ }else{
|
|
|
+ $openId = $user['openId'];
|
|
|
+ }
|
|
|
+
|
|
|
$typeList = configDict::getConfig('capitalType');
|
|
|
$capitalType = $typeList['xhOrder']['id'];
|
|
|
$attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
|
|
|
@@ -273,17 +292,22 @@ class OrderController extends BaseController
|
|
|
$input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
|
|
|
$input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
|
|
|
$input->SetTrade_type("JSAPI");
|
|
|
-
|
|
|
+
|
|
|
//花卉宝代为申请的微信支付
|
|
|
- if ($this->merchantExtend['generalMerchant'] == 1) {
|
|
|
+ $merchantExtend = $this->merchantExtend;
|
|
|
+ if ($merchantExtend['generalMerchant'] == 1) {
|
|
|
$input->SetSub_openid($openId);
|
|
|
} else {
|
|
|
$input->SetOpenid($openId);
|
|
|
}
|
|
|
-
|
|
|
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->merchantExtend);
|
|
|
+ //小程序使用miniAppId
|
|
|
+ if(httpUtil::isMiniProgram()){
|
|
|
+ $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
$tools = new \JsApiPay();
|
|
|
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
$newParams = json_decode($jsApiParameters, true);
|
|
|
$newParams['orderId'] = $orderId;
|
|
|
util::success($newParams);
|