StoreController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 think\facade\Db;
  10. class StoreController extends Base
  11. {
  12. public function list()
  13. {
  14. $config = Config::getconfig();
  15. if (empty($config['storedistance'])) {
  16. $config['storedistance'] = 10;
  17. }
  18. if (!\app\model\Uploadminiprogram::getaudit(input('get.v', '', 'serach_in'))) {
  19. $stid = input('post.stid', '', 'serach_in');
  20. $cid = input('post.cid', '', 'serach_in');
  21. if (empty($stid)) {
  22. $stid = input('get.stid', '', 'serach_in');
  23. }
  24. if (empty($cid)) {
  25. $cid = input('get.cid', '', 'serach_in');
  26. }
  27. $keyword = input('post.keyword', '', 'serach_in');
  28. $longitude = input('post.longitude', '', 'serach_in'); //经度信息
  29. $latitude = input('post.latitude', '', 'serach_in'); //纬度信息
  30. if (!empty($longitude) && !empty($latitude)) {
  31. $sql = "select * from (select id,stid,cate_ids,weid,sort,title,tzid,owner_name,region_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 desc ) as a where a.distance<=" . ($config['storedistance'] * 1000) . " and status=1";
  32. } else {
  33. $sql = "select * from " . (new Store)->getTable() . " where status=1";
  34. }
  35. $sql .= " and `weid` = " . weid();
  36. if (trim($keyword)) {
  37. $sql .= " and `title` LIKE '%" . $keyword . "%'";
  38. }
  39. if (!empty($stid) && $stid != 'undefined') {
  40. $sql .= " and `stid` = " . $stid;
  41. }
  42. if ($cid) {
  43. $sql .= " and FIND_IN_SET('" . $cid . "',cate_ids) ";
  44. }
  45. //分页
  46. $sqlpage = getsqlpage();
  47. $sql .= " LIMIT " . $sqlpage['start'] . "," . $sqlpage['limit'];
  48. //$sql .= " order by sort asc,id desc";
  49. $data = Db::query($sql);
  50. foreach ($data as &$vo) {
  51. if (!empty($vo['tzid'])) {
  52. if (empty($vo['store_logo']) || empty($vo['title'])) {
  53. $Tuanzhang = Tuanzhang::find($vo['tzid']);
  54. if (!empty($Tuanzhang)) {
  55. $vo['store_logo'] = $Tuanzhang['touxiang'];
  56. $vo['title'] = $Tuanzhang['community_title'];
  57. }
  58. }
  59. }
  60. $vo['store_logo'] = toimg($vo['store_logo']);
  61. $vo['distance'] = round(($vo['distance']) / 1000, 1);
  62. }
  63. }
  64. return $this->json(['data' => $data]);
  65. }
  66. public function detail($id)
  67. {
  68. $data = Store::find($id);
  69. if (!empty($data)) {
  70. $data = $data->toArray();
  71. }
  72. if (!empty($data['tzid'])) {
  73. if (empty($data['store_logo']) || empty($data['title'])) {
  74. $Tuanzhang = Tuanzhang::find($data['tzid']);
  75. if (!empty($Tuanzhang)) {
  76. $data['store_logo'] = $Tuanzhang['touxiang'];
  77. $data['title'] = $Tuanzhang['community_title'];
  78. }
  79. }
  80. }
  81. $data['store_banner'] = StoreImage::where(['sid' => $id, 'ptype' => 'banner'])
  82. ->field('image')
  83. ->order('sort asc')
  84. ->select()
  85. ->toArray();
  86. $data['content_img'] = StoreImage::where(['sid' => $id, 'ptype' => 'content'])
  87. ->field('image')
  88. ->order('sort asc')
  89. ->select()
  90. ->toArray();
  91. if (!empty($data['tzid'])) {
  92. $Tuanzhang = Tuanzhang::find($data['tzid']);
  93. if (!empty($Tuanzhang)) {
  94. if (empty($data['store_logo'])) {
  95. $data['store_logo'] = $Tuanzhang['touxiang'];
  96. }
  97. if (empty($data['title'])) {
  98. $data['title'] = $Tuanzhang['community_title'];
  99. }
  100. if (empty($data['content'])) {
  101. $data['content'] = $Tuanzhang['introduction'];
  102. }
  103. }
  104. }
  105. $data['storeconfig'] = Config::getconfig('store');
  106. $data['create_time'] = time_ymd($data['create_time']);
  107. $data['address'] = $data['city_name'] . $data['district_name'] . $data['house_number'];
  108. return $this->json(['data' => $data]);
  109. }
  110. }