request->get(); $mobile = isset($get['mobile']) ? $get['mobile'] : ''; $status = xhUserService::mobileNotUsed($mobile, $this->merchantId); if($status){ util::successInfo(''); } util::failInfo(''); } public function actionRegisterInfo() { $post = Yii::$app->request->post(); $session = Yii::$app->session; if(isset($post['code']) == false || empty($post['code'])){ util::failInfo('没有验证码'); } if(isset($session['activeMobileAuthCode']) == false){ util::failInfo('未生成过验证码'); } if($post['code'] != $session['activeMobileAuthCode']){ util::failInfo('验证码不正确'); } if(isset($post['mobile']) == false || stringUtil::isMobieNumber($post['mobile'] == false) ){ util::failInfo('没有手机号或不符合要求'); } unset($post['_csrf']); unset($post['code']); xhUserService::updateById($this->userId, $post); util::successInfo(); } public function actionApply() { $post = Yii::$app->request->post(); $activeId = isset($post['activeId']) ? $post['activeId'] : 0; $classId = isset($post['classId']) ? $post['classId'] : 0; $couponId = isset($post['couponId']) ? $post['couponId'] : 0; $now = time(); $date = date("Y-m-d H:i:s",$now); $active = xhActiveService::getById($activeId); if($active['merchantId'] != $this->merchantId){ util::failInfo('非法访问!'); } $class = xhActiveTicketClassService::getById($classId); if($class['merchantId'] != $this->merchantId){ util::failInfo('非法访问。'); } if(empty($this->user['mobile'])){ util::failInfo('没有填写手机号'); } $payWay = configDict::getConfig('payWay','cashPay'); $payStyle = configDict::getConfig('payStyle','cashPay'); $order = xhActiveOrderService::getByCondition(['activeId' => $activeId,'userId' => $this->userId,'classId' => $classId]); if(empty($order)){ $addData = [ 'id' => 'AC'.stringUtil::buildOrderNo(0), 'activeId' => $activeId, 'classId' => $classId, 'userId' => $this->userId, 'merchantId' => $this->merchantId, 'bookName' => $this->user['userName'], 'bookMobile' => $this->user['mobile'], 'payStatus' => 0, 'passStatus' => $active['needCheck'] == 0 ? 1 : 0,//passStatus - 审批通过状态:-1、不通过,0、未审批(默认),1、审批通过 'createTime' => $date, 'addTime' => $now, 'prePrice' => $class['price'], 'actPrice' => $class['price'], 'payWay' => $payWay, 'payStyle' => $payStyle, ]; $order = xhActiveOrderService::add($addData); } $totalFee = $order['actPrice']; if($order['payStatus'] == 1){ util::failInfo('亲,您已经报过名了哦'); } if($now > $active['endTime']){ util::failInfo('亲,活动已经结束了哦'); } if($now > $active['deadline']){ util::failInfo('亲,报名已经结束了哦'); } if(!empty($active['allowNum']) && $active['applyNum'] >= $active['allowNum']){ util::failInfo('人数已经满了哦'); } $orderId = $order['id']; if($class['price'] <= 0){//免费活动直接报名不需付款 $applyNum = $active['applyNum']; $addApplyNum = $applyNum + 1; xhActiveService::updateById($activeId, ['applyNum'=>$addApplyNum]); xhActiveOrderService::updateById($orderId, ['payStatus' => 1]); util::successInfo('请稍候…','A0001',['orderId'=>$orderId,'fee'=>'free']); } ini_set('date.timezone','Asia/Shanghai'); $weixin = Yii::getAlias("@vendor/weixin"); require_once($weixin.'/lib/WxPay.Api.php'); require_once($weixin.'/example/WxPay.JsApiPay.php'); $name = $active['title']." 活动报名"; $openId = $this->user['openId']; $expireTime = $active['deadline'];//订单有效期至报名结束时间 $typeList = configDict::getConfig('capitalType'); $capitalType = $typeList['xhActiveOrder']['id']; $attach = "couponId=".$couponId."&capitalType=".$capitalType;//将流水类型、代金劵传过去 $input = new \WxPayUnifiedOrder(); $input->SetBody($name); $input->SetOut_trade_no($orderId); $input->SetTotal_fee($totalFee*100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", $expireTime)); $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传 $input->SetNotify_url(Yii::$app->params['frontUrl'].'/notice/weixin-callback/'); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $wxOrder = \WxPayApi::unifiedOrder($input,6,$this->merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder,$this->merchantExtend); $newParams = json_decode($jsApiParameters,true); $newParams['orderId'] = $orderId; $newParams['fee'] = 'fee';//收费 util::successInfo('操作成功','A0001',$newParams); } public function actionResult() { $get = Yii::$app->request->get(); $status = isset($get['status']) ? $get['status'] : ''; $orderId = isset($get['orderId']) ? $get['orderId'] : 0; return $this->render('result',['status' => $status,'orderId'=>$orderId]); } public function actionGenerateAuthCode() { $get = Yii::$app->request->get(); $mobile = isset($get['mobile']) ? $get['mobile'] : 0; if(stringUtil::isMobieNumber($mobile) == false){ util::failInfo('手机号填写有误'); } $status = xhUserService::mobileNotUsed($mobile, $this->merchantId); if($status == false){ util::failInfo('手机号已经被使用'); } $now = time(); $session = Yii::$app->session; if(isset($session['activeMobileAuthCode']) == false || ($now - $session['activeMobileAuthCodeTime']) > 120){ $num = stringUtil::getRandNum(5); $session['activeMobileAuthCode'] = $num; $session['activeMobileAuthCodeTime'] = time(); $msg = "您的验证码:".$num; xhCommonService::sendMobileMsg($mobile, $msg,$this->merchant); util::successInfo($msg); } } /** *检测验证码 */ public function actionCheckAuthCode() { $get = Yii::$app->request->get(); $session = Yii::$app->session; if(isset($get['code']) && isset($session['activeMobileAuthCode'])){ if($get['code'] == $session['activeMobileAuthCode']){ util::successInfo(''); } util::failInfo('验证码不正确'); } } public function actionOrder() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $order = xhActiveOrderService::getById($id); if($order['userId'] != $this->userId){ util::stop('非法访问'); } $activeId = $order['activeId']; $active = xhActiveService::getById($activeId); return $this->renderPartial('order',['active'=>$active,'order'=>$order,'id'=>$id]); } }