|
- <?php
- /**
- * 数据库表类 zz_news
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2017/12/19 16:48 $
- */
-
- namespace common\models;
-
- use yii\db\ActiveRecord;
- use yii\db\Exception;
- use yii\db\Expression;
-
- /**
- * 数据库表类 zz_news.
- * @property integer $id
- * @property integer $class_id
- * @property string $news_title
- * @property string $navi_content
- * @property string $content
- * @property string $create_user
- * @property string $create_time
- * @property string $update_time
- * @property integer $delete_flag
- */
- class ZzNews extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'zz_news';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['class_id', 'delete_flag'], 'integer'],
- [['content'], 'required'],
- [['content'], 'string'],
- [['create_time', 'update_time'], 'safe'],
- [['news_title'], 'string', 'max' => 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();
- }
- }
|