|
|
@@ -5,8 +5,12 @@ namespace mall\controllers;
|
|
|
use bizHd\custom\classes\CustomClass;
|
|
|
use bizMall\px\classes\PxApplyClass;
|
|
|
use bizMall\px\classes\PxClassClass;
|
|
|
+use bizMall\wx\classes\WxOpenClass;
|
|
|
+use common\components\dict;
|
|
|
+use common\components\httpUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
+use bizMall\promote\services\CouponService;
|
|
|
|
|
|
/**
|
|
|
* 培训报名
|
|
|
@@ -36,7 +40,7 @@ class PxApplyController extends BaseController
|
|
|
$get['className'] = $info['name'] ?? '';
|
|
|
$get['classCover'] = $info['cover'] ?? '';
|
|
|
$get['applyTime'] = date("Y-m-d H:i:s");
|
|
|
- $get['status'] = PxApplyClass::STATUS_CONFIRM;
|
|
|
+ $get['status'] = PxApplyClass::STATUS_UN_CONFIRM;
|
|
|
|
|
|
PxApplyClass::addApply($get, $this->shop);
|
|
|
util::complete();
|
|
|
@@ -50,4 +54,74 @@ class PxApplyController extends BaseController
|
|
|
util::success($respond);
|
|
|
}
|
|
|
|
|
|
+ public function actionWxPay()
|
|
|
+ {
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
|
|
|
+ $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
|
|
|
+
|
|
|
+ $order = PxApplyClass::getByCondition(['customId'=> $this->customId,'orderSn' => $orderSn,'status'=>PxApplyClass::STATUS_UN_CONFIRM]);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('订单号无效');
|
|
|
+ }
|
|
|
+ //验证优惠券是否还有效
|
|
|
+ if (!empty($couponId)) {
|
|
|
+ CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
|
|
|
+ }
|
|
|
+ $name = $orderSn;
|
|
|
+ $totalFee = $order['actPrice'];
|
|
|
+ $wxPayType = 0;
|
|
|
+ //小程序使用miniOpenId
|
|
|
+ if (httpUtil::isMiniProgram()) {
|
|
|
+ $openId = $this->user['miniOpenId'];
|
|
|
+ $wxPayType = 1;
|
|
|
+ } else {
|
|
|
+ $openId = $this->user['openId'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $typeList = dict::getConfig('capitalType');
|
|
|
+ $capitalType = $typeList['pxApply']['id'];
|
|
|
+
|
|
|
+ $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['mallHost'] . '/notice/wx-callback/');
|
|
|
+ $input->SetTrade_type("JSAPI");
|
|
|
+
|
|
|
+ //花卉宝代为申请的微信支付
|
|
|
+ $sjExtend = $this->sjExtend;
|
|
|
+ if ($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);
|
|
|
+
|
|
|
+ $current = date("Y-m-d H:i:s");
|
|
|
+ $updateData = ['deadline' => $current, 'changePrice' => 2];
|
|
|
+ // PurchaseClass::updateById($id, $updateData);
|
|
|
+ util::success($newParams);
|
|
|
+ }
|
|
|
}
|