作者 王智

daima

@@ -307,210 +307,215 @@ class Index extends Api @@ -307,210 +307,215 @@ class Index extends Api
307 if ($param['type'] == 1) { 307 if ($param['type'] == 1) {
308 $map3['is_show'] = ['eq', 1]; 308 $map3['is_show'] = ['eq', 1];
309 } 309 }
310 - $rult = Db::name('seller')->where($map3)->where($map)->where($map2)->order('weight desc')->page($param['pages'], $param['rows'])->select();  
311 - $count = Db::name('seller')->where($map3)->where($map)->where($map2)->order('weight desc')->select();  
312 -  
313 - dump($rult);  
314 - die;if (empty($rult)) {  
315 - //如果为空 310 + $rult = Db::name('seller')->where($map3)->where($map)->where($map2)->order('weight asc')->page($param['pages'], $param['rows'])->select();
  311 + $count = Db::name('seller')->where($map3)->where($map)->where($map2)->order('weight asc')->select();
  312 + //asc
316 $list = [ 313 $list = [
317 'count' => 0, 314 'count' => 0,
318 'list' => [] 315 'list' => []
319 ]; 316 ];
320 - } else {  
321 - //计算距离 KM  
322 - foreach ($rult as $k => $v) {  
323 - $ruestul[$k]['id'] = $v['id'];  
324 - $ruestul[$k]['title'] = $v['title'];  
325 - $ruestul[$k]['address'] = $v['address'];  
326 - $ruestul[$k]['avatar'] = cdnurl($v['avatar']);  
327 - $ruestul[$k]['order'] = $v['order'];  
328 - if (empty($param['lng']) || $param['lng'] == null || $param['lng'] == '' || $param['lng'] == "") {  
329 - $ruestul[$k]['from'] = '暂无距离信息';  
330 - } else {  
331 - $ruestul[$k]['from'] = $this->getDistance($param['lng'], $param['lat'], $v['lng'], $v['lat']) . 'km';  
332 - }  
333 - $ruestul[$k]['talk_num'] = $v['talk_num'];  
334 - }  
335 - $newarr = array_column($ruestul, 'from');  
336 - array_multisort($newarr, SORT_ASC, $ruestul);  
337 - $list = [  
338 - 'count' => count($count),  
339 - 'list' => $ruestul  
340 - ];  
341 - }  
342 - $this->success('成功', $list);  
343 - } 317 + } else
  318 +{
  319 + //计算距离 KM
  320 +foreach ($rult as $k => $v)
  321 +{
  322 +$ruestul[$k]['id'] = $v['id'];
  323 +$ruestul[$k]['title'] = $v['title'];
  324 +$ruestul[$k]['address'] = $v['address'];
  325 +$ruestul[$k]['avatar'] = cdnurl($v['avatar']);
  326 +$ruestul[$k]['order'] = $v['order'];
  327 +if (empty($param['lng']) || $param['lng'] == null || $param['lng'] == '' || $param['lng'] == "")
  328 +{
  329 +$ruestul[$k]['from'] = '暂无距离信息';
  330 +}
344 331
  332 +else {
  333 + $ruestul[$k]['from'] = $this->getDistance($param['lng'], $param['lat'], $v['lng'], $v['lat']) . 'km';
  334 +}
  335 +$ruestul[$k]['talk_num'] = $v['talk_num'];
  336 +}
  337 +$newarr = array_column($ruestul, 'from');
  338 +array_multisort($newarr, SORT_ASC, $ruestul);
  339 +$list = [
  340 + 'count' => count($count),
  341 + 'list' => $ruestul
  342 +];
  343 +}
  344 +$this->success('成功', $list);
  345 +}
