EnrollServer.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/6/11
  6. * Time: 上午9:28
  7. */
  8. namespace common\api;
  9. use Yii;
  10. use linslin\yii2\curl\Curl;
  11. use backend\base\Help;
  12. class EnrollServer
  13. {
  14. public $housename;
  15. public $mobile;
  16. public $city;
  17. public $username;
  18. public $houseType;
  19. public $budget;
  20. /*
  21. * 计算当天剩余时间 返回秒
  22. * */
  23. public function Remainingime()
  24. {
  25. $year = date("Y");
  26. $month = date("m");
  27. $day = date("d");
  28. $end = mktime(23, 59, 59, $month, $day, $year);//当天结束时间戳
  29. return (date('H', $end) - date('H', time())) * 60 * 60;//剩余小时数,
  30. }
  31. /*
  32. * 限制一天报名次数
  33. * */
  34. public function Restrict($input = null)
  35. {
  36. $data = (new Curl())->setPostParams([
  37. 'ucode' => 'http://ygadmin.yigouf.com',
  38. 'phone' => $input['mobile']
  39. ])->post('http://ossimg.pinfangw.com/public/signrestrict');
  40. $data = json_decode($data, true);
  41. if ($data['code'] == 200) {
  42. if ($data['data']['is_test']) {
  43. return $data['data'];
  44. }
  45. $ipinfo = new IpInfoServer();
  46. $ip = $ipinfo->getUserIp();
  47. $cache = \common\api\CacheServer::Cache();
  48. $cacheName = md5($ip);
  49. $CacheContent = $cache->get($cacheName);
  50. $data['data']['count'] = $CacheContent;
  51. if ($CacheContent === false) {
  52. $data['data']['sign'] = false;
  53. $cache->set($cacheName, 1, $this->Remainingime());
  54. } else {
  55. if ($data['data']['sign'] != 0 && $CacheContent >= $data['data']['sign']) {
  56. $data['data']['sign'] == true;//达到指定次数进行限制
  57. } else {
  58. $data['data']['sign'] = false;
  59. $cache->set($cacheName, ++$CacheContent, $this->Remainingime());
  60. }
  61. }
  62. } else {
  63. $data['data']['is_test'] = false;
  64. $data['data']['sign'] == fasle;
  65. }
  66. return $data['data'];
  67. }
  68. /*
  69. * 有归属楼盘 模板
  70. * */
  71. public function TemplateOne()
  72. {
  73. $str = '';
  74. $str .= ' <table class="table">';
  75. $str .= '<tr><td>信息订阅!</td></tr>';
  76. if (!empty($this->username)) {
  77. $str .= ' <tr><td>姓名:</td><td>' . $this->username . '</td></tr>';
  78. }
  79. if (!empty($this->mobile)) {
  80. $str .= '<tr><td>电话:</td><td>' . $this->mobile . '</td></tr>';
  81. }
  82. if (!empty($this->city)) {
  83. $str .= '<tr><td>区域:</td><td>' . $this->city . '</td></tr>';
  84. }
  85. if (!empty($this->housename)) {
  86. $str .= '<tr><td>意向楼盘:</td><td>' . $this->housename . '</td></tr>';
  87. }
  88. if (!empty($this->houseType)) {
  89. $str .= '<tr><td>意向户型:</td><td>' . $this->houseType . '</td></tr>';
  90. }
  91. if (!empty($this->city)) {
  92. $str .= '<tr><td>意向区域:</td><td>' . $this->city . '</td></tr>';
  93. }
  94. if (!empty($this->budget)) {
  95. $str .= '<tr><td>预算:</td><td>' . $this->budget . '</td></tr>';
  96. }
  97. $str .= ' </table>';
  98. return $str;
  99. $msgemail = <<<Eof
  100. <!doctype html>
  101. <html lang="en">
  102. <head>
  103. <meta charset="UTF-8">
  104. <meta name="viewport"
  105. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  106. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  107. <title>邮件</title>
  108. </head>
  109. <body>
  110. <table class="table">
  111. <tr>
  112. <td>信息订阅!</td>
  113. </tr>
  114. <tr>
  115. <td>姓名:</td>
  116. <td>{$this->username}</td>
  117. </tr>
  118. <tr>
  119. <td>电话:</td>
  120. <td>{$this->mobile}</td>
  121. </tr>
  122. <tr>
  123. <td>区域:</td>
  124. <td>{$this->city}</td>
  125. </tr>
  126. <tr>
  127. <td>意向楼盘:</td>
  128. <td>{$this->housename}</td>
  129. </tr>
  130. </table>
  131. </body>
  132. </html>
  133. Eof;
  134. return $msgemail;
  135. }
  136. /*
  137. *公共 模板
  138. * */
  139. public function TemplateTwo()
  140. {
  141. }
  142. public function TabelEmail($input)
  143. {
  144. $str = '';
  145. $str .= ' <table class="table">';
  146. $str .= '<tr><td>信息订阅!</td></tr>';
  147. if (!empty($input['name'])) {
  148. $str .= ' <tr><td>姓名:</td><td>' . $input['name'] . '</td></tr>';
  149. }
  150. if (!empty($input['mobile'])) {
  151. $str .= '<tr><td>电话:</td><td>' . $input['mobile'] . '</td></tr>';
  152. }
  153. if (!empty($input['city_name'])) {
  154. $str .= '<tr><td>区域:</td><td>' . $input['city_name'] . '</td></tr>';
  155. }
  156. if (!empty($input['house_name'])) {
  157. $str .= '<tr><td>意向楼盘:</td><td>' . $input['house_name'] . '</td></tr>';
  158. }
  159. if (!empty($input['intention_housetype'])) {
  160. $str .= '<tr><td>意向户型:</td><td>' . $input['intention_housetype'] . '</td></tr>';
  161. }
  162. if (!empty($input['intention_city'])) {
  163. $str .= '<tr><td>意向区域:</td><td>' . $input['intention_city'] . '</td></tr>';
  164. }
  165. if (!empty($input['budget'])) {
  166. $str .= '<tr><td>预算:</td><td>' . $input['budget'] . '</td></tr>';
  167. }
  168. $str .= ' </table>';
  169. return $str;
  170. }
  171. public function GetArr($input, $str)
  172. {
  173. $arr = [];
  174. $arr['email'] = $input['send_email'];
  175. $arr['title'] = Yii::t('app', 'enter_email');
  176. $arr['content'] = $str;
  177. $arr['id'] = $input['id'];
  178. return $arr;
  179. }
  180. public function ChacPhone($mobile)
  181. {
  182. //限制电话号码
  183. $new_time = time();
  184. $astrict_phone = \common\models\AstrictPhone::find()
  185. ->where(['mobile'=>$mobile,'state'=>1])
  186. ->one();
  187. if(!empty($astrict_phone)){
  188. if(($astrict_phone['astrict_start'] == 0 && $astrict_phone['astrict_start'] == 0)|| ($astrict_phone['astrict_start'] <= $new_time && $astrict_phone['astrict_start'] == 0)||($astrict_phone['astrict_start'] <= $new_time && $astrict_phone['astrict_start'] >= $new_time)){
  189. return ['code'=>true,'msg'=>$astrict_phone['astrict_msg']];
  190. }
  191. }
  192. //今天是否已经报名过
  193. $day_start_time =strtotime(date("Y-m-d",time()));
  194. $rows = \common\models\Enroll::find()
  195. ->where(['mobile'=>$mobile])
  196. ->andWhere(['>','create_at',$day_start_time])
  197. ->orderBy(['create_at'=>SORT_DESC,'id'=>SORT_DESC])
  198. ->asArray()->one();
  199. if(!empty($rows)) return ['code'=>true,'msg'=>'电话号码已经报过名!'];
  200. }
  201. }