Order.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\api\controller\v1\taxiUser;
  3. use app\api\controller\ApiController;
  4. use app\common\model\Users;
  5. use app\http\IResponse;
  6. use EasyWeChat\Factory;
  7. use Lettered\Support\Upload;
  8. use think\App;
  9. use app\api\service\JWTAuth as IAuth;
  10. use think\Db;
  11. use think\Exception;
  12. class Order extends ApiController
  13. {
  14. protected $model;
  15. public function __construct(App $app = null, IAuth $auth)
  16. {
  17. parent::__construct($app, $auth);
  18. $this->model = new \app\common\model\TaxiOrder();
  19. $this->taxiUserModel = new \app\api\model\taxi\User();
  20. }
  21. public function index()
  22. {
  23. // 1. 传入用户位置
  24. $param = $this->request->param();
  25. // 数据校验
  26. $valid = $this->validate($param, [
  27. 'lng' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
  28. 'lat' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
  29. 'page' => 'require',
  30. ],[
  31. 'lng.require' => '缺少经度参数',
  32. 'lng.regex' => '经度参数有误',
  33. 'lat.require' => '缺少维度参数',
  34. 'lat.regex' => '维度参数有误'
  35. ]);
  36. // 错误
  37. if (true !== $valid){
  38. return $this->ApiJson(-1,$valid);
  39. }
  40. $limit = 20;
  41. $taxiUser = $this->auth->guard('taxi_user')->user();
  42. // $carType =
  43. // 经纬度升序
  44. $lists = $this->model
  45. ->fieldRaw("* , TRUNCATE(( 6371 * acos (
  46. cos ( radians(".$param['lat'].") )
  47. * cos( radians( latitude ) )
  48. * cos( radians( longitude ) - radians(".$param['lng'].") )
  49. + sin ( radians(".$param['lat'].") )
  50. * sin( radians( latitude ) )
  51. )
  52. ), 2) AS distance")
  53. ->having('distance < 10')
  54. ->where(['status' => 2])
  55. ->where(['status' => 2])
  56. ->order(['distance' => 'ASC'])
  57. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  58. ->select();
  59. return $this->ApiJson(0,'', $lists);
  60. }
  61. }