request->get(['car_id']); if(empty($params['car_id'])){ return $this->fail('缺少必要参数'); } $result = VehicleLogic::getCarLocal($params); //返回数据 if($result['code'] == 1){ return $this->success($result['msg'],$result['data']); }else{ return $this->fail($result['msg']); } } public function getCarHistory():Json { //获取参数 $params = $this->request->get(['car_id','start_time','end_time']); //验证参数 if(empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){ return $this->fail('缺少必要参数'); } //验证时间格式 if(!checkDateIsValid($params['start_time'],['Y-m-d H:i:s']) || !checkDateIsValid($params['end_time'],['Y-m-d H:i:s'])) { return $this->fail('日期格式错误'); } //获取数据 $result = VehicleLogic::getCarHistory($params); //返回数据 if($result['code'] == 1){ return $this->success($result['msg'],$result['data']); }else{ return $this->fail($result['msg']); } } public function createRentCarUser() { //获取参数 $params = $this->request->post(['company_id','car_id','user_id','user_name','user_phone']); if(empty($params['company_id']) || empty($params['car_id']) || empty($params['user_id']) || empty($params['user_name']) || empty($params['user_phone'])){ return $this->fail('缺少必要参数'); } $vehicleRent = VehicleRent::where('car_id',$params['car_id'])->where('company_id',$params['company_id'])->find(); $vehicleRent -> user_id = $params['user_id']; $vehicleRent -> user_name = $params['user_name']; $vehicleRent -> user_phone = $params['user_phone']; $result = $vehicleRent -> save(); return $result ? $this->success('sucess') : $this->fail('error'); } //添加自有车辆 public function addSelfCar() { //获取参数 $params = $this->request->post(['license','company_id','company_name','company_user','company_phone','user_id','user_name','user_phone']); if(empty($params['license']) || empty($params['user_id']) || empty($params['user_name']) || empty($params['user_phone'])){ return $this->fail('error'); } Db::startTrans(); try { //写入数据 $vehicle = Vehicle::create([ 'license' => $params['license'], 'gps_imei' => '', 'type' => 1, 'status' => 3, 'is_del' => 1, 'create_time' => time(), 'update_time' => time(), ]); $vehicleRent = VehicleRent::create([ 'car_id'=> $vehicle->id, 'company_id' => $params['company_id'], 'company_name' => $params['company_name'], 'company_user' => $params['company_user'], 'company_phone' => $params['company_phone'], 'use_user_id' => $params['user_id'], 'use_user_name' => $params['user_name'], 'use_user_phone' => $params['user_phone'], ]); if($vehicle->id && $vehicleRent->id){ Db::commit(); return $this->success('success',['car_id'=>$vehicle->id]); }else{ Db::rollback(); return $this->fail('error'); } }catch (\Exception $e) { Db::rollback(); return $this->fail($e->getMessage()); } } }