345 346
346 - /**  
347 - * 首页接口  
348 - * @ApiTitle (首页接口-店铺详情)  
349 - * @ApiSummary (店铺详情)  
350 - * @ApiMethod (POST)  
351 - * @ApiRoute (/api/Index/SellerCon)  
352 - * @ApiParams (name="id", type="int", required=true, description="店铺ID")  
353 - * @ApiParams (name="pages", type="int", required=true, description="pages")  
354 - * @ApiParams (name="rows", type="int", required=true, description="rows")  
355 - * @ApiReturnParams (name="code", type="integer", required=true, sample="0")  
356 - * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")  
357 - * @ApiReturn ({  
358 - 'code':'1',  
359 - 'msg':'返回成功',  
360 - "data": {  
361 - "id": 3,  
362 - "avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",  
363 - "title": "这是第三个店铺",  
364 - "opentime": "8:00-9:00",  
365 - "address": "北京市北京市海淀区吴玉章路",  
366 - "mobile": "1391929399",  
367 - "content": "<p>这是第三个商家的详情</p>",  
368 - "num": 3, //平均评分  
369 - "talkList": {  
370 - "count": 1,//评论总数  
371 - "talk": [  
372 - {  
373 - "id": 1, //评论id  
374 - "num": 3, //评分  
375 - "createtime": "1970-05-09", //评论时间  
376 - "avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/0wpUDw5m0LRvdDueia3uMWmrYb53GXRaTnYwMWC18kRmX6P6PIaPDgQqarEIfwroicx1z51D6bjQicOV0PibBx2PqQ/132",  
377 - "nickname": "Gody",  
378 - "images": [ //评论图  
379 - "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",  
380 - "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png"  
381 - ]  
382 - }  
383 - ]  
384 - } 347 +
  348 +/**
  349 + * 首页接口
  350 + * @ApiTitle (首页接口-店铺详情)
  351 + * @ApiSummary (店铺详情)
  352 + * @ApiMethod (POST)
  353 + * @ApiRoute (/api/Index/SellerCon)
  354 + * @ApiParams (name="id", type="int", required=true, description="店铺ID")
  355 + * @ApiParams (name="pages", type="int", required=true, description="pages")
  356 + * @ApiParams (name="rows", type="int", required=true, description="rows")
  357 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  358 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  359 + * @ApiReturn ({
  360 +'code':'1',
  361 +'msg':'返回成功',
  362 +"data": {
  363 +"id": 3,
  364 +"avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
  365 +"title": "这是第三个店铺",
  366 +"opentime": "8:00-9:00",
  367 +"address": "北京市北京市海淀区吴玉章路",
  368 +"mobile": "1391929399",
  369 +"content": "<p>这是第三个商家的详情</p>",
  370 +"num": 3, //平均评分
  371 +"talkList": {
  372 +"count": 1,//评论总数
  373 +"talk": [
  374 +{
  375 +"id": 1, //评论id
  376 +"num": 3, //评分
  377 +"createtime": "1970-05-09", //评论时间
  378 +"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/0wpUDw5m0LRvdDueia3uMWmrYb53GXRaTnYwMWC18kRmX6P6PIaPDgQqarEIfwroicx1z51D6bjQicOV0PibBx2PqQ/132",
  379 +"nickname": "Gody",
  380 +"images": [ //评论图
  381 +"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
  382 +"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png"
  383 +]
  384 +}
  385 +]
  386 +}
  387 +}
  388 +})
  389 + */
  390 +public
  391 +function SellerCon()
  392 +{
  393 + $param = $this->request->param();
  394 + $seller_arr = Db::name('seller')->where('id', $param['id'])->find();
  395 + if (empty($seller_arr)) {
  396 + $this->error('参数错误', 0);
  397 + die;
385 } 398 }
386 - })  
387 - */  
388 - public function SellerCon()  
389 - {  
390 - $param = $this->request->param();  
391 - $seller_arr = Db::name('seller')->where('id', $param['id'])->find();  
392 - if (empty($seller_arr)) {  
393 - $this->error('参数错误', 0);  
394 - die;  
395 - }  
396 - $list = [  
397 - 'id' => $seller_arr['id'],  
398 - 'avatar' => cdnurl($seller_arr['avatar']),  
399 - 'title' => $seller_arr['title'],  
400 - 'opentime' => $seller_arr['opentime'],  
401 - 'address' => $seller_arr['address'],  
402 - 'lng' => $seller_arr['lng'],  
403 - 'lat' => $seller_arr['lat'],  
404 - 'mobile' => $seller_arr['mobile'],  
405 - 'content' => $seller_arr['content'] 399 + $list = [
  400 + 'id' => $seller_arr['id'],
  401 + 'avatar' => cdnurl($seller_arr['avatar']),
  402 + 'title' => $seller_arr['title'],
  403 + 'opentime' => $seller_arr['opentime'],
  404 + 'address' => $seller_arr['address'],
  405 + 'lng' => $seller_arr['lng'],
  406 + 'lat' => $seller_arr['lat'],
  407 + 'mobile' => $seller_arr['mobile'],
  408 + 'content' => $seller_arr['content']
  409 + ];
  410 + $talk_arr = Db::name('seller_talk')
  411 + ->alias('s')
  412 + ->join('user u', 'u.id=s.user_id')
  413 + ->where('seller_id', $param['id'])
  414 + ->order('id desc')
  415 + ->page($param['pages'], $param['rows'])
  416 + ->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
  417 + ->select();
  418 + $count = Db::name('seller_talk')
  419 + ->alias('s')
  420 + ->join('user u', 'u.id=s.user_id')
  421 + ->where('seller_id', $param['id'])
  422 + ->order('id desc')
  423 + ->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
  424 + ->select();
  425 + if (empty($talk_arr)) {
  426 + $list['num'] = 5;
  427 + $list['talkList'] = [
  428 + 'count' => 0,
  429 + 'talk' => []
406 ]; 430 ];
407 - $talk_arr = Db::name('seller_talk')  
408 - ->alias('s')  
409 - ->join('user u', 'u.id=s.user_id')  
410 - ->where('seller_id', $param['id'])  
411 - ->order('id desc')  
412 - ->page($param['pages'], $param['rows'])  
413 - ->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')  
414 - ->select();  
415 - $count = Db::name('seller_talk')  
416 - ->alias('s')  
417 - ->join('user u', 'u.id=s.user_id')  
418 - ->where('seller_id', $param['id'])  
419 - ->order('id desc')  
420 - ->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')  
421 - ->select();  
422 - if (empty($talk_arr)) {  
423 - $list['num'] = 5;  
424 - $list['talkList'] = [  
425 - 'count' => 0,  
426 - 'talk' => []  
427 - ];  
428 - } else {  
429 - $sum = array_sum(array_column($count, 'num'));  
430 - $list['num'] = ($sum + 5) / (count($count) + 1);  
431 - foreach ($talk_arr as $k => $v) {  
432 - $talkList[$k]['id'] = $v['id'];  
433 - $talkList[$k]['num'] = $v['num'];  
434 - $talkList[$k]['createtime'] = date('Y-m-d', $v['createtime']);  
435 - $talkList[$k]['avatar'] = $v['avatar'];  
436 - $talkList[$k]['nickname'] = $v['nickname'];  
437 - $talkList[$k]['title'] = $v['title'];  
438 - if (empty($v['images'])) {  
439 - $talkList[$k]['images'] = []; 431 + } else {
  432 + $sum = array_sum(array_column($count, 'num'));
  433 + $list['num'] = ($sum + 5) / (count($count) + 1);
  434 + foreach ($talk_arr as $k => $v) {
  435 + $talkList[$k]['id'] = $v['id'];
  436 + $talkList[$k]['num'] = $v['num'];
  437 + $talkList[$k]['createtime'] = date('Y-m-d', $v['createtime']);
  438 + $talkList[$k]['avatar'] = $v['avatar'];
  439 + $talkList[$k]['nickname'] = $v['nickname'];
  440 + $talkList[$k]['title'] = $v['title'];
  441 + if (empty($v['images'])) {
  442 + $talkList[$k]['images'] = [];
  443 + } else {
  444 + if (strstr($v['images'], ',')) {
  445 + $image = explode(',', $v['images']);
440 } else { 446 } else {
441 - if (strstr($v['images'], ',')) {  
442 - $image = explode(',', $v['images']);  
443 - } else {  
444 - $image = explode(' ', $v['images']);  
445 - }  
446 - foreach ($image as $k1 => $v1) {  
447 - $image[$k1] = cdnurl($v1);  
448 - }  
449 - $talkList[$k]['images'] = $image; 447 + $image = explode(' ', $v['images']);
450 } 448 }
  449 + foreach ($image as $k1 => $v1) {
  450 + $image[$k1] = cdnurl($v1);
  451 + }
  452 + $talkList[$k]['images'] = $image;
451 } 453 }
452 - $list['talkList'] = [  
453 - 'count' => count($count),  
454 - 'talk' => $talkList  
455 - ];  
456 } 454 }
457 - $this->success('成功', $list); 455 + $list['talkList'] = [
  456 + 'count' => count($count),
  457 + 'talk' => $talkList
  458 + ];
458 } 459 }
  460 + $this->success('成功', $list);
  461 +}
