Government.php
6.8 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/12/26
* Time: 17:37
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 农户认证
*/
class Government extends Api
{
/**
* @ApiTitle (农场列表)
* @ApiSummary (农场列表)
* @ApiMethod (POST)
* @ApiRoute (/api/government/index)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="type", type="inter", required=false, description="状态(不传或者1为待认证,2为已通过,3为已拒绝)")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id"://认证ID
"farm_id"://农场id
"createtime"://申请日期
"name"://农场名称
"avatar"://用户头像
"content"://农场简介
"address"://农场地址
}
})
*/
public function index(){
$user_id = $this->getUserId();
//首先查出政府入驻信息
$government = Db::name('government')
->where('user_id',$user_id)
->find();
$type = $this->request->param('type');
if(empty($type) || $type == 1){
//待认证
//查出是属于该政府审核的农场信息
$data = Db::name('attestation')
->where('institution_id',$government['id'])
->field('id,farm_id,createtime,user_id')
->where('status',0)
->select();
foreach ($data as &$v){
$v['createtime'] = date('Y-m-d',$v['createtime']);
$farm = Db::name('farm')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.id',$v['farm_id'])
->field('a.name,a.content,a.address,b.avatar')
->find();
$v['name'] = $farm['name'];
$v['content'] = $farm['content'];
$v['address'] = $farm['address'];
$v['avatar'] = $farm['avatar'];
}
$this->success('success',$data);
}elseif($type == 2){
//已通过
//查出是属于该政府审核的农场信息
$data = Db::name('attestation')
->where('institution_id',$government['id'])
->field('id,farm_id,createtime,user_id')
->where('status',1)
->select();
foreach ($data as &$v){
$v['createtime'] = date('Y-m-d',$v['createtime']);
$farm = Db::name('farm')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.id',$v['farm_id'])
->field('a.name,a.content,a.address,b.avatar')
->find();
$v['name'] = $farm['name'];
$v['content'] = $farm['content'];
$v['address'] = $farm['address'];
$v['avatar'] = $farm['avatar'];
}
$this->success('success',$data);
}elseif ($type == 3){
//已拒绝
//查出是属于该政府审核的农场信息
$data = Db::name('attestation')
->where('institution_id',$government['id'])
->field('id,farm_id,createtime,user_id')
->where('status',2)
->select();
foreach ($data as &$v){
$v['createtime'] = date('Y-m-d',$v['createtime']);
$farm = Db::name('farm')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.id',$v['farm_id'])
->field('a.name,a.content,a.address,b.avatar')
->find();
$v['name'] = $farm['name'];
$v['content'] = $farm['content'];
$v['address'] = $farm['address'];
$v['avatar'] = $farm['avatar'];
}
$this->success('success',$data);
}
}
/**
* @ApiTitle (认证通过)
* @ApiSummary (认证通过)
* @ApiMethod (POST)
* @ApiRoute (/api/government/successful)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="id", type="inter", required=false, description="审核的ID")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function successful()
{
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$res = Db::name('attestation')->where('id',$id)->find();
if($res['status'] == 1 || $res['status'] == 2){
$this->success('已经认证过了');
}
$ren['user_id'] = $res['user_id'];
$ren['title'] = '您的认证申请已通过';
$ren['createtime'] = time();
Db::name('message')->insertGetId($ren);
$data = Db::name('attestation')->where('id',$id)->update(['status'=>1]);
if(empty($data)){
$this->error('审核失败');
}else{
$this->success('审核成功');
}
}
/**
* @ApiTitle (认证拒绝)
* @ApiSummary (认证拒绝)
* @ApiMethod (POST)
* @ApiRoute (/api/government/failed)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="id", type="inter", required=false, description="审核的ID")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function failed()
{
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$res = Db::name('attestation')->where('id',$id)->find();
if($res['status'] == 1 || $res['status'] == 2){
$this->success('已经认证过了');
}
$ren['user_id'] = $res['user_id'];
$ren['title'] = '您的认证申请已拒绝';
$ren['createtime'] = time();
Db::name('message')->insertGetId($ren);
$data = Db::name('attestation')->where('id',$id)->update(['status'=>2]);
if(empty($data)){
$this->error('审核失败');
}else{
$this->success('审核成功');
}
}
}