diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 0e38650f..f84383d4 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -11,7 +11,7 @@ use think\response\Json; */ class VehicleController extends BaseApiController { - public array $notNeedLogin = ['getCompany','setContract','tricycle','multipleRent','singleRent']; + public array $notNeedLogin = ['getCompany','setContract','getRentRecord','tricycle','multipleRent','singleRent']; /* *获取平台公司接口 @@ -25,7 +25,7 @@ class VehicleController extends BaseApiController } } - public function setContract() { + public function setContract():Json { $params = $this->request->post(['party_a','party_b','num','start_time','end_time']); //验证参数 if(empty($params['party_a']) || empty($params['party_b']) || empty($params['num']) || empty($params['start_time']) || empty($params['end_time'])){ @@ -45,6 +45,22 @@ class VehicleController extends BaseApiController } } + public function getRentRecord():Json { + //获取参数 + $params = $this -> request -> get('contract_id'); + if(empty($params)){ + return $this->fail('确实必要参数'); + } + //获取数据 + $result = VehicleLogic::recordInfo($params); + //返回数据 + if($result['code'] == 1){ + return $this->success($result['msg'],$result['data']); + }else{ + return $this->fail($result['msg']); + } + } + /* * 获取去未出租的三轮车列表 */ diff --git a/app/api/logic/VehicleLogic.php b/app/api/logic/VehicleLogic.php index b55258e8..3f7c9ab2 100644 --- a/app/api/logic/VehicleLogic.php +++ b/app/api/logic/VehicleLogic.php @@ -170,8 +170,9 @@ class VehicleLogic extends BaseLogic 'contract_id' => $setContract['data']['id'], 'party_a' => $params['party_a'], 'party_b' => $params['party_b'], - 'start_time' => $params['start_time'], - 'end_time' => $params['end_time'], + 'num' => $params['num'], + 'start_time' => strtotime($params['start_time']), + 'end_time' => strtotime($params['end_time']), 'status' => 1, 'create_time' => time(), 'update_time' => time(), @@ -183,4 +184,23 @@ class VehicleLogic extends BaseLogic return ['code'=>0,'msg'=>$e->getMessage()]; } } + + public static function recordInfo($contract_id) { + $record = VehicleRentRecord::field('car_ids,num,start_time,end_time')->where('contract_id',$contract_id)->find(); + if(!$record){ + return ['code'=>0,'msg'=>'数据不存在']; + } + $cars = Vehicle::field('license')->where('id','in',$record['car_ids'])->select(); + if(!$cars){ + return ['code'=>0,'msg'=>'车辆不存在']; + } + $car_license = array_column($cars->toArray(),'license'); + $data = [ + 'num' => $record['num'], + 'start_time' => $record['start_time'], + 'end_time' => $record['end_time'], + 'car_license' => $car_license + ]; + return ['code'=>1,'msg'=>'请求成功','data'=>$data]; + } } diff --git a/app/api/route/app.php b/app/api/route/app.php index 058b085f..2011c5ec 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -33,5 +33,8 @@ Route::rule('getCarHistory','Gps/getCarHistory','get'); /*-------------------------------------------------------------------------------------------*/ Route::rule('getCompany','Vehicle/getCompany','get'); Route::rule('setContract','Vehicle/setContract','post'); +Route::rule('getRentRecord','Vehicle/getRentRecord','get'); + + Route::rule('multipleRent','Vehicle/multipleRent','post'); Route::rule('singleRent','Vehicle/singleRent','post'); \ No newline at end of file