ProjectModel.class.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?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;
}
}