ActiveController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace mobile\controllers;
  3. use Yii;
  4. use common\components\util;
  5. use common\components\stringUtil;
  6. use common\components\configDict;
  7. use common\services\xhActiveService;
  8. use common\services\xhActiveOrderService;
  9. use common\services\xhCommonService;
  10. use common\services\xhActiveTicketClassService;
  11. use common\services\xhUserService;
  12. class ActiveController extends MobileendController
  13. {
  14. public $layout = 'centerMain';
  15. public $withoutLogin = ['index'];
  16. public function actionMobileNotUse()
  17. {
  18. $get = Yii::$app->request->get();
  19. $mobile = isset($get['mobile']) ? $get['mobile'] : '';
  20. $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
  21. if($status){
  22. util::successInfo('');
  23. }
  24. util::failInfo('');
  25. }
  26. public function actionRegisterInfo()
  27. {
  28. $post = Yii::$app->request->post();
  29. $session = Yii::$app->session;
  30. if(isset($post['code']) == false || empty($post['code'])){
  31. util::failInfo('没有验证码');
  32. }
  33. if(isset($session['activeMobileAuthCode']) == false){
  34. util::failInfo('未生成过验证码');
  35. }
  36. if($post['code'] != $session['activeMobileAuthCode']){
  37. util::failInfo('验证码不正确');
  38. }
  39. if(isset($post['mobile']) == false || stringUtil::isMobieNumber($post['mobile'] == false) ){
  40. util::failInfo('没有手机号或不符合要求');
  41. }
  42. unset($post['_csrf']);
  43. unset($post['code']);
  44. xhUserService::updateById($this->userId, $post);
  45. util::successInfo();
  46. }
  47. public function actionApply()
  48. {
  49. $post = Yii::$app->request->post();
  50. $activeId = isset($post['activeId']) ? $post['activeId'] : 0;
  51. $classId = isset($post['classId']) ? $post['classId'] : 0;
  52. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  53. $now = time();
  54. $date = date("Y-m-d H:i:s",$now);
  55. $active = xhActiveService::getById($activeId);
  56. if($active['merchantId'] != $this->merchantId){
  57. util::failInfo('非法访问!');
  58. }
  59. $class = xhActiveTicketClassService::getById($classId);
  60. if($class['merchantId'] != $this->merchantId){
  61. util::failInfo('非法访问。');
  62. }
  63. if(empty($this->user['mobile'])){
  64. util::failInfo('没有填写手机号');
  65. }
  66. $payWay = configDict::getConfig('payWay','cashPay');
  67. $payStyle = configDict::getConfig('payStyle','cashPay');
  68. $order = xhActiveOrderService::getByCondition(['activeId' => $activeId,'userId' => $this->userId,'classId' => $classId]);
  69. if(empty($order)){
  70. $addData = [
  71. 'id' => 'AC'.stringUtil::buildOrderNo(0),
  72. 'activeId' => $activeId,
  73. 'classId' => $classId,
  74. 'userId' => $this->userId,
  75. 'merchantId' => $this->merchantId,
  76. 'bookName' => $this->user['userName'],
  77. 'bookMobile' => $this->user['mobile'],
  78. 'payStatus' => 0,
  79. 'passStatus' => $active['needCheck'] == 0 ? 1 : 0,//passStatus - 审批通过状态:-1、不通过,0、未审批(默认),1、审批通过
  80. 'createTime' => $date,
  81. 'addTime' => $now,
  82. 'prePrice' => $class['price'],
  83. 'actPrice' => $class['price'],
  84. 'payWay' => $payWay,
  85. 'payStyle' => $payStyle,
  86. ];
  87. $order = xhActiveOrderService::add($addData);
  88. }
  89. $totalFee = $order['actPrice'];
  90. if($order['payStatus'] == 1){
  91. util::failInfo('亲,您已经报过名了哦');
  92. }
  93. if($now > $active['endTime']){
  94. util::failInfo('亲,活动已经结束了哦');
  95. }
  96. if($now > $active['deadline']){
  97. util::failInfo('亲,报名已经结束了哦');
  98. }
  99. if(!empty($active['allowNum']) && $active['applyNum'] >= $active['allowNum']){
  100. util::failInfo('人数已经满了哦');
  101. }
  102. $orderId = $order['id'];
  103. if($class['price'] <= 0){//免费活动直接报名不需付款
  104. $applyNum = $active['applyNum'];
  105. $addApplyNum = $applyNum + 1;
  106. xhActiveService::updateById($activeId, ['applyNum'=>$addApplyNum]);
  107. xhActiveOrderService::updateById($orderId, ['payStatus' => 1]);
  108. util::successInfo('请稍候…','A0001',['orderId'=>$orderId,'fee'=>'free']);
  109. }
  110. ini_set('date.timezone','Asia/Shanghai');
  111. $weixin = Yii::getAlias("@vendor/weixin");
  112. require_once($weixin.'/lib/WxPay.Api.php');
  113. require_once($weixin.'/example/WxPay.JsApiPay.php');
  114. $name = $active['title']." 活动报名";
  115. $openId = $this->user['openId'];
  116. $expireTime = $active['deadline'];//订单有效期至报名结束时间
  117. $typeList = configDict::getConfig('capitalType');
  118. $capitalType = $typeList['xhActiveOrder']['id'];
  119. $attach = "couponId=".$couponId."&capitalType=".$capitalType;//将流水类型、代金劵传过去
  120. $input = new \WxPayUnifiedOrder();
  121. $input->SetBody($name);
  122. $input->SetOut_trade_no($orderId);
  123. $input->SetTotal_fee($totalFee*100);
  124. $input->SetTime_start(date("YmdHis"));
  125. $input->SetTime_expire(date("YmdHis", $expireTime));
  126. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  127. $input->SetNotify_url(Yii::$app->params['frontUrl'].'/notice/weixin-callback/');
  128. $input->SetTrade_type("JSAPI");
  129. $input->SetOpenid($openId);
  130. $wxOrder = \WxPayApi::unifiedOrder($input,6,$this->merchantExtend);
  131. $tools = new \JsApiPay();
  132. $jsApiParameters = $tools->GetJsApiParameters($wxOrder,$this->merchantExtend);
  133. $newParams = json_decode($jsApiParameters,true);
  134. $newParams['orderId'] = $orderId;
  135. $newParams['fee'] = 'fee';//收费
  136. util::successInfo('操作成功','A0001',$newParams);
  137. }
  138. public function actionResult()
  139. {
  140. $get = Yii::$app->request->get();
  141. $status = isset($get['status']) ? $get['status'] : '';
  142. $orderId = isset($get['orderId']) ? $get['orderId'] : 0;
  143. return $this->render('result',['status' => $status,'orderId'=>$orderId]);
  144. }
  145. public function actionGenerateAuthCode()
  146. {
  147. $get = Yii::$app->request->get();
  148. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  149. if(stringUtil::isMobieNumber($mobile) == false){
  150. util::failInfo('手机号填写有误');
  151. }
  152. $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
  153. if($status == false){
  154. util::failInfo('手机号已经被使用');
  155. }
  156. $now = time();
  157. $session = Yii::$app->session;
  158. if(isset($session['activeMobileAuthCode']) == false || ($now - $session['activeMobileAuthCodeTime']) > 120){
  159. $num = stringUtil::getRandNum(5);
  160. $session['activeMobileAuthCode'] = $num;
  161. $session['activeMobileAuthCodeTime'] = time();
  162. $msg = "您的验证码:".$num;
  163. xhCommonService::sendMobileMsg($mobile, $msg,$this->merchant);
  164. util::successInfo($msg);
  165. }
  166. }
  167. /**
  168. *检测验证码
  169. */
  170. public function actionCheckAuthCode()
  171. {
  172. $get = Yii::$app->request->get();
  173. $session = Yii::$app->session;
  174. if(isset($get['code']) && isset($session['activeMobileAuthCode'])){
  175. if($get['code'] == $session['activeMobileAuthCode']){
  176. util::successInfo('');
  177. }
  178. util::failInfo('验证码不正确');
  179. }
  180. }
  181. public function actionOrder()
  182. {
  183. $get = Yii::$app->request->get();
  184. $id = isset($get['id']) ? $get['id'] : 0;
  185. $order = xhActiveOrderService::getById($id);
  186. if($order['userId'] != $this->userId){
  187. util::stop('非法访问');
  188. }
  189. $activeId = $order['activeId'];
  190. $active = xhActiveService::getById($activeId);
  191. return $this->renderPartial('order',['active'=>$active,'order'=>$order,'id'=>$id]);
  192. }
  193. }