100], [['navi_content'], 'string', 'max' => 255], [['create_user'], 'string', 'max' => 50], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'class_id' => 'Class ID', 'news_title' => 'News Title', 'navi_content' => 'Navi Content', 'content' => 'Content', 'create_user' => 'Create User', 'create_time' => 'Create Time', 'update_time' => 'Update Time', 'delete_flag' => 'Delete Flag', ]; } /** * Function Description:获取新闻列表 * Function Name: GetNewsList * @param $param * * @return array * * @author 娄梦宁 */ public function GetNewsList($param){ $news_title=$param['news_title']; $limit=$param['page_size']; $offset = ($param['current_page'] - 1) * $param['page_size']; $where=['and',['=','delete_flag',0]]; if($news_title!=''){ $where=['like','news_title',$news_title]; } $select=[ 'id', 'class_id'=>new Expression('case class_id when 1 then "公司新闻" when 2 then "新闻报道" when 3 then "行业动态" else "" end'), 'news_title', 'navi_content', 'create_time', ]; $result=self::find()->select($select) ->from(self::tableName()) ->where($where) ->offset($offset) ->limit($limit) ->asArray() ->all(); $count=self::find()->from(self::tableName()) ->where($where)->count(); return [ 'news_list'=>$result, 'page'=>[ 'current_page'=>intval($param['current_page']), 'page_size'=>intval($param['page_size']), 'total_count'=>intval($count), 'total_pages'=>intval(ceil($count/$param['page_size'])), ] ]; } /** * Function Description:删除一条新闻 * Function Name: DelNews * @param $news_id * * * @author 娄梦宁 */ public function DelNews($news_id) { self::updateAll(['delete_flag'=>1],['id'=>$news_id]); } /** * Function Description:获取新闻数据 * Function Name: GetNewsInfo * @param $news_id * * @return array|null|ActiveRecord * * @author 娄梦宁 */ public function GetNewsInfo($news_id) { $select=[ 'news_id'=>'id', 'news_title', 'navi_content', 'content', 'class_id' ]; $result=self::find()->select($select)->from(self::tableName())->where(['id'=>$news_id])->asArray()->one(); return $result; } /** * Function Description:保存新闻,根据id是否传判断新增或修改 * Function Name: SaveNews * @param $params * * * @author 娄梦宁 */ public function SaveNews($params) { $model=clone $this; if(isset($params['id'])){ $model=self::findOne($params['id']); } $model->attributes=$params; $model->save(); } }