ProjectModel.class.php 2.4 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/4/28
 * Time: 11:54
 */

namespace Common\Model;

use Common\Model\CommonModel;

class ProjectModel extends CommonModel {

    // 自动验证
    protected $_validate = array(
        //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
        array('name', 'require', '名称不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('description', 'require', '描述不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('city', 'require', '城市不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('thumb', 'require', '缩略图不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('image', 'require', '缩略图不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('sname', 'require', '传承人名称不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('avatar', 'require', '传承人头像不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('sdescription', 'require', '传承人描述不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
//        array('href_ids', 'require', '报道跳转资讯id不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('content', 'require', '详情不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
    );

    // 获取列表
    public function getList($page_num, $keyword = null, $start_time = null, $end_time = null) {
        $perPage = 25;
        $where['is_del'] = 0;
        if($keyword) {
            $where['name'] = array('like', '%'.$keyword.'%');
        }
        if($start_time && $end_time) {
            $where['ctime'] = array('between', array($start_time,$end_time));
        }
        return $this->where($where)
            ->page($page_num, $perPage)
            ->select();
    }

    // 获取详情
    public function getInfo($id) {
        $where['is_del'] = 0;
        $where['id'] = $id;
        return $this->where($where)->find();
    }

    /**
     * 获取数据总数
     * @author Liuzhen
     */
    public function getCount($keyword = null, $start_time = null, $end_time = null) {
        if($keyword) {
            $where['name'] = array('like', '%'.$keyword.'%');
        }
        if($start_time && $end_time) {
            $where['ctime'] = array('between', array($start_time,$end_time));
        }
        $where['is_del'] = 0;
        $count = $this->where($where)
            ->count();
        return $count;
    }
}