ListNews.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: LYY
  5. * Date: 2020.10.22
  6. */
  7. namespace common\models;
  8. //use yii\db\ActiveRecord;
  9. class ListNews extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['list_id', 'in', 'range' => [1]],
  15. ['nid', 'required', 'message' => '咨询不能为空'],
  16. [['sort', 'state', 'information'], 'safe']
  17. ];
  18. /**
  19. * list_id:[
  20. * 1:移动端首页房产头条咨询推送位
  21. * ]
  22. */
  23. }
  24. /***********************************后台数据*******************************************/
  25. //获取数据列表
  26. public function getList($input)
  27. {
  28. $query = self::find();
  29. $query->select(['pfg_list_news.*', 'pfg_news.subject','pfg_category_city.city_name','pfg_category_news.news_name']);
  30. $query->where(['pfg_list_news.list_id' => $input['list_id']]);
  31. $count = $query->count();
  32. $query->leftJoin('pfg_news', 'pfg_news.id = pfg_list_news.nid');
  33. $query->leftJoin('pfg_category_city', 'pfg_news.city = pfg_category_city.id');
  34. $query->leftJoin('pfg_category_news', 'pfg_news.category = pfg_category_news.id');
  35. if (!empty($input['page'])) {
  36. $query->offset(--$input['page'] * $input['limit']);
  37. }
  38. if (!empty($input['limit'])) {
  39. $query->limit($input['limit']);
  40. }
  41. $data = $query->orderBy(['pfg_list_news.state' => SORT_ASC, 'pfg_list_news.sort' => SORT_DESC])->asArray()->all();
  42. foreach ($data as &$val) {
  43. $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
  44. }
  45. return ['msg' => '获取数据完成', 'count' => $count, 'data' => $data];
  46. }
  47. /**
  48. * 获取一条数据
  49. * */
  50. public function getFindOne($id)
  51. {
  52. $query = self::find();
  53. $query->select(['pfg_list_house.*', 'pfg_house.name']);
  54. $query->where(['pfg_list_house.id' => $id]);
  55. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  56. return $query->asArray()->one();
  57. }
  58. /*
  59. * 检测数据是否存在
  60. * */
  61. public function listExists($where)
  62. {
  63. return self::find()->where($where)->exists();
  64. }
  65. //首页获取指定列表咨询推送位列表
  66. public function getPushInfo($list_id,$limit = null){
  67. $select = [
  68. 'pfg_news.id',
  69. 'pfg_news.subject'
  70. ];
  71. $query = self::find();
  72. $query->select($select);
  73. $query->where(['pfg_list_news.list_id'=>$list_id]);
  74. $query->andWhere(['pfg_news.del'=>1,'pfg_news.state'=>1]);
  75. $query->leftJoin('pfg_news','pfg_list_news.nid = pfg_news.id');
  76. if(!empty($limit)){
  77. $query->limit($limit);
  78. }
  79. return $query->orderBy(['pfg_list_news.sort'=>SORT_DESC])->asArray()->all();
  80. }
  81. }