Index.php
18.0 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 首页接口
* @ApiTitle (首页接口-轮播图)
* @ApiSummary (轮播图)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/Banner)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"id": 1,
"image": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"content": "<p>富文本详情</p>",
"hot_id": 热点文章ID,
"seller_id": 门店,
"type": 类别:1=富文本详情,2=热点文章详情,3=门店详情,
"createtime": 1598851787,
"updatetime": 1598852871
}
]
})
*/
public function Banner()
{
$list = Db::name('index_banner')->select();
if (empty($list)) {
$list = [];
} else {
foreach ($list as $k => $v) {
$list[$k]['image'] = cdnurl($v['image']);
}
}
$this->success('成功', $list);
}
/**
* 首页接口
* @ApiTitle (首页接口-热点文章列表)
* @ApiSummary (热点文章列表)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/HotList)
* @ApiParams (name="pages", type="int", required=true, description="pages")
* @ApiParams (name="rows", type="int", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"count": 总数,
"list": [
{
"id": 2,
"avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"type": 1=置顶,0=不置顶,
"title": "这是第二个热点新闻",
"look": 查看数,
"createtime": "2020-08-31"
}
]
}
})
*/
public function HotList()
{
$param = $this->request->param();
$arr = Db::name('hot')->order('id desc')->select();
if (empty($arr)) {
$count = 0;
$list = [];
} else {
foreach ($arr as $k => $v) {
if ($v['type'] == 1) {
$list[$k]['id'] = $v['id'];
$list[$k]['avatar'] = cdnurl($v['avatar']);
$list[$k]['type'] = $v['type'];
$list[$k]['title'] = $v['title'];
$list[$k]['look'] = $v['look'];
$list[$k]['createtime'] = date('Y-m-d', $v['createtime']);
}
}
foreach ($arr as $k => $v) {
if ($v['type'] == 0) {
$list[$k]['id'] = $v['id'];
$list[$k]['avatar'] = cdnurl($v['avatar']);
$list[$k]['type'] = $v['type'];
$list[$k]['title'] = $v['title'];
$list[$k]['look'] = $v['look'];
$list[$k]['createtime'] = date('Y-m-d', $v['createtime']);
}
}
$count = count($list);
$list = $this->page_array($param['rows'], $param['pages'], $list, 0);
}
$rult = [
'count' => $count,
'list' => $list
];
$this->success('成功', $rult);
}
/**
* 首页接口
* @ApiTitle (首页接口-热点文章详情)
* @ApiSummary (热点文章详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/HotCon)
* @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": {
"id": 1,
"avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"title": "这是第一个热点新闻",
"type": 1=置顶,0=不置顶,,
"content": "<p>这是第一个热点新闻这是第一个热点新闻这是第一个热点新闻这是第一个热点新闻这是第一个热点新闻这是第一个热点新闻这是第一个热点新闻<br></p>",
"look": 查看数,
"createtime": "2020-08-31",
"updatetime": 1598852900
}
})
*/
public function HotCon()
{
$id = input('id');
$look = Db::name('hot')->where('id', $id)->value('look');
Db::name('hot')->where('id', $id)->update(['look' => $look + 1]);
$array = Db::name('hot')->where('id', $id)->find();
if (empty($array)) {
$this->error('参数错误', 0);
die;
}
$array['avatar'] = cdnurl($array['avatar']);
$array['createtime'] = date('Y-m-d', $array['createtime']);
$this->success('成功', $array);
}
/**
* 首页接口
* @ApiTitle (首页接口-热点文章查看数增加)
* @ApiSummary (热点文章查看数增加)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/HotLookNumSave)
* @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": {
}
})
*/
public function HotLookNumSave()
{
$id = input('id');
$look = Db::name('hot')->where('id', $id)->value('look');
$res = Db::name('hot')->where('id', $id)->update(['look' => $look + 1]);
$this->res($res);
}
/**
* 首页接口
* @ApiTitle (首页接口-会员购买详情)
* @ApiSummary (会员购买详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/BuyVipCon)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"id": 1,
"title": "名称",
"con": "权益",
"type": 1=折扣0=普通,
"del_price": "划线价格",
"price": "价格"
}
]
})
*/
public function BuyVipCon()
{
$rult = Db::name('vip')->select();
if (empty($rult)) {
$list = [];
} else {
foreach ($rult as $k => $v) {
$list[$k]['id'] = $v['id'];
$list[$k]['title'] = $v['title'];
$list[$k]['con'] = $v['con'];
$list[$k]['type'] = $v['type'];
$list[$k]['del_price'] = $v['del_price'];
$list[$k]['price'] = $v['price'];
}
}
$this->success('成功', $list);
}
/**
* 首页接口
* @ApiTitle (首页接口-洗车服务详情)
* @ApiSummary (洗车服务详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/CarConWri)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"fuwu": "<p>服务内容<img alt=\"1111.png\" src=\"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png\" width=\"157\" height=\"237\"></p>",
"qingxi": "<p><span style=\"font-size: 13px;\">清洗方式:</span><img alt=\"1111.png\" src=\"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png\" width=\"157\" height=\"237\"><br></p>",
"zhuyi": "<p>注意事项:</p><div class=\"simditor-wrapper\"><div class=\"simditor-toolbar\" style=\"width: 492.263px;\"><ul><li></li></ul></div><img alt=\"20200523_161817_867.png\" src=\"http://xiche.qiniu.bronet.cn/uploads/20200831/Fpai9ciBOkSDnU3UrAWJ3J0acogV.png\" width=\"728\" height=\"410\"></div>",
"xiche": "<p><img alt=\"20200523_161817_867.png\" src=\"http://xiche.qiniu.bronet.cn/uploads/20200831/Fpai9ciBOkSDnU3UrAWJ3J0acogV.png\" width=\"728\" height=\"410\"><br></p><p>洗车详情:</p><div class=\"simditor-wrapper\"><div class=\"simditor-toolbar\" style=\"width: 492.263px;\"><ul><li></li></ul></div></div>"
}
})
*/
public function CarConWri()
{
$arr = Db::name('vip_con')->order('id desc')->limit(1)->find();
$data = [
'fuwu' => $arr['fuwu_content'],
'qingxi' => $arr['qingxi_content'],
'zhuyi' => $arr['zhuyi_content'],
'xiche' => $arr['xiche_content'],
];
$this->success('成功', $data);
}
/**
* 首页接口
* @ApiTitle (首页接口-首页爱车养护列表)
* @ApiSummary (首页爱车养护列表)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/IndexLoveCarList)
* @ApiParams (name="lat", type="int", required=true, description="纬度")
* @ApiParams (name="lng", type="int", required=true, description="经度")
* @ApiParams (name="pages", type="int", required=true, description="pages")
* @ApiParams (name="rows", type="int", required=true, description="rows")
* @ApiParams (name="keywords", type="string", required=true, description="搜索关键字")
* @ApiParams (name="city", type="string", required=true, description="区域关键字")
* @ApiParams (name="type", type="int", required=true, description="1=首页,2=爱车养护")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"count": 2,
"list": [
{
"id": 店铺ID,
"title": "店铺名",
"address": "店铺地址",
"avatar": "店铺头图",
"order": 订单数,
"from": "距离",
"talk_num": 评论数
}
]
}
})
*/
public function IndexLoveCarList()
{
$param = $this->request->param();
$map = [];
$map2 = [];
$map3 = [];
if ($param['city'] != '全市') {
$map['address'] = ['LIKE', '%' . $param['city'] . '%'];
}
if (!empty($param['keywords']) || $param['keywords'] != null || $param['keywords'] != '' || $param['keywords'] != "") {
$map2['title'] = ['LIKE', '%' . $param['keywords'] . '%'];
}
if ($param['type'] == 1) {
$map3['is_show'] = ['eq', 1];
}
$rult = Db::name('seller')->where($map3)->where($map)->where($map2)->order('id desc')->page($param['pages'], $param['rows'])->select();
$count = Db::name('seller')->where($map3)->where($map)->where($map2)->order('id desc')->select();
if (empty($rult)) {
//如果为空
$list = [
'count' => 0,
'list' => []
];
} else {
//计算距离 KM
foreach ($rult as $k => $v) {
$ruestul[$k]['id'] = $v['id'];
$ruestul[$k]['title'] = $v['title'];
$ruestul[$k]['address'] = $v['address'];
$ruestul[$k]['avatar'] = cdnurl($v['avatar']);
$ruestul[$k]['order'] = $v['order'];
if (empty($param['lng']) || $param['lng'] == null || $param['lng'] == '' || $param['lng'] == "") {
$ruestul[$k]['from'] = '暂无距离信息';
} else {
$ruestul[$k]['from'] = $this->getDistance($param['lng'], $param['lat'], $v['lng'], $v['lat']) . 'km';
}
$ruestul[$k]['talk_num'] = $v['talk_num'];
}
$newarr = array_column($ruestul, 'from');
array_multisort($newarr, SORT_ASC, $ruestul);
$list = [
'count' => count($count),
'list' => $ruestul
];
}
$this->success('成功', $list);
}
/**
* 首页接口
* @ApiTitle (首页接口-店铺详情)
* @ApiSummary (店铺详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/SellerCon)
* @ApiParams (name="id", type="int", required=true, description="店铺ID")
* @ApiParams (name="pages", type="int", required=true, description="pages")
* @ApiParams (name="rows", type="int", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 3,
"avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"title": "这是第三个店铺",
"opentime": "8:00-9:00",
"address": "北京市北京市海淀区吴玉章路",
"mobile": "1391929399",
"content": "<p>这是第三个商家的详情</p>",
"num": 3, //平均评分
"talkList": {
"count": 1,//评论总数
"talk": [
{
"id": 1, //评论id
"num": 3, //评分
"createtime": "1970-05-09", //评论时间
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/0wpUDw5m0LRvdDueia3uMWmrYb53GXRaTnYwMWC18kRmX6P6PIaPDgQqarEIfwroicx1z51D6bjQicOV0PibBx2PqQ/132",
"nickname": "Gody",
"images": [ //评论图
"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png"
]
}
]
}
}
})
*/
public function SellerCon()
{
$param = $this->request->param();
$seller_arr = Db::name('seller')->where('id', $param['id'])->find();
if (empty($seller_arr)) {
$this->error('参数错误', 0);
die;
}
$list = [
'id' => $seller_arr['id'],
'avatar' => cdnurl($seller_arr['avatar']),
'title' => $seller_arr['title'],
'opentime' => $seller_arr['opentime'],
'address' => $seller_arr['address'],
'lng' => $seller_arr['lng'],
'lat' => $seller_arr['lat'],
'mobile' => $seller_arr['mobile'],
'content' => $seller_arr['content']
];
$talk_arr = Db::name('seller_talk')
->alias('s')
->join('user u', 'u.id=s.user_id')
->where('seller_id', $param['id'])
->order('id desc')
->page($param['pages'], $param['rows'])
->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
->select();
$count = Db::name('seller_talk')
->alias('s')
->join('user u', 'u.id=s.user_id')
->where('seller_id', $param['id'])
->order('id desc')
->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
->select();
if (empty($talk_arr)) {
$list['num'] = 0;
$list['talkList'] = [
'count' => 0,
'talk' => []
];
} else {
$sum = array_sum(array_column($count, 'num'));
$list['num'] = $sum / count($count);
foreach ($talk_arr as $k => $v) {
$talkList[$k]['id'] = $v['id'];
$talkList[$k]['num'] = $v['num'];
$talkList[$k]['createtime'] = date('Y-m-d', $v['createtime']);
$talkList[$k]['avatar'] = $v['avatar'];
$talkList[$k]['nickname'] = $v['nickname'];
$talkList[$k]['title'] = $v['title'];
if (empty($v['images'])) {
$talkList[$k]['images'] = [];
} else {
if (strstr($v['images'], ',')) {
$image = explode(',', $v['images']);
} else {
$image = explode(' ', $v['images']);
}
foreach ($image as $k1 => $v1) {
$image[$k1] = cdnurl($v1);
}
$talkList[$k]['images'] = $image;
}
}
$list['talkList'] = [
'count' => count($count),
'talk' => $talkList
];
}
$this->success('成功', $list);
}
/**
* 首页接口
* @ApiTitle (首页接口-添加评论)
* @ApiSummary (添加评论)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/TalkSave)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="seller_id", type="int", required=true, description="商家ID")
* @ApiParams (name="title", type="int", required=true, description="评论内容")
* @ApiParams (name="images", type="int", required=true, description="评论图")
* @ApiParams (name="num", type="int", 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 TalkSave()
{
$param = $this->request->param();
$user_id = $this->is_token($this->request->header());
$data = [
'seller_id' => $param['seller_id'],
'user_id' => $user_id,
'title' => $param['title'],
'num' => $param['num'],
'images' => $param['images'],
'createtime' => time(),
];
$res = Db::name('seller_talk')->insert($data);
$talk_num = Db::name('seller')->where('id', $param['seller_id'])->value('talk_num');
Db::name('seller')->where('id', $param['seller_id'])->update(['talk_num' => $talk_num + 1]);
$this->res($res);
}
}