MainController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace openend\controllers;
  3. use common\services\xhSetMealService;
  4. use common\services\xhInviteService;
  5. use common\services\xhMerchantAccountService;
  6. use common\services\xhMerchantService;
  7. use common\components\weixinUtil;
  8. use common\components\configDict;
  9. use common\components\stringUtil;
  10. use common\components\util;
  11. use common\services\xhAdminService;
  12. use common\services\xhCommonService;
  13. use common\services\xhApplyOrderService;
  14. use Yii;
  15. use yii\web\Controller;
  16. class MainController extends OpenendController
  17. {
  18. public $withoutLogin = ['index','product','service','about-us','login','check-merchant-name'];
  19. public function actionIndex()
  20. {
  21. return $this->render('index');
  22. }
  23. public function actionProduct()
  24. {
  25. return $this->render('product');
  26. }
  27. public function actionService()
  28. {
  29. return $this->render('service');
  30. }
  31. public function actionAboutUs()
  32. {
  33. return $this->render('aboutUs');
  34. }
  35. public function actionApply()
  36. {
  37. return $this->renderPartial('apply');
  38. }
  39. public function actionApplySubmit()
  40. {
  41. $post = Yii::$app->request->post();
  42. unset($post['_csrf']);
  43. $createTime = date("Y-m-d H:i:s");
  44. $account = xhMerchantAccountService::getByBusinessLicense($post['businessLicense']);
  45. if(empty($account)){
  46. $accountData = ['userId'=>$this->userId,'businessLicense'=>$post['businessLicense'],'idCard'=>$post['idCard'],
  47. 'idCardBack'=>$post['idCardBack'],'bankCardInfo'=>$post['bankCardInfo'],'bankCardNo'=>$post['bankCardNo'],
  48. 'mobile'=>$post['mobile'],'email'=>$post['email'],'createTime'=>$createTime,'bankCard'=>$post['bankCard'],
  49. 'applyName'=>$post['applyName'],'telephone'=>$post['telephone'],
  50. ];
  51. $account = xhMerchantAccountService::add($accountData);//保存商事主体信息
  52. }
  53. util::successInfo('请稍候');
  54. }
  55. public function actionApplySuccess()
  56. {
  57. return $this->renderPartial('applySuccess');
  58. }
  59. public function actionLogin()
  60. {
  61. echo '请使用微信访问';
  62. }
  63. /**
  64. * 下载微信里的图片到服务器
  65. */
  66. public function actionDownloadWxImg()
  67. {
  68. $get = Yii::$app->request->get();
  69. $mediaId = isset($get['mediaId']) ? $get['mediaId'] : '';
  70. $imgList = weixinUtil::downloadmediaIdImg($this->merchant, $mediaId);
  71. if(!empty($imgList)){
  72. util::successInfo('操作成功','A0001',$imgList);
  73. }
  74. util::failInfo();
  75. }
  76. public function actionCheckMerchantName()
  77. {
  78. $get = Yii::$app->request->get();
  79. $merchantName = isset($get['merchantName']) ? $get['merchantName'] : '';
  80. $m = xhMerchantService::getByMerchantName($merchantName);
  81. if(!empty($m)){
  82. util::failInfo('公众号名称已经使用');
  83. }
  84. util::successInfo();
  85. }
  86. public function actionCheckInviteCode()
  87. {
  88. $get = Yii::$app->request->get();
  89. $code = isset($get['code']) ? $get['code'] : '';
  90. $invite = xhInviteService::getByCode($code);
  91. if(empty($invite)){
  92. util::failInfo('邀请码错误');
  93. }
  94. $now = time();
  95. if($now > $invite['deadline']){
  96. util::failInfo('邀请码已经失效');
  97. }
  98. if(!empty($invite['takeStatus'])){
  99. util::failInfo('邀请码已经使用');
  100. }
  101. util::successInfo('操作成功','A0001',$invite);
  102. }
  103. public function actionGenerateCode()
  104. {
  105. $get = Yii::$app->request->get();
  106. $mobile = isset($get['mobile']) ? $get['mobile'] : '';
  107. if(preg_match("/^1[0-9]\d{9}$/",$mobile) == false){
  108. util::failInfo('手机号填写有误');
  109. }
  110. $session = Yii::$app->session;
  111. $now = time();
  112. if(isset($session['authCode']) == false || ($now - $session['authCodeTime']) > 120){
  113. $num = stringUtil::getRandNum(5);
  114. $session['authCode'] = $num;
  115. $session['authCodeTime'] = time();
  116. $msg = "您的验证码:".$num;
  117. xhCommonService::sendMobileMsg($mobile, $msg);
  118. util::successInfo();
  119. }
  120. util::failInfo('请稍等会…');
  121. }
  122. /**
  123. * 检测验证码
  124. */
  125. public function actionCheckCode()
  126. {
  127. $get = Yii::$app->request->get();
  128. $authCode = isset($get['authCode']) ? $get['authCode'] : '';
  129. $session = Yii::$app->session;
  130. if(isset($session['authCode']) && $authCode == $session['authCode']){
  131. util::successInfo('');
  132. }
  133. util::failInfo('验证号不正确');
  134. }
  135. public function actionCheckEmail()
  136. {
  137. $get = Yii::$app->request->get();
  138. $email = isset($get['email']) ? $get['email'] : '';
  139. $status = xhApplyOrderService::emailIsUse($email);
  140. if($status){
  141. util::failInfo('邮箱已经使用');
  142. }
  143. util::successInfo();
  144. }
  145. }