EnrollController.php 6.0 KB

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