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 addSelfCar() { //获取参数 $params = $this->request->post(['license','pic','company_id','company_name','company_user','company_phone']); if(empty($params['license']) || empty($params['pic']) || empty($params['company_id']) || empty($params['company_name']) || empty($params['company_user']) || empty($params['company_phone'])){ return $this->fail('缺少必要参数'); } Db::startTrans(); try { //获取数据 $vehicle = Vehicle::where('license',$params['license'])->find(); if(!empty($vehicle)){ return $this->fail('该车牌号的车辆已存在'); } //写入数据 $vehicle = Vehicle::create([ 'license' => $params['license'], 'pic' => $params['pic'], 'gps_imei' => '', 'type' => 1, 'status' => 2, 'create_time' => time(), 'update_time' => time(), ]); $vehicleRent = VehicleRent::create([ 'car_id'=> $vehicle->id, 'contract_id' => 0, 'company_id' => $params['company_id'], 'company_name' => $params['company_name'], 'company_user' => $params['company_user'], 'company_phone' => $params['company_phone'], 'create_time' => time() ]); 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()); } } public function updateVehicleRent(){ //获取参数 $params = $this->request->post(['car_id','use_user_id','use_user_name','use_user_phone']); if(empty($params['car_id']) || empty($params['use_user_id']) || empty($params['use_user_name']) || empty($params['use_user_phone'])){ return $this->fail('参数错误'); } //更新 $vehicleRent = VehicleRent::where('car_id',$params['car_id'])->find(); if(empty($vehicleRent)){ return $this->fail('数据错误'); } $result = VehicleRent::where('car_id',$params['car_id'])->update([ 'use_user_id' => $params['use_user_id'], 'use_user_name' => $params['use_user_name'], 'use_user_phone' => $params['use_user_phone'], ]); if($result){ return $this->success('请求成功'); }else{ return $this->fail('失败'); } } public function cancelRent() { //获取参数 $params = $this->request->post(['car_id','status']); if(empty($params['car_id']) || empty($params['status'])){ return $this->fail('参数错误'); } //更新 $vehicleRent = VehicleRent::where('car_id',$params['car_id'])->find(); if(empty($vehicleRent)){ return $this->fail('数据错误'); } $result1 = VehicleRent::where('car_id',$params['car_id'])->update([ 'status' => $params['status'], ]); $result2 = Vehicle::where('id',$params['car_id'])->update([ 'status' => 3, ]); if($result1 && $result2){ return $this->success('请求成功'); }else{ return $this->fail('失败'); } } }