12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- /**
- * Created by PhpStorm.
- * User: LYY
- * Date: 2020.10.22
- */
- namespace common\models;
- //use yii\db\ActiveRecord;
- class ListNews extends Common
- {
- public function rules()
- {
- return [
- ['list_id', 'in', 'range' => [1]],
- ['nid', 'required', 'message' => '咨询不能为空'],
- [['sort', 'state', 'information'], 'safe']
- ];
- /**
- * list_id:[
- * 1:移动端首页房产头条咨询推送位
- * ]
- */
- }
- /***********************************后台数据*******************************************/
- //获取数据列表
- public function getList($input)
- {
- $query = self::find();
- $query->select(['pfg_list_news.*', 'pfg_news.subject','pfg_category_city.city_name','pfg_category_news.news_name']);
- $query->where(['pfg_list_news.list_id' => $input['list_id']]);
- $count = $query->count();
- $query->leftJoin('pfg_news', 'pfg_news.id = pfg_list_news.nid');
- $query->leftJoin('pfg_category_city', 'pfg_news.city = pfg_category_city.id');
- $query->leftJoin('pfg_category_news', 'pfg_news.category = pfg_category_news.id');
- if (!empty($input['page'])) {
- $query->offset(--$input['page'] * $input['limit']);
- }
- if (!empty($input['limit'])) {
- $query->limit($input['limit']);
- }
- $data = $query->orderBy(['pfg_list_news.state' => SORT_ASC, 'pfg_list_news.sort' => SORT_DESC])->asArray()->all();
- foreach ($data as &$val) {
- $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
- }
- return ['msg' => '获取数据完成', 'count' => $count, 'data' => $data];
- }
- /**
- * 获取一条数据
- * */
- public function getFindOne($id)
- {
- $query = self::find();
- $query->select(['pfg_list_house.*', 'pfg_house.name']);
- $query->where(['pfg_list_house.id' => $id]);
- $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
- return $query->asArray()->one();
- }
- /*
- * 检测数据是否存在
- * */
- public function listExists($where)
- {
- return self::find()->where($where)->exists();
- }
- //首页获取指定列表咨询推送位列表
- public function getPushInfo($list_id,$limit = null){
- $select = [
- 'pfg_news.id',
- 'pfg_news.subject'
- ];
- $query = self::find();
- $query->select($select);
- $query->where(['pfg_list_news.list_id'=>$list_id]);
- $query->andWhere(['pfg_news.del'=>1,'pfg_news.state'=>1]);
- $query->leftJoin('pfg_news','pfg_list_news.nid = pfg_news.id');
- if(!empty($limit)){
- $query->limit($limit);
- }
- return $query->orderBy(['pfg_list_news.sort'=>SORT_DESC])->asArray()->all();
- }
- }
|