Government.php
4.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
<?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);
}
}
}