Attestation.php
22.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/12/16
* Time: 19:07
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Cache;
/**
* 农场入驻/认证模块
*/
class Attestation extends Api
{
/**
* @ApiTitle (农场主入驻农场)
* @ApiSummary (农场主入驻农场)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/addForm)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="shen", type="int", required=false, description="身份")
* @ApiParams (name="name", type="string", required=false, description="姓名")
* @ApiParams (name="phone", type="string", required=false, description="电话")
* @ApiParams (name="idcard", type="string", required=false, description="身份证号")
* @ApiParams (name="front", type="string", required=false, description="身份证正面")
* @ApiParams (name="behind", type="string", required=false, description="身份证反面")
* @ApiParams (name="farm_name", type="string", required=false, description="农场名")
* @ApiParams (name="province", type="string", required=true, description="省")
* @ApiParams (name="city", type="string", required=true, description="市")
* @ApiParams (name="county", type="string", required=true, description="区/县")
* @ApiParams (name="address", type="string", required=false, description="位置")
* @ApiParams (name="lng", type="string", required=false, description="经度")
* @ApiParams (name="lat", type="string", required=false, description="纬度")
* @ApiParams (name="content", type="int", required=false, description="简介")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function addForm()
{
$user_id = $this->getUserId();
$param = $this->request->param();
if($param['shen'] != 1){
$this->error('请输入正确的参数');
}
$validate = new Validate([
'name' => 'require',
'phone' => 'require',
'idcard'=>'require',
'front'=>'require',
'behind'=>'require',
'farm_name'=>'require',
'province' => 'require',
'city' => 'require',
'county' => 'require',
'lng'=>'require',
'lat'=>'require',
'address' => 'require',
'content'=>'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$http = 'http://q2ugvq3qf.bkt.clouddn.com';
$param['front'] = str_replace($http,'',$param['front']);
$param['behind'] = str_replace($http,'',$param['behind']);
$param['user_id'] = $user_id;
$param['createtime'] = time();
unset($param['shen']);
$data = Db::name('personage')
->insertGetId($param);
//将农场主的农场信息添加到表中
$res['user_id'] = $user_id;
$id_num = Db::name('user')->where('id',$user_id)->field('id,id_num')->find();
$res['id_num'] = $id_num['id_num'];
$res['identity'] = '个人';
$res['name'] = $param['farm_name'];
$res['content'] = $param['content'];
$res['province'] = $param['province'];
$res['city'] = $param['city'];
$res['county'] = $param['county'];
$res['lng'] = $param['lng'];
$res['lat'] = $param['lat'];
$res['address'] = $param['address'];
$res['createtime'] = time();
Db::name('farm')->insertGetId($res);
//修改用户表中用户的身份 并且 将用户积分加4
Db::name('user')->where('id',$user_id)->update(['identity'=>2,'score'=>4]);
$message['user_id'] = $user_id;
$message['title'] = '恭喜您入驻成功';
$message['content'] = '欢迎来到溯源农场,您已成功入驻,现在您可以在首页添加您的农场项目,发布溯源动态,查看农业资讯。您的操作可以获得工分并参与平台的抽奖活动。请悉心经营您的农场,溯源驿站和您一起为中国的农业而努力!';
$message['createtime'] = time();
Db::name('message')->insertGetId($message);
if($data){
$this->success('入驻成功');
}else{
$this->error('入驻失败');
}
}
/**
* @ApiTitle (企业入驻农场)
* @ApiSummary (企业入驻农场)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/company)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="shen", type="int", required=false, description="身份")
* @ApiParams (name="name", type="string", required=false, description="法人姓名")
* @ApiParams (name="phone", type="string", required=false, description="手机号")
* @ApiParams (name="tel", type="string", required=false, description="座机")
* @ApiParams (name="company_name", type="string", required=false, description="企业名称")
* @ApiParams (name="idcard", type="string", required=false, description="纳税人识别号")
* @ApiParams (name="image", type="string", required=false, description="营业执照")
* @ApiParams (name="farm_name", type="string", required=false, description="农场名称")
* @ApiParams (name="province", type="string", required=true, description="省")
* @ApiParams (name="city", type="string", required=true, description="市")
* @ApiParams (name="county", type="string", required=true, description="区/县")
* @ApiParams (name="address", type="string", required=false, description="位置")
* @ApiParams (name="lng", type="string", required=false, description="经度")
* @ApiParams (name="lat", type="string", required=false, description="纬度")
* @ApiParams (name="content", type="int", required=false, description="简介")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function company()
{
$user_id = $this->getUserId();
$param = $this->request->param();
if($param['shen'] != 2){
$this->error('请输入正确的参数');
}
$validate = new Validate([
'name' => 'require',
'phone' => 'require',
'company_name'=>'require',
'idcard'=>'require',
'image'=>'require',
'farm_name'=>'require',
'province' => 'require',
'city' => 'require',
'county' => 'require',
'lng'=>'require',
'lat'=>'require',
'address' => 'require',
'content'=>'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$http = 'http://q2ugvq3qf.bkt.clouddn.com';
$param['image'] = str_replace($http,'',$param['image']);
$param['user_id'] = $user_id;
$param['createtime'] = time();
unset($param['shen']);
$data = Db::name('company')
->insertGetId($param);
//将企业的农场信息添加到表中
$res['user_id'] = $user_id;
$id_num = Db::name('user')->where('id',$user_id)->field('id,id_num')->find();
$res['id_num'] = $id_num['id_num'];
$res['identity'] = '企业';
$res['name'] = $param['farm_name'];
$res['content'] = $param['content'];
$res['province'] = $param['province'];
$res['city'] = $param['city'];
$res['county'] = $param['county'];
$res['lng'] = $param['lng'];
$res['lat'] = $param['lat'];
$res['address'] = $param['address'];
$res['createtime'] = time();
Db::name('farm')->insertGetId($res);
//修改用户表中用户的身份
Db::name('user')->where('id',$user_id)->update(['identity'=>3,'score'=>4]);
$message['user_id'] = $user_id;
$message['title'] = '恭喜您入驻成功';
$message['content'] = '欢迎来到溯源农场,您已成功入驻,现在您可以在首页添加您的农场项目,发布溯源动态,查看农业资讯。您的操作可以获得工分并参与平台的抽奖活动。请悉心经营您的农场,溯源驿站和您一起为中国的农业而努力!';
$message['createtime'] = time();
Db::name('message')->insertGetId($message);
if($data){
$this->success('入驻成功');
}else{
$this->error('入驻失败');
}
}
/**
* @ApiTitle (政府入驻农场)
* @ApiSummary (政府入驻农场)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/government)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="shen", type="int", required=false, description="身份")
* @ApiParams (name="name", type="string", required=false, description="法人姓名")
* @ApiParams (name="phone", type="string", required=false, description="手机号")
* @ApiParams (name="tel", type="string", required=false, description="座机")
* @ApiParams (name="company_name", type="string", required=false, description="单位名称")
* @ApiParams (name="idcard", type="string", required=false, description="纳税人识别号")
* @ApiParams (name="image", type="string", required=false, description="营业执照")
* @ApiParams (name="province", type="string", required=true, description="省")
* @ApiParams (name="city", type="string", required=true, description="市")
* @ApiParams (name="county", type="string", required=true, description="区/县")
* @ApiParams (name="address", type="string", required=false, description="位置")
* @ApiParams (name="lng", type="string", required=false, description="经度")
* @ApiParams (name="lat", type="string", required=false, description="纬度")
* @ApiParams (name="content", type="int", required=false, description="简介")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function government()
{
$user_id = $this->getUserId();
$param = $this->request->param();
if($param['shen'] != 3){
$this->error('请输入正确的参数');
}
$validate = new Validate([
'name' => 'require',
'phone' => 'require',
'company_name'=>'require',
'idcard'=>'require',
'image'=>'require',
'province' => 'require',
'city' => 'require',
'county' => 'require',
'lng'=>'require',
'lat'=>'require',
'address' => 'require',
'content'=>'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$http = 'http://q2ugvq3qf.bkt.clouddn.com';
$param['image'] = str_replace($http,'',$param['image']);
$param['user_id'] = $user_id;
$param['createtime'] = time();
unset($param['shen']);
$data = Db::name('government')
->insertGetId($param);
//修改用户表中用户的身份
Db::name('user')->where('id',$user_id)->update(['identity'=>4]);
$message['user_id'] = $user_id;
$message['title'] = '恭喜您入驻成功';
$message['content'] = '欢迎来到溯源农场,您已成功入驻,现在您可以在首页添加您的农场项目,发布溯源动态,查看农业资讯。您的操作可以获得工分并参与平台的抽奖活动。请悉心经营您的农场,溯源驿站和您一起为中国的农业而努力!';
$message['createtime'] = time();
Db::name('message')->insertGetId($message);
if($data){
$this->success('提交成功');
}else{
$this->error('提交失败');
}
}
/**
* @ApiTitle (农场入驻信息)
* @ApiSummary (农场入驻信息)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/info)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function info()
{
$user_id = $this->getUserId();
$user = Db::name('user')
->where('id',$user_id)
->field('id,identity')
->find();
if($user['identity'] == 2){
$data = Db::name('personage')
->where('user_id',$user_id)
->field('id,name,phone,farm_name,idcard,front,behind,lng,lat,address,content')
->find();
$data['front'] = 'http://q2ugvq3qf.bkt.clouddn.com'.$data['front'];
$data['behind'] = 'http://q2ugvq3qf.bkt.clouddn.com'.$data['behind'];
$data['identity'] = '农场主';
$this->success('success',$data);
}elseif($user['identity'] == 3){
$data = Db::name('company')
->where('user_id',$user_id)
->field('id,name,phone,tel,company_name,farm_name,idcard,image,lng,lat,address,content')
->find();
$data['idcard'] = str_replace(substr($data['idcard'],2,-3),'*****',$data['idcard']);
$data['identity'] = '企业单位';
$data['image'] = 'http://q2ugvq3qf.bkt.clouddn.com'.$data['image'];
$this->success('success',$data);
}elseif($user['identity'] == 4){
$data = Db::name('government')
->where('user_id',$user_id)
->field('id,name,phone,tel,company_name,idcard,image,lng,lat,address,content,status')
->find();
$data['idcard'] = str_replace(substr($data['idcard'],2,-3),'**',$data['idcard']);
$data['image'] = 'http://q2ugvq3qf.bkt.clouddn.com'.$data['image'];
$data['identity'] = '政府单位';
$this->success('success',$data);
}else{
$this->error('您还没有入住农场');
}
}
/**
* @ApiTitle (我的认证基础信息)
* @ApiSummary (我的认证基础信息)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/attestation)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id":"id",//农场id
"name":"name",//姓名
"identity":"身份",//身份
"farm_name"://农场名
"lng"://经度
"lat"://纬度
"address":"address",//详细地址
"project_num"://创建项目
"createtime"://入驻时间
"is_ti"://是否已经提交(1提交过2没有提交过)
}
})
*/
public function attestation()
{
$user_id = $this->getUserId();
$data = Db::name('user')
->where('id',$user_id)
->find();
if($data['identity'] == 2){
$info = Db::name('attestation')->where('user_id',$user_id)->find();
if(!empty($info)){
$list['is_ti'] = 1;
}else{
$list['is_ti'] = 2;
}
//查询入驻消息 拿出 申请人名字
$res = Db::name('personage')
->where('user_id',$user_id)
->find();
//查询农场表 拿出 农场信息
$farm = Db::name('farm')
->where('user_id',$user_id)
->find();
$list['id'] = $farm['id'];
$list['name'] = $res['name'];
$list['identity'] = $farm['identity'];
$list['farm_name'] = $farm['name'];
$list['lng'] = $farm['lng'];
$list['lat'] = $farm['lat'];
$list['province'] = $farm['province'];
$list['city'] = $farm['city'];
$list['county'] = $farm['county'];
$list['address'] = $farm['address'];
$list['project_num'] = $farm['project_num'];
$list['createtime'] = date('Y-m-d H:i:s',$farm['createtime']);
$this->success('success',$list);
}elseif ($data['identity'] == 3){
//查询是否已经提交认证信息
$info = Db::name('attestation')->where('user_id',$user_id)->find();
if(!empty($info)){
$list['is_ti'] = 1;
}else{
$list['is_ti'] = 2;
}
//查询入驻消息 拿出 申请人名字
$res = Db::name('company')
->where('user_id',$user_id)
->find();
//查询农场表 拿出 农场信息
$farm = Db::name('farm')
->where('user_id',$user_id)
->find();
$list['id'] = $farm['id'];
$list['name'] = $res['name'];
$list['identity'] = $farm['identity'];
$list['farm_name'] = $farm['name'];
$list['lng'] = $farm['lng'];
$list['lat'] = $farm['lat'];
$list['province'] = $farm['province'];
$list['city'] = $farm['city'];
$list['county'] = $farm['county'];
$list['address'] = $farm['address'];
$list['project_num'] = $farm['project_num'];
$list['createtime'] = date('Y-m-d H:i:s',$farm['createtime']);
$this->success('success',$list);
}else{
$this->error('身份有误,请先入驻农场');
}
}
/**
* @ApiTitle (查询认证机构信息)
* @ApiSummary (查询认证机构信息)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/institution)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="province", type="string", required=true, description="省份信息")
* @ApiParams (name="city", type="string", required=true, description="市区")
* @ApiParams (name="county", type="string", required=true, description="区县信息")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
id://机构id
institution://机构
}
})
*/
public function institution()
{
$user_id = $this->getUserId();
$param = $this->request->param();
if(!empty($param['province'])){
$where['province'] = ['Like',"$param[province]%"];
}
if(!empty($param['city'])){
$where['city'] = ['eq',$param['city']] ;
}
if(!empty($param['county'])){
$where['county'] = ['eq',$param['county']];
}
$where['status'] = ['eq',1];
$data = Db::name('government')
->field('id,company_name')
->where($where)
->select();
if(empty($data)){
$city = Db::name('government')
->field('id,company_name')
->where('province','Like',"$param[province]%")
->where('city',$param['city'])
->select();
if(empty($city)){
$province = Db::name('government')
->field('id,company_name')
->where('province','Like',"$param[province]%")
->select();
if(empty($province)){
$this->success('暂无机构');
}else{
$this->success('success',$province);
}
}else{
$this->success('success',$city);
}
}else{
$this->success('success',$data);
}
}
/**
* @ApiTitle (提交认证信息)
* @ApiSummary (提交认证信息)
* @ApiMethod (POST)
* @ApiRoute (/api/attestation/sub)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="farm_id", type="int", required=true, description="农场id")
* @ApiParams (name="institution", type="string", required=true, description="认证机构")
* @ApiParams (name="institution_id", type="int", required=true, description="认证机构ID")
* @ApiParams (name="name", type="string", required=true, description="申请人")
* @ApiParams (name="identity", type="string", required=true, description="身份")
* @ApiParams (name="farm_name", type="string", required=true, description="农场名")
* @ApiParams (name="project_num", type="string", required=true, description="项目个数")
* @ApiParams (name="address", type="string", required=true, description="农场地址")
*
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
id://机构id
institution://机构
}
})
*/
public function sub()
{
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'farm_id' => 'require',
'institution' => 'require',
'name'=>'require',
'identity'=>'require',
'institution_id'=>'require',
'farm_name'=>'require',
'project_num'=>'require',
'address' => 'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$res = Db::name('attestation')->where('user_id',$user_id)->where('farm_id',$param['farm_id'])->find();
if(!empty($res)){
$param['updatetime'] = time();
$param['status'] = 0;
$data = Db::name('attestation')->where('user_id',$user_id)->where('farm_id',$param['farm_id'])->update($param);
if($data){
$this->success('正在审核中');
}else{
$this->error('提交失败');
}
}
$param['createtime'] = time();
$param['user_id'] = $user_id;
$data = Db::name('attestation')
->insertGetId($param);
if($data){
$this->success('提交成功');
}else{
$this->error('提交失败');
}
}
}