HouseComment.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:25
  7. */
  8. namespace common\models;
  9. class HouseComment extends Common
  10. {
  11. public $xuqiu = [1 => '预热观看', 2 => '有打算', 3 => '准备下手'];
  12. public $house_name; //搜索楼盘名字
  13. public $reply_status; //回复与未回复
  14. public function rules()
  15. {
  16. return [
  17. ['mobile', 'match', 'pattern' => '/^1[23456789]\d{9}$/', 'message' => '请输入正确的手机号码'],
  18. [['mobile', 'hid', 'content', 'ip'], 'required', 'message' => '{attribute}不能为空'],
  19. ['content', 'string', 'max' => 200],
  20. ['ip', 'ip'],
  21. ['diduan', 'compare', 'compareValue' => 5, 'operator' => '<='],
  22. ['jiaotong', 'compare', 'compareValue' => 5, 'operator' => '<='],
  23. ['peitao', 'compare', 'compareValue' => 5, 'operator' => '<='],
  24. ['huanjing', 'compare', 'compareValue' => 5, 'operator' => '<='],
  25. ['xingjiabi', 'compare', 'compareValue' => 5, 'operator' => '<='],
  26. [['del', 'is_show', 'initiator'], 'in', 'range' => [1, 2], 'message' => '请输入正确的信息'],
  27. [['del', 'is_show', 'initiator'], 'default', 'value' => 1],
  28. // [['jiaotong','peitao','huanjing','xingjiabi','diduan'],'integer','max'=>1],
  29. ['demand', 'in', 'range' => array_flip($this->xuqiu), 'message' => '购房需求错误'],
  30. //搜索字段
  31. ['house_name', 'string', 'max' => 30],
  32. ['reply_status', 'in', 'range' => [1, 2]],
  33. ['read', 'in', 'range' => [1, 2]],
  34. ['author', 'string', 'max' => 255],
  35. ];
  36. }
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'hid' => '楼盘名称',
  41. 'mobile' => '手机号码',
  42. 'ip' => '用户IP地址',
  43. 'content' => '评测内容',
  44. 'author' => '添加人',
  45. ];
  46. }
  47. public function getList($page)
  48. {
  49. $query = self::find();
  50. $query->select(['pfg_house.name', 'pfg_house_comment.*', 'count(pfg_house_comment.hid) as total']);
  51. $query->andWhere(['pfg_house_comment.del' => 1]);
  52. if (!empty($page['content_status'])) {
  53. $query->andWhere(['pfg_house_comment.read' => $page['content_status']]);
  54. }
  55. $query->leftJoin('pfg_house', 'pfg_house_comment.hid=pfg_house.id');
  56. if (!empty($page['house_text'])) {
  57. $query->andWhere(['like', 'pfg_house.name', trim($page['house_text'], " ")]);
  58. }
  59. if (!empty($page['page'])) {
  60. $query->offset = ($page['page'] - 1) * $page['limit'];
  61. $query->limit = $page['limit'];
  62. }
  63. $query->groupBy('pfg_house_comment.hid')->orderBy(['pfg_house_comment.create_at' => SORT_DESC])->asArray();
  64. return $query->all();
  65. }
  66. public function Total()
  67. {
  68. return self::find()->andWhere(['del' => 1])->andFilterWhere(['hid' => $this->hid])->count();
  69. }
  70. public function MoregetList($page)
  71. {
  72. $query = self::find();
  73. $select = ['pfg_house.name', 'pfg_house_comment.*'];
  74. // $query->select(['pfg_house.name','pfg_house_comment.*','(case when pfg_house_commentreply.reply_content is null then 1 when pfg_house_commentreply.reply_content is not null then 2 else null end) reply']);
  75. $query->innerJoin('pfg_house', 'pfg_house_comment.hid=pfg_house.id');
  76. if ($this->reply_status == 2) {
  77. array_push($select, 'pfg_house_commentreply.id as reply');
  78. $query->innerJoin("pfg_house_commentreply", "pfg_house_comment.id = pfg_house_commentreply.cid");
  79. } else if ($this->reply_status == 1) {
  80. $cid = HouseCommentreply::find()->select('cid')->column();
  81. $query->andFilterWhere(['not in', 'pfg_house_comment.id', $cid]);
  82. } else {
  83. array_push($select, 'pfg_house_commentreply.id as reply');
  84. $query->leftJoin("pfg_house_commentreply", " pfg_house_comment.id = pfg_house_commentreply.cid");
  85. }
  86. $query->select($select);
  87. // if(!empty($page['reply_status'])) {
  88. // if ($page['reply_status'] == 1) {
  89. // $query->andWhere("pfg_house_commentreply.reply_content is null");
  90. // }
  91. // if ($page['reply_status'] == 2) {
  92. // $query->andWhere("pfg_house_commentreply.reply_content is not null");
  93. // }
  94. // }
  95. $query->andWhere(['pfg_house.del' => 1]);
  96. $query->andWhere(['pfg_house_comment.del' => 1]);
  97. $query->andFilterWhere(['pfg_house_comment.hid' => $this->hid]);
  98. $query->andFilterWhere(['pfg_house_comment.read' => $this->read]);
  99. $query->andFilterWhere(['pfg_house_comment.initiator' => $this->initiator]);
  100. $query->andFilterWhere(['like', 'pfg_house.name', $this->house_name]);
  101. if (!empty($page['page'])) {
  102. $query->offset = ($page['page'] - 1) * $page['limit'];
  103. $query->limit = $page['limit'];
  104. }
  105. return $query->orderBy(['pfg_house_comment.create_at' => SORT_DESC])->asArray()->all();
  106. // $query = self::find();
  107. // $query->select(['pfg_house_comment.*','(case when pfg_house_commentreply.reply_content is null then 1 when pfg_house_commentreply.reply_content is not null then 2 else null end) reply']);
  108. // $query->leftJoin("pfg_house_commentreply","pfg_house_comment.id = pfg_house_commentreply.cid");
  109. // if(!empty($page['reply_status'])) {
  110. // if ($page['reply_status'] == 1) {
  111. // $query->andWhere("pfg_house_commentreply.reply_content is null");
  112. // }
  113. // if ($page['reply_status'] == 2) {
  114. // $query->andWhere("pfg_house_commentreply.reply_content is not null");
  115. // }
  116. // }
  117. // $query->andWhere(['pfg_house_comment.del'=>1]);
  118. // $query->andWhere(['pfg_house_comment.hid'=>$this->hid]);
  119. // if(!empty($page['content_status'])){
  120. // $query->andWhere(['pfg_house_comment.read' => $page['content_status']]);
  121. // }
  122. // if(!empty($page['page']))
  123. // {
  124. // $query->offset = ($page['page'] - 1) * $page['limit'];
  125. // $query->limit = $page['limit'];
  126. // }
  127. // return $query->orderBy(['pfg_house_comment.create_at'=>SORT_DESC])->asArray()->all();
  128. }
  129. public function FindById($id)
  130. {
  131. return self::findOne($id);
  132. }
  133. //Ip 限制
  134. public function Iplimit($input)
  135. {
  136. $total = self::find()->andWhere(['del' => 1, 'hid' => $input['hid'], 'ip' => $input['ip']])->count();
  137. if ($total >= 2) {
  138. return false;
  139. }
  140. return true;
  141. }
  142. public function getHouseList($page)
  143. {
  144. $query = self::find();
  145. $query->select(['pfg_house.name', 'pfg_house_comment.*']);
  146. $query->andWhere(['pfg_house_comment.del' => 1]);
  147. $query->andWhere(['pfg_house_comment.is_show' => 1]);
  148. $query->andWhere(['pfg_house_comment.hid' => $this->hid]);
  149. $query->leftJoin('pfg_house', 'pfg_house_comment.hid=pfg_house.id');
  150. if (is_array($page) && !empty($page)) {
  151. $query->offset = ($page['page'] - 1) * $page['limit'];
  152. $query->limit = $page['limit'];
  153. } else {
  154. $query->limit = $page;
  155. }
  156. return $query->orderBy(['pfg_house_comment.create_at' => SORT_DESC])->asArray()->all();
  157. }
  158. public function getHouseListTotal()
  159. {
  160. $query = self::find();
  161. $query->andWhere(['del' => 1]);
  162. $query->andWhere(['is_show' => 1]);
  163. $query->andWhere(['hid' => $this->hid]);
  164. return $query->count();
  165. }
  166. public function initSql($query)
  167. {
  168. $query->select(['pfg_house_comment.*', '(case when pfg_house_commentreply.reply_content is null then 1 when pfg_house_commentreply.reply_content is not null then 2 else null end) reply']);
  169. $query->leftJoin("pfg_house_commentreply", "pfg_house_comment.id = pfg_house_commentreply.cid");
  170. if (!empty($page['reply_status'])) {
  171. if ($page['reply_status'] == 1) {
  172. $query->andWhere("pfg_house_commentreply.reply_content is null");
  173. }
  174. if ($page['reply_status'] == 2) {
  175. $query->andWhere("pfg_house_commentreply.reply_content is not null");
  176. }
  177. }
  178. $query->andWhere(['pfg_house_comment.del' => 1]);
  179. $query->andWhere(['pfg_house_comment.hid' => $this->hid]);
  180. if (!empty($page['content_status'])) {
  181. $query->andWhere(['pfg_house_comment.read' => $page['content_status']]);
  182. }
  183. return $query;
  184. }
  185. public function moreTotal($page)
  186. {
  187. $query = self::find();
  188. $query->innerJoin('pfg_house', 'pfg_house_comment.hid=pfg_house.id');
  189. if ($this->reply_status == 2) {
  190. $query->innerJoin("pfg_house_commentreply", "pfg_house_comment.id = pfg_house_commentreply.cid");
  191. } else if ($this->reply_status == 1) {
  192. $cid = HouseCommentreply::find()->select('cid')->column();
  193. $query->andFilterWhere(['not in', 'pfg_house_comment.id', $cid]);
  194. // $query->innerJoin("pfg_house_commentreply", "pfg_house_commentreply.cid != pfg_house_comment.id ");
  195. // $query->andFilterWhere(['<>','pfg_house_commentreply.cid','null']);
  196. }
  197. $query->andWhere(['pfg_house_comment.del' => 1]);
  198. $query->andFilterWhere(['pfg_house_comment.hid' => $this->hid]);
  199. $query->andFilterWhere(['pfg_house_comment.initiator' => $this->initiator]);
  200. $query->andFilterWhere(['like', 'pfg_house.name', $this->house_name]);
  201. $query->andFilterWhere(['pfg_house_comment.read' => $this->read]);
  202. return $query->count();
  203. // $query = self::find();
  204. // $query->select(['pfg_house_comment.*','(case when pfg_house_commentreply.reply_content is null then 1 when pfg_house_commentreply.reply_content is not null then 2 else null end) reply']);
  205. // $query->leftJoin("pfg_house_commentreply","pfg_house_comment.id = pfg_house_commentreply.cid");
  206. // if(!empty($page['reply_status'])) {
  207. // if ($page['reply_status'] == 1) {
  208. // $query->andWhere("pfg_house_commentreply.reply_content is null");
  209. // }
  210. // if ($page['reply_status'] == 2) {
  211. // $query->andWhere("pfg_house_commentreply.reply_content is not null");
  212. // }
  213. // }
  214. // $query->andWhere(['pfg_house_comment.del'=>1]);
  215. // $query->andWhere(['pfg_house_comment.hid'=>$this->hid]);
  216. // if(!empty($page['content_status'])){
  217. // $query->andWhere(['pfg_house_comment.read' => $page['content_status']]);
  218. // }
  219. // return $query->count();
  220. }
  221. //PC资讯列表页热门评论
  222. public function GetComment($limit)
  223. {
  224. $query = self::find();
  225. $query->andWhere(['pfg_house.is_push' => 2]);
  226. $query->andWhere(['pfg_house.is_view' => 1]);
  227. $query->andWhere(['pfg_house.del' => 1]);
  228. $query->andWhere(['pfg_house_comment.is_show' => 1, 'pfg_house_comment.del' => 1]);
  229. $query->select(['pfg_house.id', 'pfg_house.name', 'pfg_house_comment.mobile', 'pfg_house_comment.content', 'pfg_house_comment.create_at']);
  230. $query->leftJoin('pfg_house', 'pfg_house_comment.hid = pfg_house.id');
  231. $query->groupBy('pfg_house_comment.hid');
  232. $query->limit = $limit;
  233. return $query->orderBy('RAND()')->asArray()->all();
  234. }
  235. }