EnrollController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /*
  3. Created by PhpStorm.
  4. User: xiaofeng
  5. Date: 2018/6/10
  6. Time: 下午3:15
  7. */
  8. namespace frontend\controllers;
  9. use frontend\base\CommonController;
  10. use Yii;
  11. use frontend\base\Help;
  12. use common\api\EnrollServer;
  13. use common\enums\EmailEnum;
  14. use linslin\yii2\curl\Curl;
  15. class EnrollController extends CommonController
  16. {
  17. public $enableCsrfValidation = false;
  18. /*
  19. * name 姓名
  20. * source_model 来源模块
  21. * mobile 手机号
  22. * intention_house 意向楼盘
  23. * hid 楼盘ID 不存在:0
  24. * equipment 设备 2=>pc 1=>移动
  25. * city 区域
  26. *
  27. * */
  28. public function actionSignup()
  29. {
  30. $en = new EnrollServer();
  31. $cacheResult = $en->Restrict(Yii::$app->request->post());
  32. if (!$cacheResult['is_test'] && $cacheResult['sign']) {
  33. return Help::JsonCode(Help::ERROR, '您今天的报名次数已超过限制');
  34. }
  35. $form = new \common\forms\VisitorRegistrationForm();
  36. $form->load(Yii::$app->request->post(), '');
  37. if (!$form->validate()) return Help::JsonCode(Help::ERROR, '提交失败', $form->errors);
  38. /*
  39. * 2020.7.27 lyy 报名号码限制
  40. * */
  41. $astrict_is = $en->ChacPhone(Yii::$app->request->post('mobile'));
  42. if ($astrict_is['code']) return Help::JsonCode(Help::ERROR, $astrict_is['msg']);//号码限制
  43. $model = new \common\models\Enroll();
  44. $model->scenario = 'pcadd';
  45. $model->load(array_merge($form->attributes, Yii::$app->request->post()), '');
  46. if ($model->save()) {
  47. if ($cacheResult['is_test']) {
  48. //如果是测试号码,则不走以下发送邮箱的步骤
  49. return Help::JsonCode(Help::SUCCESS, '测试号码提交成功');
  50. }
  51. $array = array_merge($form->attributes, Yii::$app->request->post());
  52. (new Curl())->setPostParams([
  53. 'name' => empty($array['housename']) ? '' : $array['housename'],
  54. 'city' => empty($array['city_name']) ? '' : $array['city_name'],
  55. 'tel' => empty($array['mobile']) ? '' : $array['mobile'],
  56. 'time' => $_SERVER['REQUEST_TIME'],
  57. ])->post('http://abc.pinfangw.com/index.php?m=Admin&c=ReceiveSign');
  58. $Email = $form->attributes;
  59. $Email['id'] = $model->attributes['id'];
  60. (new \common\service\common\MailerService())->send($form->send_email, $Email, EmailEnum::SITEFORM);
  61. return Help::JsonCode(Help::SUCCESS, '提交成功');
  62. }
  63. // $en = new EnrollServer();
  64. // $cacheResult = $en->Restrict();
  65. // if($cacheResult === false) return Help::JsonCode(Help::ERROR,'您今天的报名次数已超过限制');
  66. // // aid: 0
  67. // //source: 2
  68. // //equipment: 2
  69. // //intention_city: 区域
  70. // //intention_housetype: 户型
  71. // //budget: 预算
  72. // //mobile: 13816450442
  73. // //根据报名判断是否有相应的区域邮箱
  74. // $input = Yii::$app->request->post();
  75. // $en->mobile = $input['mobile'];
  76. // if(!empty($input['intention_house']))
  77. // {
  78. // $en->housename = $input['intention_house'];
  79. // }
  80. // if(!empty($input['intention_housetype']))
  81. // {
  82. // $en->houseType = $input['intention_housetype'];
  83. // }
  84. // if(!empty($input['budget']))
  85. // {
  86. // $en->budget = $input['budget'];//预算
  87. // }
  88. // if(!empty($input['hid'])){
  89. // $houst = new \common\models\House();
  90. // $houseModel = $houst->FindById($input['hid']); //楼盘相关信息
  91. // $en->housename = $houseModel['name'];
  92. // $city = $houseModel['city'];
  93. // // $email = $cityEmail->FindByEmail($houseModel['city']);
  94. // // $en->city = $email['city_name'];
  95. // }else if(!empty($input['city'])){
  96. // $city = $input['city'];
  97. // // $email = $cityEmail->FindByEmail($input['city']);
  98. // // $en->city = $email['city_name'];
  99. // }
  100. // if(!empty($input['intention_city']))
  101. // {
  102. // $city_rows = \common\models\CategoryCity::findOne(['city_name'=> $input['intention_city']]);
  103. // if($city_rows)
  104. // {
  105. // $city = $city_rows['id'];
  106. // }
  107. // $en->city = $input['intention_city'];
  108. // }
  109. // //根据区域发送指定邮箱
  110. // if(!empty($city))
  111. // {
  112. // $cityEmail = new \common\models\Email();
  113. // $email = $cityEmail->FindByEmail($city);
  114. // $catCity = ( new \common\models\CategoryCity())->FindById($city);
  115. // $en->city = $catCity['city_name'];
  116. // }
  117. // if(!empty($email))
  118. // {
  119. // $e = $email['email'];
  120. // $en->city = $email['city_name'];
  121. // }
  122. // else
  123. // {
  124. // $e = Yii::$app->params['default_email'];
  125. // }
  126. // // ( new \common\api\EmailServer())->SendOut($e,Yii::t('app','enter_email'),$msgemail);
  127. // $model = new \common\models\Enroll();
  128. // $model->scenario = 'pcadd';
  129. // $auth = $model->Authenticator($input);
  130. // if(is_object($auth))
  131. // {
  132. // $auth->ip = Yii::$app->request->userIP;
  133. // $auth->send_email = $e;
  134. // if($auth->save(false)){
  135. // $auth->attributes['id'];
  136. // $en->username = $auth->name;
  137. // //发送邮件
  138. // $event = new \common\event\Event();
  139. // $arr = [];
  140. // $arr['email'] = $e;
  141. // $arr['title'] = Yii::t('app','enter_email');
  142. // $arr['content'] = $en->TemplateOne();
  143. // $arr['id'] = $auth->attributes['id'];
  144. // $event->SendEmail($arr);
  145. // return Help::JsonCode(Help::SUCCESS,'提交成功');
  146. // }
  147. // }
  148. // return Help::JsonCode(Help::ERROR,'提交失败',$auth);
  149. }
  150. }