VolunteerModel.php
5.3 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/9/26
* Time: 15:42
*/
namespace api\common\model;
use think\Model;
class VolunteerModel extends Model
{
protected $name = 'volunteer';
/**
* 获取对应级别用户
* @param $level
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListByLevel($level){
$levelModel=new LevelModel();
$info=$levelModel->getLevelTime($level);
$map['work_time']=['>',$info['min']];
$map1['work_time']=['<=',$info['max']];
$map['status']=2;
$info=$this->where($map)->where($map1)->order('work_time','DESC')->select()->toArray();
return $info;
}
/**
* 增加工作时间
* @param $level
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addWorkTime($userId,$time){
$map['user_id']=$userId;
$this->where($map)->setInc('work_time',$time);
/*添加团队工时*/
}
public function addStudyTime($userId,$time){
$map['user_id']=$userId;
$this->where($map)->setInc('study_time',$time);
/*添加团队工时*/
}
/**
* 获取用户详情
* @param $userId
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserInfo($userId){
$map['user_id']=$userId;
$user=$this->where($map)->find();
if (empty($user)){
return;
}
$userInfo['area']=$user['province'] ;
$userInfo['nickname']=$user['nickname'] ;
$userInfo['avatar']=cmf_get_image_url($user['photo']);
$userInfo['serial']=$user['serial'] ;
$userInfo['name']=$user['name'];
$userInfo['level']=$user['level'];
$userInfo['work_time']=$user['work_time'];
$userInfo['study_time']=$user['study_time'];
$userInfo['use_time']=$user['use_time']??0;
$userInfo['level_time']=$user['work_time']-$user['use_time'];
$userInfo['status']=$this->getUserState($user['status'],$user['stage']);
return $userInfo;
}
public function getUserState($status,$stage){
$name='';
if ($status==2){
switch ($stage){
case 1:
$name='志愿者(待学习)';
break;
case 2:
$name='志愿者(待实习)';
break;
case 3:
$name='志愿者';
break;
default:
$name='';
break;
}
}else{
$name='非志愿者';
}
return $name;
}
/*
* 获取用户状态
* @param $userId
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserStatus($userId){
$map['user_id']=$userId;
$user=$this->where($map)->find();
if (empty($user)){
$return['code']=0;
$return['remark']='待提交';
}
if ($user['status']==1){
$return['code']=1;
$return['remark']='审核中';
}
if ($user['status']==2){
switch ($user['stage']){
case 1:
$return['code']=2;
$return['remark']='志愿者(待学习)';
break;
case 2:
$return['code']=3;
$return['remark']='志愿者(待实习)';
break;
case 3:
$return['code']=4;
$return['remark']='志愿者';
break;
default:
$return['code']='';
$return['remark']='';
break;
}
// $this->getUserStage()
// if ($user['study_time']>=5 && $user['work_time']>10){
// $userInfo['status']='志愿者';
// $userInfo['user_num']=$userId.$user['create_time'];
// $return['code']=4;
// $return['remark']='志愿者';
// }
//
// if ($user['study_time']<5){
// $userInfo['status']='志愿者(待学习)';
// $userInfo['user_num']='';
// $return['code']=2;
// $return['remark']='志愿者(待学习)';
// }
//
// if ($user['study_time']>=5 && $user['work_time']<10){
// $userInfo['status']='志愿者(待实习)';
// $userInfo['user_num']='';
//
// $return['code']=3;
// $return['remark']='志愿者(待实习)';
// }
}
if ($user['status']==3){
$return['code']=-1;
$return['remark']='不通过';
}
return $return;
}
}