| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace app\api\controller\v1\taxiUser;
- use app\api\controller\ApiController;
- use app\common\model\Taxi;
- use app\common\model\TaxiServiceCategory;
- use app\common\model\Users;
- use app\http\IResponse;
- use EasyWeChat\Factory;
- use Lettered\Support\Upload;
- use think\App;
- use app\api\service\JWTAuth as IAuth;
- use think\Db;
- use think\Exception;
- class Order extends ApiController
- {
- protected $model;
- public function __construct(App $app = null, IAuth $auth)
- {
- parent::__construct($app, $auth);
- $this->model = new \app\common\model\TaxiOrder();
- $this->taxiUserModel = new \app\api\model\taxi\User();
- }
- /**
- * 接单大厅订单列表
- * @return mixed|\think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function index()
- {
- // 1. 传入用户位置
- $param = $this->request->param();
- // 数据校验
- $valid = $this->validate($param, [
- 'lng' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
- 'lat' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
- 'page' => 'require',
- ],[
- 'lng.require' => '缺少经度参数',
- 'lng.regex' => '经度参数有误',
- 'lat.require' => '缺少维度参数',
- 'lat.regex' => '维度参数有误'
- ]);
- // 错误
- if (true !== $valid){
- return IResponse::failure($valid);
- }
- $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
- $taxiUser = $this->auth->guard('taxi_user')->user();
- if(!$taxiUser){
- return IResponse::failure('用户不存在,或已被冻结');
- }
- $categoryIds = Taxi::where(['taxi_user_id'=> $taxiUser['id']])->column('category_id');
- $categoryIds = array_unique($categoryIds);
- // 经纬度升序
- $lists = $this->model
- ->fieldRaw("* , TRUNCATE(( 6371 * acos (
- cos ( radians(".$param['lat'].") )
- * cos( radians( latitude ) )
- * cos( radians( longitude ) - radians(".$param['lng'].") )
- + sin ( radians(".$param['lat'].") )
- * sin( radians( latitude ) )
- )
- ), 2) AS distance")
- ->having('distance < 10')
- ->where(['status' => 2])
- ->where(function($query) use($categoryIds){
- if($categoryIds){
- $query->whereIn('category_id', $categoryIds);
- }
- })
- ->order(['distance' => 'ASC'])
- ->limit((($param['page'] - 1) * $limit) . "," . $limit)
- ->select();
- return IResponse::success($lists,'获取成功');
- }
- /**
- * 我的订单
- * @return mixed
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function myOrder()
- {
- // 1. 传入用户位置
- $param = $this->request->param();
- $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
- $taxiUser = $this->auth->guard('taxi_user')->user();
- if(!$taxiUser){
- return IResponse::failure('用户不存在,或已被冻结');
- }
- // 经纬度升序
- $lists = $this->model->with(['paylog','user','taxi','taxiUser'])
- ->where(['taxi_uid' => $taxiUser['id']])
- ->order(['created_at' => 'desc'])
- ->limit((($param['page'] - 1) * $limit) . "," . $limit)
- ->select();
- return IResponse::success($lists,'获取成功');
- }
- /**
- * 等待服务订单
- * @return mixed|\think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function waitOrder()
- {
- $taxiUser = $this->auth->guard('taxi_user')->user();
- if(!$taxiUser){
- return IResponse::failure('用户不存在,或已被冻结');
- }
- $info = model('common/TaxiOrder')->with(['paylog','user','taxi','taxiUser'])
- ->where(['taxi_uid' => $taxiUser['id']])
- ->whereIn('status',[2,3])
- ->order('created_at','desc')
- ->find();
- if($info){
- return IResponse::success(!is_null($info)? $info : [],'获取成功');
- }else{
- return IResponse::failure('获取失败');
- }
- }
- /**
- * 接单
- * @return mixed
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function receive()
- {
- $param = $this->request->param();
- $id = isset($param['id'])? $param['id'] : 0;
- $taxiUser = $this->auth->guard('taxi_user')->user();
- if(!$taxiUser){
- return IResponse::failure('用户不存在,或已被冻结');
- }
- $info = model('common/TaxiOrder')
- ->where(['taxi_uid' => $taxiUser['id'],'id'=> $id, 'status'=>3])
- ->order('created_at','desc')
- ->find();
- if(empty($info)){
- return IResponse::failure('订单不存在,或已处理');
- }
- }
- /**
- * 已送达
- * @return mixed
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function delivered()
- {
- $param = $this->request->param();
- $id = isset($param['id'])? $param['id'] : 0;
- $taxiUser = $this->auth->guard('taxi_user')->user();
- if(!$taxiUser){
- return IResponse::failure('用户不存在,或已被冻结');
- }
- $info = model('common/TaxiOrder')
- ->where(['taxi_uid' => $taxiUser['id'],'id'=> $id, 'status'=>3])
- ->order('created_at','desc')
- ->find();
- if(empty($info)){
- return IResponse::failure('订单不存在,或已处理');
- }
- }
- }
|