TeamModel.php
2.1 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
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/9/26
* Time: 16:06
*/
namespace api\common\model;
use think\Model;
class TeamModel extends Model
{
protected $name = 'team';
public function getPicAttr($value){
return cmf_get_image_url($value);
}
/**
* 获取地址
* @param $order 排序方式
* @param $field 获取字段
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTeamList($order,$field){
$map['status']=2;
$info=$this->where($map)->order($order)->select()->toArray();
return $info;
}
/**
* 获取团队详情
* @param $id id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTeamInfo($id){
$map['id']=$id;
$info=$this->where($map)->find();
$info['create_time_attr']=date('Y-m-d',$info['create_time']);
$info['content']=cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
return $info;
}
public function joinTeamList($user_id){
$map['user_id']=$user_id;
$map['status']=1;
$team_array=db('team_apply')->where($map)->column('team_id');
if (empty($team_array)){
return;
}
$team_id=implode(',',$team_array);
$map1['id']=['in',$team_id];
$info=$this->where($map1)->select();
foreach ($info as $k=>$v){
$info[$k]['pic']=cmf_get_image_url($v['pic']);
$info[$k]['my_time']=$this->myTime($user_id,$v['id']);
}
return $info;
}
/** 我的时间
* @param $user_id
* @param $team_id
* @return float|int
*/
public function myTime($user_id,$team_id){
$map['user_id']=$user_id;
$map['team_id']=$team_id;
$time=db('team_work_log')->where($map)->sum('work_time');
return $time;
}
}