JoinModel.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
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2019/2/28
* Time: 18:29
*/
namespace api\index\model;
use think\Model;
class JoinModel extends Model
{
public function findData($where){
$data=$this->where($where)->order('id','desc')->find();
return $data;
}
/**
* 查询多条
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectData($where){
$data=$this->where($where)->select()->toArray();
return $data;
}
public function getJoinData($activity_id){
$where['j.activity_id']=$activity_id;
$where['j.status']=['in','1,3'];
$where['j.delete_time']=0;
$info=$this->alias('j')
->join('cmf_volunteer v','v.user_id=j.user_id')
->where($where)
//->fetchSql()
->select()
->toArray();
//->toArray();
//dump($info);
return $info;
}
/**
* @param $userId 用户参加活动id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserJoin($userId){
$where['j.user_id']=$userId;
$where['j.status']=['in','1,3'];
$where['j.delete_time']=0;
$info=$this->alias('j')
->field('a.*,at.type_name,pp.*,a.id as id')
->join('cmf_activity a','a.id=j.activity_id')
->join('cmf_activity_type at','a.activity_type=at.id','LEFT')
->join('cmf_position_province pp','a.position_id=pp.id','LEFT')
->where($where)
->order('a.start_time','desc')
->group('a.id')
->select()
->toArray();
foreach ($info as $k=>$v){
$info[$k]['start_time_text']=date('Y-m-d',$v['start_time']);
$info[$k]['end_time_text']=date('Y-m-d',$v['end_time']);
$info[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
}
// echo $this->getLastSql();
return $info;
}
}