|
|
@@ -6,6 +6,9 @@ use biz\ghs\classes\GhsClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
use bizHd\purchase\services\PurchaseService;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
+use bizHd\wx\classes\WxOpenClass;
|
|
|
+use common\components\dict;
|
|
|
+use common\components\httpUtil;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
|
|
|
@@ -117,4 +120,70 @@ class PurchaseController extends BaseController
|
|
|
util::success($respond);
|
|
|
}
|
|
|
|
|
|
+ //微信支付 shish 2021.4.11
|
|
|
+ public function actionWxPay()
|
|
|
+ {
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $couponId = $post['couponId'] ?? 0;
|
|
|
+ $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
|
|
|
+ $order = PurchaseClass::getByCondition(['orderSn' => $orderSn]);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('订单号无效');
|
|
|
+ }
|
|
|
+ $id = $order['id'];
|
|
|
+
|
|
|
+ $name = $orderSn;
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+
|
|
|
+ //强制使用小程序的miniOpenId
|
|
|
+ $openId = $this->admin['miniOpenId'];
|
|
|
+
|
|
|
+ $typeList = dict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['xhPurchase']['id'];
|
|
|
+ //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
|
|
|
+ $wxPayType = 0;
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ $wxPayType = 1;
|
|
|
+ }
|
|
|
+ $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
|
|
|
+ //订单30分钟后过期
|
|
|
+ $now = time();
|
|
|
+ $expireTime = $now + 1800;
|
|
|
+
|
|
|
+ $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));
|
|
|
+ $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $merchantExtend = WxOpenClass::getWxInfo();
|
|
|
+
|
|
|
+ if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
|
|
|
+ $input->SetSub_openid($openId);
|
|
|
+ } else {
|
|
|
+ $input->SetOpenid($openId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //强制使用小程序的miniAppId
|
|
|
+ $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
|
|
|
+
|
|
|
+ $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
|
|
|
+ $tools = new \JsApiPay();
|
|
|
+ $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
|
|
|
+ $newParams = json_decode($jsApiParameters, true);
|
|
|
+ $current = date("Y-m-d H:i:s");
|
|
|
+ $updateData = ['deadline' => $current, 'changePrice' => 2];
|
|
|
+ PurchaseClass::updateById($id, $updateData);
|
|
|
+ util::success($newParams);
|
|
|
+ }
|
|
|
+
|
|
|
}
|