StoreController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Store;
  5. use app\model\StoreImage;
  6. use app\model\Users;
  7. use app\model\Tuanzhang;
  8. use app\model\Config;
  9. use app\model\Category;
  10. use app\model\Goods;
  11. use think\facade\Db;
  12. class StoreController extends Base
  13. {
  14. public function list()
  15. {
  16. $config = Config::getconfig();
  17. if (empty($config['storedistance'])) {
  18. $config['storedistance'] = 10;
  19. }
  20. if (!\app\model\Uploadminiprogram::getaudit(input('get.v', '', 'serach_in'))) {
  21. $stid = input('post.stid', '', 'serach_in');
  22. $cid = input('post.cid', '', 'serach_in');
  23. if (empty($stid)) {
  24. $stid = input('get.stid', '', 'serach_in');
  25. }
  26. if (empty($cid)) {
  27. $cid = input('get.cid', '', 'serach_in');
  28. }
  29. $keyword = input('post.keyword', '', 'serach_in');
  30. $longitude = input('post.longitude', '', 'serach_in'); //经度信息
  31. $latitude = input('post.latitude', '', 'serach_in'); //纬度信息
  32. if (!empty($longitude) && !empty($latitude)) {
  33. $sql = "select * from (select id,stid,cate_ids,weid,sort,title,tzid,latitude,longitude,owner_name,region_name,province_name,city_name,district_name,address,store_logo,status, ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($latitude*PI()/180-`latitude`*PI()/180)/2),2)+COS($latitude*PI()/180)*COS(`latitude`*PI()/180)*POW(SIN(($longitude*PI()/180-`longitude`*PI()/180)/2),2)))*1000) AS distance from " . (new Store)->getTable() . " order by distance asc ) as a where a.distance<=" . ($config['storedistance'] * 1000) . " and status=1";
  34. } else {
  35. $sql = "select * from " . (new Store)->getTable() . " where status=1";
  36. }
  37. $sql .= " and `weid` = " . weid();
  38. if (trim($keyword)) {
  39. $sql .= " and (`title` LIKE '%" . $keyword . "%' OR address LIKE '%" . $keyword . "%' OR province_name LIKE '%" . $keyword . "%' OR city_name LIKE '%" . $keyword . "%' OR district_name LIKE '%" . $keyword . "%') ";
  40. }
  41. if (!empty($stid) && $stid != 'undefined') {
  42. $sql .= " and `stid` = " . $stid;
  43. }
  44. if ($cid) {
  45. $sql .= " and FIND_IN_SET('" . $cid . "',cate_ids) ";
  46. }
  47. //分页
  48. $sqlpage = getsqlpage();
  49. $sql .= " LIMIT " . $sqlpage['start'] . "," . $sqlpage['limit'];
  50. //$sql .= " order by sort asc,id desc";
  51. $data = Db::query($sql);
  52. foreach ($data as &$vo) {
  53. if (!empty($vo['tzid'])) {
  54. if (empty($vo['store_logo']) || empty($vo['title'])) {
  55. $Tuanzhang = Tuanzhang::find($vo['tzid']);
  56. if (!empty($Tuanzhang)) {
  57. $vo['store_logo'] = $Tuanzhang['touxiang'];
  58. $vo['title'] = $Tuanzhang['community_title'];
  59. }
  60. }
  61. }
  62. $vo['store_logo'] = toimg($vo['store_logo']);
  63. $vo['distance'] = round(($vo['distance']) / 1000, 1);
  64. }
  65. }
  66. return $this->json(['data' => $data]);
  67. }
  68. public function detail($id)
  69. {
  70. $data = Store::find($id);
  71. if (!empty($data)) {
  72. $data = $data->toArray();
  73. }
  74. if (!empty($data['tzid'])) {
  75. if (empty($data['store_logo']) || empty($data['title'])) {
  76. $Tuanzhang = Tuanzhang::find($data['tzid']);
  77. if (!empty($Tuanzhang)) {
  78. $data['store_logo'] = $Tuanzhang['touxiang'];
  79. $data['title'] = $Tuanzhang['community_title'];
  80. }
  81. }
  82. }
  83. $data['store_banner'] = StoreImage::where(['sid' => $id, 'ptype' => 'banner'])
  84. ->field('image')
  85. ->order('sort asc')
  86. ->select()
  87. ->toArray();
  88. $data['content_img'] = StoreImage::where(['sid' => $id, 'ptype' => 'content'])
  89. ->field('image')
  90. ->order('sort asc')
  91. ->select()
  92. ->toArray();
  93. if (!empty($data['tzid'])) {
  94. $Tuanzhang = Tuanzhang::find($data['tzid']);
  95. if (!empty($Tuanzhang)) {
  96. if (empty($data['store_logo'])) {
  97. $data['store_logo'] = $Tuanzhang['touxiang'];
  98. }
  99. if (empty($data['title'])) {
  100. $data['title'] = $Tuanzhang['community_title'];
  101. }
  102. if (empty($data['content'])) {
  103. $data['content'] = $Tuanzhang['introduction'];
  104. }
  105. }
  106. }
  107. $data['storeconfig'] = Config::getconfig('store');
  108. $data['create_time'] = time_ymd($data['create_time']);
  109. $data['address'] = $data['city_name'] . $data['district_name'] . $data['house_number'];
  110. return $this->json(['data' => $data]);
  111. }
  112. public function goodslist()
  113. {
  114. $sid = input('get.sid', '', 'serach_in');
  115. $catdata = Category::getlist(['pid' => 0, 'status' => 1]);
  116. foreach ($catdata as $vo) {
  117. $vo['goodslist'] = Goods::getGoodsBycat(['sid' => $sid, 'cat' => $vo['id'], 'count' => 100]);
  118. if ($vo['goodslist']) {
  119. $data[] = $vo;
  120. }
  121. }
  122. return $this->json(['data' => $data]);
  123. }
  124. }