459 462
460 463
461 - /**  
462 - * 首页接口  
463 - * @ApiTitle (首页接口-添加评论)  
464 - * @ApiSummary (添加评论)  
465 - * @ApiMethod (POST)  
466 - * @ApiRoute (/api/Index/TalkSave)  
467 - * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")  
468 - * @ApiParams (name="seller_id", type="int", required=true, description="商家ID")  
469 - * @ApiParams (name="title", type="int", required=true, description="评论内容")  
470 - * @ApiParams (name="images", type="int", required=true, description="评论图")  
471 - * @ApiParams (name="num", type="int", required=true, description="评分")  
472 - * @ApiReturnParams (name="code", type="integer", required=true, sample="0")  
473 - * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")  
474 - * @ApiReturn ({  
475 - 'code':'1',  
476 - 'msg':'返回成功',  
477 - })  
478 - */  
479 - public function TalkSave()  
480 - {  
481 - $param = $this->request->param();  
482 - $user_id = $this->is_token($this->request->header());  
483 - $data = [  
484 - 'seller_id' => $param['seller_id'],  
485 - 'user_id' => $user_id,  
486 - 'title' => $param['title'],  
487 - 'num' => $param['num'],  
488 - 'images' => $param['images'],  
489 - 'createtime' => time(),  
490 - ];  
491 - $res = Db::name('seller_talk')->insert($data);  
492 - $talk_num = Db::name('seller')->where('id', $param['seller_id'])->value('talk_num');  
493 - Db::name('seller')->where('id', $param['seller_id'])->update(['talk_num' => $talk_num + 1]);  
494 - $this->res($res);  
495 - } 464 +/**
  465 + * 首页接口
  466 + * @ApiTitle (首页接口-添加评论)
  467 + * @ApiSummary (添加评论)
  468 + * @ApiMethod (POST)
  469 + * @ApiRoute (/api/Index/TalkSave)
  470 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  471 + * @ApiParams (name="seller_id", type="int", required=true, description="商家ID")
  472 + * @ApiParams (name="title", type="int", required=true, description="评论内容")
  473 + * @ApiParams (name="images", type="int", required=true, description="评论图")
  474 + * @ApiParams (name="num", type="int", required=true, description="评分")
  475 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  476 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  477 + * @ApiReturn ({
  478 +'code':'1',
  479 +'msg':'返回成功',
  480 +})
  481 + */
  482 +public
  483 +function TalkSave()
  484 +{
  485 + $param = $this->request->param();
  486 + $user_id = $this->is_token($this->request->header());
  487 + $data = [
  488 + 'seller_id' => $param['seller_id'],
  489 + 'user_id' => $user_id,
  490 + 'title' => $param['title'],
  491 + 'num' => $param['num'],
  492 + 'images' => $param['images'],
  493 + 'createtime' => time(),
  494 + ];
  495 + $res = Db::name('seller_talk')->insert($data);
  496 + $talk_num = Db::name('seller')->where('id', $param['seller_id'])->value('talk_num');
  497 + Db::name('seller')->where('id', $param['seller_id'])->update(['talk_num' => $talk_num + 1]);
  498 + $this->res($res);
  499 +}
