Shopnearby.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 附件店铺控制器
  15. */
  16. class Shopnearby extends MobileMall {
  17. public function initialize() {
  18. parent::initialize();
  19. }
  20. /**
  21. * @api {POST} api/Shopnearby/index 首页显示
  22. * @apiVersion 1.0.0
  23. * @apiGroup Shopnearby
  24. *
  25. * @apiHeader {String} X-DS-KEY 用户授权token
  26. *
  27. * @apiParam {Int} brand 所属品牌id
  28. * @apiParam {Int} category 所属分类id
  29. * @apiParam {String} keyword 关键字
  30. * @apiParam {String} longitude 经度
  31. * @apiParam {String} latitude 纬度
  32. * @apiParam {String} sort_key 键
  33. * @apiParam {String} sort_value 值
  34. * @apiParam {Int} page 当前第几页
  35. * @apiParam {Int} per_page 每页多少
  36. *
  37. * @apiSuccess {String} code 返回码,10000为成功
  38. * @apiSuccess {String} message 返回消息
  39. * @apiSuccess {Object} result 返回数据
  40. * @apiSuccess {Object[]} result.store_list 店铺列表 (返回字段参考store)
  41. * @apiSuccess {Float} result.store_list.distance 距离
  42. * @apiSuccess {Float} result.store_list.store_credit_percent 店铺信用评分
  43. * @apiSuccess {Int} result.page_total 总页数
  44. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  45. */
  46. public function index() {
  47. $this->_get_Own_Store_List();
  48. }
  49. private function _get_Own_Store_List() {
  50. //查询条件
  51. $condition=array();
  52. $condition[] = array('store_state', '=',1);
  53. if (!empty(input('post.keyword'))) {
  54. $condition[] = array('store_name', 'like', '%' . input('post.keyword') . '%');
  55. }
  56. $storeclass_id = intval(input('param.storeclass_id'));
  57. if ($storeclass_id > 0) {
  58. $condition[] = array('storeclass_id', '=', $storeclass_id);
  59. }
  60. $lat = input('post.latitude', 0);
  61. $lng = input('post.longitude', 0);
  62. if (!is_numeric($lat) || !is_numeric($lng)) {
  63. ds_json_encode(10001, lang('param_error'));
  64. }
  65. $sort_key = input('post.sort_key');
  66. switch ($sort_key) {
  67. case 'sale':
  68. $order = 'store_sales desc';
  69. break;
  70. case 'distance':
  71. $order = 'distance asc';
  72. break;
  73. case 'score':
  74. $order = 'store_credit desc';
  75. break;
  76. default:
  77. $order = 'is_platform_store desc,store_recommend desc,store_sort asc,store_baozh desc,store_credit desc,store_desccredit desc';
  78. }
  79. $evaluatestore_model = model('evaluatestore');
  80. $store_list_object = Db::name('store')->where($condition)
  81. ->where('(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lat . '-store_latitude)/360),2)+COS(PI()*' . $lat . '/180)* COS(store_latitude * PI()/180)*POW(SIN(PI()*(' . $lng . '-store_longitude)/360),2)))) < 100000')
  82. ->fieldRaw('store_id,is_platform_store,store_name,area_info,store_address,storeclass_id,store_collect,store_logo,store_avatar,(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lat . '-store_latitude)/360),2)+COS(PI()*' . $lat . '/180)* COS(store_latitude * PI()/180)*POW(SIN(PI()*(' . $lng . '-store_longitude)/360),2)))) as distance')
  83. ->order($order)
  84. ->paginate(['list_rows'=>$this->pagesize,'query' => request()->param()],false);
  85. $store_list = $store_list_object->items();
  86. $memberId = $this->getMemberIdIfExists();
  87. foreach ($store_list as $key => $value) {
  88. $store_list[$key]['distance'] = round($value['distance'], 2);
  89. $store_list[$key]['store_avatar'] = get_store_logo($value['store_avatar'], 'store_avatar');
  90. $store_list[$key]['store_logo'] = get_store_logo($value['store_logo']);
  91. $store_evaluate_info = $evaluatestore_model->getEvaluatestoreInfoByStoreID($value['store_id'], $value['storeclass_id']);
  92. $store_list[$key]['store_credit_percent'] = $store_evaluate_info['store_credit_percent'];
  93. $store_list[$key]['goods_list'] = model('goods')->getGoodsListByColorDistinct(array(array('store_id' ,'=', $value['store_id']), array('goods_commend' ,'=', 1)), 'goods_image,goods_id,goods_price', 'goods_id desc', 0, 4);
  94. foreach ($store_list[$key]['goods_list'] as $k => $v) {
  95. $store_list[$key]['goods_list'][$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $value['store_id']);
  96. }
  97. // 如果已登录 判断该店铺是否已被收藏
  98. if ($memberId) {
  99. $c = (int) model('favorites')->getStoreFavoritesCountByStoreId($value['store_id'], $memberId);
  100. $store_list[$key]['is_favorate'] = $c > 0;
  101. } else {
  102. $store_list[$key]['is_favorate'] = false;
  103. }
  104. }
  105. $result = array_merge(array('store_list' => $store_list), mobile_page($store_list_object));
  106. ds_json_encode(10000, '', $result);
  107. }
  108. }