| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace mall\controllers;
- use bizHd\custom\classes\CustomClass;
- use bizMall\px\classes\PxApplyClass;
- use bizMall\px\classes\PxClassClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- use bizHd\wx\classes\WxOpenClass;
- /**
- * 培训报名
- */
- class PxApplyController extends BaseController
- {
- //报名申请 ssh 2021.3.17
- public function actionAdd()
- {
- $get = Yii::$app->request->get();
- $classId = $get['classId'] ?? 0;
- $info = PxClassClass::getClassInfo($classId);
- PxClassClass::valid($info, $this->sjId);
- $customId = $this->customId;
- if (!empty($customId)) {
- $custom = CustomClass::getCustomInfo($customId);
- CustomClass::valid($custom, $this->sjId);
- }
- $get['sjId'] = $this->sjId;
- $get['prePrice'] = $info['tuition'];
- $get['actPrice'] = $info['tuition'];
- $get['shopId'] = $this->shopId;
- $get['shopAdminId'] = 0;
- $get['customId'] = $this->customId;
- $get['className'] = $info['name'] ?? '';
- $get['classCover'] = $info['cover'] ?? '';
- $get['applyTime'] = date("Y-m-d H:i:s");
- $get['status'] = PxApplyClass::STATUS_UN_CONFIRM;
- $respond = PxApplyClass::addApply($get, $this->shop);
- util::success($respond);
- }
- //新学员 学员管理 ssh 2021.3.17
- public function actionList()
- {
- $where = ['shopId' => $this->shopId];
- $respond = PxApplyClass::getApplyList($where);
- util::success($respond);
- }
- public function actionWxPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $post = Yii::$app->request->post();
- $orderSn = $post['orderSn'] ?? 0;
- $couponId = 0;
- $order = PxApplyClass::getByCondition(['customId' => $this->customId, 'orderSn' => $orderSn, 'status' => PxApplyClass::STATUS_UN_CONFIRM]);
- if (empty($order)) {
- util::fail('订单号无效');
- }
- $name = $orderSn;
- $totalFee = $order['actPrice'];
- //强制使用小程序miniOpenId,不再考虑web
- $openId = $this->user['miniOpenId'];
- $wxPayType = 1;
- $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");
- $input->SetOpenid($openId);
- $sjExtend = WxOpenClass::getMallWxInfo();
- $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
- $newParams = json_decode($jsApiParameters, true);
- util::success($newParams);
- }
- }
|