496 500
497 501
498 - /**  
499 - * 首页接口  
500 - * @ApiTitle (首页接口-联系客服文字)  
501 - * @ApiSummary (联系客服文字)  
502 - * @ApiMethod (POST)  
503 - * @ApiRoute (/api/Index/Lianxi)  
504 - * @ApiReturnParams (name="code", type="integer", required=true, sample="0")  
505 - * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")  
506 - * @ApiReturn ({  
507 - 'code':'1',  
508 - 'msg':'返回成功',  
509 - })  
510 - */  
511 - public function Lianxi()  
512 - {  
513 - $title = Db::name('lianxi')->where('id', 1)->value('title');  
514 - $this->success('成功', $title);  
515 - } 502 +/**
  503 + * 首页接口
  504 + * @ApiTitle (首页接口-联系客服文字)
  505 + * @ApiSummary (联系客服文字)
  506 + * @ApiMethod (POST)
  507 + * @ApiRoute (/api/Index/Lianxi)
  508 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  509 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  510 + * @ApiReturn ({
  511 +'code':'1',
  512 +'msg':'返回成功',
  513 +})
  514 + */
  515 +public
  516 +function Lianxi()
  517 +{
  518 + $title = Db::name('lianxi')->where('id', 1)->value('title');
  519 + $this->success('成功', $title);
  520 +}
516 } 521 }