EnrollController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace wechat\controllers;
  3. use wechat\base\CommonController;
  4. use Yii;
  5. use wechat\base\Help;
  6. use common\api\EnrollServer;
  7. class EnrollController extends CommonController
  8. {
  9. public $enableCsrfValidation = false;
  10. /*
  11. * name 姓名
  12. * source_model 来源模块
  13. * mobile 手机号
  14. * intention_house 意向楼盘
  15. * hid 楼盘ID 不存在:0
  16. * equipment 设备 2=>pc 1=>移动
  17. * city 区域
  18. *
  19. * */
  20. public function actionSignup()
  21. {
  22. $en = new EnrollServer();
  23. $cacheResult = $en->Restrict();
  24. if($cacheResult === false) {
  25. return Help::JsonCode(Help::ERROR,'您今天的报名次数已超过限制');
  26. }
  27. //根据报名判断是否有相应的区域邮箱
  28. $cityEmail = new \common\models\Email();
  29. $input = Yii::$app->request->post();
  30. $en->mobile = $input['mobile'];
  31. if(!empty($input['intention_house']))
  32. {
  33. $en->housename = $input['intention_house'];
  34. }
  35. if(!empty($input['budget']))
  36. {
  37. $en->budget = $input['budget'];
  38. }
  39. if(!empty($input['intention_housetype']))
  40. {
  41. $en->houseType = $input['intention_housetype'];
  42. }
  43. if(!empty($input['intention_city']))
  44. {
  45. $city_rows = \common\models\CategoryCity::findOne(['city_name'=> $input['intention_city']]);
  46. if($city_rows)
  47. {
  48. $city = $city_rows['id'];
  49. }
  50. $en->city = $input['intention_city'];
  51. }
  52. if(!empty($input['hid'])){
  53. $houst = new \common\models\House();
  54. $houseModel = $houst->FindById($input['hid']); //楼盘相关信息
  55. $en->housename = $houseModel['name'];
  56. $city = $houseModel['city'];
  57. // $email = $cityEmail->FindByEmail($houseModel['city']);
  58. // $en->city = $email['city_name'];
  59. }else if(!empty($input['city'])){
  60. $city = $input['city'];
  61. // $email = $cityEmail->FindByEmail($input['city']);
  62. // $en->city = $email['city_name'];
  63. }
  64. //根据区域发送指定邮箱
  65. if(!empty($city))
  66. {
  67. $cityEmail = new \common\models\Email();
  68. $email = $cityEmail->FindByEmail($city);
  69. $catCity = ( new \common\models\CategoryCity())->FindById($city);
  70. $en->city = $catCity['city_name'];
  71. }
  72. if(!empty($email))
  73. {
  74. $e = $email['email'];
  75. $en->city = $email['city_name'];
  76. }
  77. else
  78. {
  79. $e = Yii::$app->params['default_email'];
  80. }
  81. $model = new \common\models\Enroll();
  82. $model->scenario = 'madd';
  83. $auth = $model->Authenticator($input);
  84. if(is_object($auth))
  85. {
  86. $auth->ip = Yii::$app->request->userIP;
  87. $auth->send_email = $e;
  88. if($auth->save(false))
  89. {
  90. $auth->attributes['id'];
  91. $en->username = $auth->name;
  92. //发送邮件
  93. $event = new \common\event\Event();
  94. $arr = [];
  95. $arr['email'] = $e;
  96. $arr['title'] = '客户报名信息';
  97. $arr['content'] = $en->TemplateOne();
  98. $arr['id'] = $auth->attributes['id'];
  99. $event->SendEmail($arr);
  100. return Help::JsonCode(Help::SUCCESS,'提交成功');
  101. }
  102. }
  103. return Help::JsonCode(Help::ERROR,'提交失败',$auth);
  104. }
  105. }