Shop.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Index.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: http://www.niushop.com.cn
  9. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  10. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  11. * =========================================================
  12. * @author : niuteam
  13. * @date : 2015.1.17
  14. * @version : v1.0.0.0
  15. */
  16. namespace app\api\controller;
  17. use app\model\shop\Shop as ShopModel;
  18. use app\model\web\WebSite;
  19. class Shop extends BaseApi
  20. {
  21. /**
  22. * 基础信息
  23. */
  24. public function info()
  25. {
  26. $site_id = isset($this->params['site_id']) ? $this->params['site_id'] : 0;
  27. if (empty($site_id)) {
  28. return $this->response($this->error('', 'REQUEST_SITE_ID'));
  29. }
  30. $shop = new ShopModel();
  31. $field = 'site_id,expire_time,site_name,website_id,is_own,level_name,category_name,shop_status,start_time,logo,avatar,banner,
  32. seo_description,qq,ww,telephone,shop_desccredit,shop_servicecredit,shop_deliverycredit,workingtime,shop_baozh,shop_baozhopen,shop_baozhrmb,
  33. shop_qtian,shop_zhping,shop_erxiaoshi,shop_tuihuo,shop_shiyong,shop_shiti,shop_xiaoxie,shop_free_time,shop_sales,shop_adv,work_week,address,full_address,longitude,latitude,sub_num';
  34. $info = $shop->getShopInfo([ [ 'site_id', '=', $site_id ] ], $field);
  35. return $this->response($info);
  36. }
  37. public function page()
  38. {
  39. $page = isset($this->params['page']) ? $this->params['page'] : 1;
  40. $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
  41. $keyword = isset($this->params['keyword']) ? $this->params['keyword'] : '';//关键词
  42. $order = isset($this->params['order']) ? $this->params['order'] : "site_id";//排序(综合、销量、信用)
  43. $sort = isset($this->params['sort']) ? $this->params['sort'] : "desc";//升序、降序
  44. $web_city = isset($this->params['web_city']) ? $this->params['web_city'] : "";
  45. $lat = isset($this->params['lat']) ? $this->params['lat'] : ""; // 纬度
  46. $lng = isset($this->params['lng']) ? $this->params['lng'] : ""; // 经度
  47. $shop = new ShopModel();
  48. $condition = [
  49. [ 'shop_status', '=', 1 ],
  50. [ 'cert_id', '<>', 0 ]
  51. ];
  52. if (!empty($keyword)) {
  53. $condition[] = [ 'site_name', 'like', '%' . $keyword . '%' ];
  54. }
  55. // 非法参数进行过滤
  56. if ($sort != "desc" && $sort != "asc") {
  57. $sort = "";
  58. }
  59. // 非法参数进行过滤
  60. if ($order != '') {
  61. if ($order != "shop_sales" && $order != "shop_desccredit") {
  62. $order = 'site_id';
  63. }
  64. $order_by = $order . ' ' . $sort;
  65. } else {
  66. $order_by = 'is_recommend desc,sort desc,site_id desc';
  67. }
  68. // 查询是否存在城市分站
  69. if (addon_is_exit('city') && !empty($web_city)) {
  70. $website_model = new WebSite();
  71. $website_info = $website_model->getWebSite([ [ 'site_area_id', '=', $web_city ] ], 'site_id');
  72. if (!empty($website_info['data'])) {
  73. $order_by = "INSTR('{$website_info['data']['site_id']}', website_id) desc," . $order_by;
  74. }
  75. }
  76. $list = $shop->getShopPageList($condition, $page, $page_size, $order_by, 'site_id,site_name,category_name,group_name,logo,avatar,banner,seo_description,shop_desccredit,shop_servicecredit,shop_deliverycredit,shop_sales,sub_num,is_own,longitude,latitude,telephone,address,full_address');
  77. if (!empty($list['data']['list'])) {
  78. foreach ($list['data']['list'] as $k => $item) {
  79. if ($item['longitude'] && $item['latitude'] && $lng && $lat) {
  80. $list['data']['list'][ $k ]['distance'] = round(getDistance((float) $item['longitude'], (float) $item['latitude'], (float) $lng, (float) $lat));
  81. } else {
  82. $list['data']['list'][ $k ]['distance'] = 0;
  83. }
  84. }
  85. }
  86. return $this->response($list);
  87. }
  88. /**
  89. * 是否显示店铺相关功能,用于审核小程序
  90. */
  91. public function isShow()
  92. {
  93. $res = 1;// 0 隐藏,1 显示
  94. return $this->response($this->success($res));
  95. }
  96. }