Shopnearby.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Shopnearby extends BaseMall {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/shopnearby.lang.php');
  21. }
  22. /*
  23. * 首页显示
  24. */
  25. public function index() {
  26. $storeclass_list = model('storeclass')->getStoreclassList();
  27. View::assign('storeclass_list', $storeclass_list);
  28. $area_mod = model('area');
  29. $city_list = $area_mod->getAreaList(array('area_parent_id' => '0'));
  30. $sort_city_list = array();
  31. foreach ($city_list as $k => $v) {
  32. if (!isset($sort_city_list[$v['area_region']])) {
  33. $sort_city_list[$v['area_region']] = array(
  34. 'region' => $v['area_region'],
  35. 'child' => array()
  36. );
  37. }
  38. $sort_city_list[$v['area_region']]['child'][] = $v;
  39. }
  40. View::assign('city_list', $sort_city_list);
  41. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  42. return View::fetch($this->template_dir . 'index');
  43. }
  44. public function get_Own_Store_List() {
  45. $store_list = array();
  46. //查询条件
  47. $condition = array(array('store_state', '=', 1));
  48. if (!empty(input('get.keyword'))) {
  49. $condition[] = array('store_name', 'like', '%' . input('get.keyword') . '%');
  50. }
  51. $storeclass_id = intval(input('get.storeclass_id'));
  52. if ($storeclass_id) {
  53. $condition[] = array('storeclass_id', '=', $storeclass_id);
  54. }
  55. $lat = input('get.latitude');
  56. $lng = input('get.longitude');
  57. if (!is_numeric($lat) || !is_numeric($lng)) {
  58. ds_json_encode(10001, lang('param_error'));
  59. }
  60. if ($lat && $lng) {
  61. $page = intval(input('get.page'));
  62. $store_list = Db::name('store')->where($condition)->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')->field('store_phone,store_latitude,store_longitude,store_id,is_platform_store,store_name,area_info,store_address,store_logo,store_avatar,store_banner,(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')->order('distance asc')->page($page, 30)->select()->toArray();
  63. foreach ($store_list as $key => $value) {
  64. $goods_conditions = array();
  65. $goods_conditions[] = array('goods_verify', '=', 1);
  66. $goods_conditions[] = array('goods_state', '=', 1);
  67. $store_list[$key]['store_banner'] && $store_list[$key]['store_banner'] = ds_get_pic( ATTACH_STORE . '/' . $value['store_id'] , $value['store_banner']);
  68. $store_list[$key]['distance'] = round($value['distance'], 2);
  69. $store_list[$key]['store_logo'] = get_store_logo($value['store_logo'], 'store_logo');
  70. $store_list[$key]['store_avatar'] = get_store_logo($value['store_avatar'], 'store_avatar');
  71. $goods_conditions[] = array('store_id', '=', $value['store_id']);
  72. $store_list[$key]['goods_list'] = Db::name('goods')->where($goods_conditions)->field('goods_name,goods_id,goods_image,goods_price')->order('goods_addtime desc')->page($page, 4)->select()->toArray();
  73. if (empty($value['area_info'])) {
  74. $store_list[$key]['area_info'] = lang('store_doesn_fill_area');
  75. }
  76. if (empty($value['store_address'])) {
  77. $store_list[$key]['store_address'] = lang('store_not_filled_detailed_address');
  78. }
  79. foreach ($store_list[$key]['goods_list'] as $key2 => $goods) {
  80. $store_list[$key]['goods_list'][$key2]['goods_image'] = goods_cthumb($goods['goods_image']);
  81. }
  82. }
  83. }
  84. if ($store_list) {
  85. echo json_encode($store_list);
  86. exit;
  87. } else {
  88. echo json_encode(false);
  89. exit;
  90. }
  91. }
  92. }