TuanzhangController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Tuanzhang;
  5. use app\model\Config;
  6. use think\facade\Db;
  7. class TuanzhangController extends Base
  8. {
  9. public function list()
  10. {
  11. $keyword = input('post.keyword', '', 'serach_in');
  12. $config = Config::getconfig();
  13. $longitude = input('post.longitude', '', 'serach_in'); //经度信息
  14. $latitude = input('post.latitude', '', 'serach_in'); //纬度信息
  15. if (!empty($longitude) && !empty($latitude)) {
  16. $sql = "select * from (select id,weid,sort,title,city_name,district_name,region_name,house_number,touxiang,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 Tuanzhang)->getTable() . " order by distance asc ) as a where a.distance<=" . ($config['technicaldistance'] * 1000) . " and status=1 ";
  17. } else {
  18. $sql = "select * from " . (new Tuanzhang)->getTable() . " where status=1 ";
  19. }
  20. $sql .= " and `weid` = " . weid();
  21. if (trim($keyword)) {
  22. $sql .= " and `title` LIKE '%" . $keyword . "%'";
  23. }
  24. $data = Db::query($sql);
  25. foreach ($data as &$vo) {
  26. $vo['touxiang'] = toimg($vo['touxiang']);
  27. $vo['distance'] = round(($vo['distance']) / 1000, 1);
  28. }
  29. $res['data'] = $data;
  30. return $this->json(['data' => $res]);
  31. }
  32. public function detail($id)
  33. {
  34. $data = Tuanzhang::find($id);
  35. if (!empty($data)) {
  36. $data = $data->toArray();
  37. }
  38. $data['create_time'] = time_ymd($data['create_time']);
  39. $data['address'] = $data['region_name'] . $data['house_number'];
  40. return $this->json(['data' => $data]);
  41. }
  42. }