ActivityModel.php
5.0 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 13:47
*/
namespace api\index\model;
use think\Model;
class ActivityModel extends Model
{
/**
* thumbnail 自动转化
* @param $value
* @return array
*/
public function getThumbnailAttr($value)
{
return cmf_get_image_url($value);
}
/**
* time 自动转化
* @param $value
* @return array
*/
public function getTimeAttr($value)
{
return date('Y-m-d',$value);
}
/**
* content 自动转化
* @param $value
* @return array
*/
public function getContentAttr($value)
{
return cmf_replace_content_file_url(htmlspecialchars_decode($value));
}
public function selectData($page,$pageNum){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['is_up'] = ['eq',1];
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->limit(($page * $pageNum),$pageNum)
->order($order)
->select()
->toArray();
return $data;
}
public function selectDataByTime($page,$pageNum,$type=0){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
if ($type==0){
$where['a.end_time']=['>',time()];
}else{
$where['a.end_time']=['<',time()];
}
$where['is_up'] = ['eq',1];
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->limit(($page * $pageNum),$pageNum)
->order($order)
->select()
->toArray();
return $data;
}
public function selectCityData($city_id,$type=">="){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['a.is_up']=1;
$where['a.end_time']=[$type,time()];
if (!empty($city_id)){
$where['a.position_id'] = $city_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
// echo $this->getLastSql();
return $data;
}
public function selectTypeData($type_id,$type="<="){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['a.is_up']=1;
$where['a.end_time']=[$type,time()];
if (!empty($type_id)){
$where['a.activity_type'] = $type_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
/**
* 即将开始的活动
* @param $page
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function beginAtOnce($page,$pageNum){
$now=time();
$map['a.create_time']=['<',$now];
$map['a.delete_time'] = ['eq',0];
if ($page<=0){
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit('2')
->select()->toArray();
}else{
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit(($page * $pageNum),$pageNum)
->select()->toArray();
}
return $data;
}
}