User.php
17.5 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\Car;
use app\common\model\Hotel;
use app\common\model\House;
use app\common\model\Num;
use app\common\model\UserTalk;
use app\common\model\UserToken;
use app\common\model\Yue;
use fast\Random;
use think\console\command\make\Model;
use think\Validate;
/**
* 我的接口
*/
class User extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
}
/**
* 我的接口
*/
public function index()
{
$this->success('', ['welcome' => $this->auth->nickname]);
}
/**
* @ApiTitle (我的接口-我的信息)
* @ApiSummary (我的信息)
* @ApiMethod (POST)
* @ApiRoute (/api/user/user_my)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data":{
"avatar":"用户头像",
"name":"用户姓名",
"status":"会员级别:[1=普通会员,2=高级会员]",
"money":"余额",
"num":"积分"
}
})
*/
public function user_my()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$user_model = new \app\common\model\User();
$user_arr = $user_model::get(['user_id' => $user_id['id']]);
$yue_model = new Yue();
$yue_arr = $yue_model::get(['user_id' => $user_id['id']]);
$yue = $yue_arr['tixian_yes'] + $yue_arr['tixian_no'];
$num_model = new Num();
$num_zengjia = $num_model::all(['user_id' => $user_id['id'], 'status' => 1]);
$num_jianshao = $num_model::all(['user_id' => $user_id['id'], 'status' => 0]);
$num_zengjia_num = array_sum(array_column($num_zengjia, 'num'));
$num_jianshao_num = array_sum(array_column($num_jianshao, 'num'));
$num = $num_zengjia_num - $num_jianshao_num;
$return = [
'avatar' => $user_arr['avatar'],
'name' => $user_arr['name'],
'status' => $user_arr['vip'],
'money' => $yue,
'num' => $num
];
$this->success('成功', $return);
}
/**
* @ApiTitle (我的接口-我的信息)
* @ApiSummary (我的信息)
* @ApiMethod (POST)
* @ApiRoute (/api/user/seller_ruzhu)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="name", type="string", required=true, description="姓名")
* @ApiParams (name="mobile", type="int", required=true, description="联系电话")
* @ApiParams (name="import_num", type="string", required=true, description="税号")
* @ApiParams (name="address", type="string", required=true, description="地址")
* @ApiParams (name="kaihu", type="string", required=true, description="开户行")
* @ApiParams (name="kaihu_name", type="string", required=true, description="账号")
* @ApiParams (name="seller_status", type="tinyint", required=true, description="店铺类型:[1=餐饮,2=酒店,3=加油站,4=重卡汽修,5=汽修,6=超市]")
* @ApiParams (name="seller_name", type="string", required=true, description="店铺名")
* @ApiParams (name="seller_avatar", type="string", required=true, description="门头")
* @ApiParams (name="seller_con", type="string", required=true, description="店铺简介")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
})
*/
public function seller_ruzhu()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$param = $this->request->param();
$seller_model = new \app\common\model\Seller();
$arr = [
'name' => $param['name'],
'mobile' => $param['mobile'],
'address' => $param['address'],
'kaihu' => $param['kaihu'],
'kaihu_num' => $param['kaihu_num'],
'seller_status' => $param['seller_status'],
'seller_name' => $param['seller_name'],
'import_num' => $param['import_num'],
'seller_avatar' => $param['seller_avatar'],
'seller_con' => $param['seller_con'],
'status' => 2,
'user_id' => $user_id['id'],
];
$res = $seller_model->save($arr);
if ($res) {
$this->success('成功');
} else {
$this->error('添加失败');
}
}
/**
* @ApiTitle (我的接口-申请状态)
* @ApiSummary (申请状态)
* @ApiMethod (POST)
* @ApiRoute (/api/user/is_status)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
"status":"审核状态:[0=审核未通过,1=审核通过,2=审核为未通过]"
}
})
*/
public function is_status()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$model = new \app\common\model\Seller();
$arr = $model::get(['user_id' => $user_id['id']]);
$return = ['status' => $arr['status']];
$this->success('成功', $return);
}
/**
* @ApiTitle (我的接口-余额)
* @ApiSummary (余额)
* @ApiMethod (POST)
* @ApiRoute (/api/user/yue)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
"tixian_yes":"可提现余额",
"tixian_no":"不可提现余额"
}
})
*/
public function yue()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$model = new Yue();
$arr = $model::get(['user_id' => $user_id['id']]);
$return = ['tixian_yes' => $arr['tixian_yes'], 'tixian_no' => $arr['tixian_no']];
$this->success('成功', $return);
}
/**
* @ApiTitle (我的接口-预约列表)
* @ApiSummary (预约列表)
* @ApiMethod (POST)
* @ApiRoute (/api/user/yy_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
"name":"姓名",
"time":"时间",
"id":"预约ID"
}
})
*/
public function yy_list()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$seller_model = new \app\common\model\Seller();
$user_model = new \app\common\model\User();
$seller_arr = $seller_model::get(['user_id' => $user_id['id']]);
if ($seller_arr['seller_status'] == 2) {
$model = new Hotel();
$hotel_con = $model::all(['seller_id' => $seller_arr['id']]);
foreach ($hotel_con as $k => $v) {
$return5[$k]['time'] = $v['createtime'];
$return5[$k]['id'] = $v['id'];
$id_arr[$k] = $v['user_id'];
}
foreach ($id_arr as $k => $v) {
$return2[$k] = $user_model::all(['user_id' => $v]);
}
foreach ($return2 as $k => $v) {
$return3[] = $v[0];
}
foreach ($return3 as $k => $v) {
$return4[$k]['name'] = $v['name'];
}
foreach ($return5 as $key => $vo) {
$list[] = array_merge($vo, $return4[$key]);
}
if ($hotel_con) {
$this->success('成功', $list);
} else {
$list = [
'name' => '',
'time' => ''
];
$this->success('成功', $list);
}
}
if ($seller_arr['seller_status'] == 5) {
$model = new Car();
$car_con = $model::all(['seller_id' => $seller_arr['id']]);
foreach ($car_con as $k => $v) {
$return5[$k]['time'] = $v['createtime'];
$return5[$k]['id'] = $v['id'];
$id_arr[$k] = $v['user_id'];
}
foreach ($id_arr as $k => $v) {
$return2[$k] = $user_model::all(['user_id' => $v]);
}
foreach ($return2 as $k => $v) {
$return3[] = $v[0];
}
foreach ($return3 as $k => $v) {
$return4[$k]['name'] = $v['name'];
}
foreach ($return5 as $key => $vo) {
$list[] = array_merge($vo, $return4[$key]);
}
if ($car_con) {
$this->success('成功', $list);
} else {
$list = [
'name' => '',
'time' => ''
];
$this->success('成功', $list);
}
}
}
/**
* @ApiTitle (我的接口-预约详情酒店)
* @ApiSummary (预约详情酒店)
* @ApiMethod (POST)
* @ApiRoute (/api/user/yy_hotel_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="int", required=true, description="预约ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
"name":"用户名",
"avatar":"头像",
"vip":"会员级别:[1=普通会员,2=高级会员]",
"time":"时间",
"people_num":"人数",
"house_name":房型",
}
})
*/
public function yy_hotel_list()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$id = input('id');
$hotel_model = new Hotel();
$hotel_arr = $hotel_model::get(['id' => $id])->toArray();
$user_model = new \app\common\model\User();
$user_con = $user_model::get(['user_id' => $hotel_arr['user_id']]);
$house_model = new House();
$house_name = $house_model::get(['id' => $hotel_arr['house_id']]);
$return = [
'name' => $user_con['name'],
'avatar' => $user_con['avatar'],
'vip' => $user_con['vip'],
'time' => date("Y-m-d H:i:s", $hotel_arr['createtime']),
'people_num' => $hotel_arr['people_num'],
'house_name' => $house_name['house_name']
];
$this->success('成功', $return);
}
/**
* @ApiTitle (我的接口-预约详情汽修)
* @ApiSummary (预约详情汽修)
* @ApiMethod (POST)
* @ApiRoute (/api/user/yy_car_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="int", required=true, description="预约ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
"name":"用户名",
"avatar":"头像",
"vip":"会员级别:[1=普通会员,2=高级会员]",
"time":"时间",
"car":"车型",
"car_num":车牌号",
"only_num":17位编码"
}
})
*/
public function yy_car_list()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$id = input('id');
$car_model = new Car();
$car_arr = $car_model::get(['id' => $id])->toArray();
$user_model = new \app\common\model\User();
$user_con = $user_model::get(['user_id' => $car_arr['user_id']]);
$return = [
'name' => $user_con['name'],
'avatar' => $user_con['avatar'],
'vip' => $user_con['vip'],
'time' => date("Y-m-d H:i:s", $car_arr['createtime']),
'car' => $car_arr['car'],
'car_num' => $car_arr['car_num'],
'only_num' => $car_arr['only_num'],
];
$this->success('成功', $return);
}
/**
* @ApiTitle (我的接口-评价)
* @ApiSummary (评价)
* @ApiMethod (POST)
* @ApiRoute (/api/user/user_talk)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="int", required=true, description="店铺ID")
* @ApiParams (name="star", type="int", required=true, description="星级")
* @ApiParams (name="con", type="string", required=true, description="评价内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function user_talk()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$param = $this->request->param();
$talk_model = new UserTalk();
$res = $talk_model->save(['star' => $param['star'], 'talk_con' => $param['con'], 'user_id' => $user_id, 'seller_id' => $param['id']]);
if ($res) {
$this->success('成功');
} else {
$this->error('评价增加失败!');
}
}
/**
* @ApiTitle (我的接口-评价展示)
* @ApiSummary (评价展示)
* @ApiMethod (POST)
* @ApiRoute (/api/user/user_talk_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="int", required=true, description="店铺ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
"seller_avatar":"门头",
"seller_name":"店铺名"
}
})
*/
public function user_talk_list()
{
$token = $this->request->header();
if (empty($token['token'])) {
$this->error('请登陆后再操作!', '', '9');
}
$token_model = new UserToken();
$user_id = $token_model::get(['token' => $token['token']]);
if (!$user_id) {
$this->error('Token不存在', '', '8');
}
$id = input('id');
$model = new \app\common\model\Seller();
$arr = $model::get(['id' => $id]);
$return = [
'seller_avatar' => $arr['seller_avatar'],
'seller_name' => $arr['seller_name']
];
$this->success('成功', $return);
}
}