request->post(['num']); //验证参数 if(empty($params['num'])){ return $this->fail('缺少必要参数'); } if(empty($this->userInfo['company_id'])){ return $this->fail('签约公司不存在'); } $params['party_b'] = $this->userInfo['company_id']; $result = VehicleLogic::initiate_contract($params); //返回数据 if($result && $result['code'] == 1){ return $this->success($result['msg']); }else{ return $this->fail($result['msg']); } } //小组服务公司租赁申请 public function rentApply() { if(!$this->request->isPost()){ return $this->fail('请求类型错误'); } //获取参数 $params = $this->request->post('license'); //获取当前公司信息 $village_company = Company::field('id,company_name,master_name,master_phone,is_contract,company_type')->where('id',$this->userInfo['company_id'])->find(); if($village_company->isEmpty() || $village_company['company_type'] != 18){ return $this->fail('非小组服务公司不能申请'); } if($village_company['is_contract'] != 1){ return $this->fail('当前小组服务公司未签约'); } //获取签约信息 $contract = Contract::field('party_a')->where('party_b',$this->userInfo['company_id'])->where('signing_timer',2)->find(); if($contract->isEmpty()){ return $this->fail('未找到签约镇街公司'); } //判断是否申请过 $apply = VehicleVillageApply::where('village_company_id',$this->userInfo['company_id'])->where('status','<>',2)->find(); if(!$apply->isEmpty()){ return $this->fail('已申请了,请勿重复申请'); } //设置数据 $result = VehicleVillageApply::create([ 'town_company_id' => $contract['party_a'], 'village_company_id' => $village_company['id'], 'village_company_name' => $village_company['company_name'], 'village_company_user' => $village_company['master_phone'], 'village_company_phone' => $village_company['id'], 'car_license' => !empty($params) ? $params : '', 'type' => !empty($params) ? 1 : 0, 'status' => 0, 'create_time' => time(), 'update_time' => time(), ]); if($result && $result->id){ return $this->success('申请成功'); }else{ return $this->fail('申请失败'); } } //镇街公司驳回小组服务公司的租赁申请 public function rejectRentApply() { //获取参数 $params = $this->request->post(['apply_id','content']); if(empty($params['apply_id']) || empty($params['content'])){ return $this->fail('缺少必要参数'); } //获取数据 $apply = VehicleVillageApply::where('id',$params['apply_id'])->where('status',0)->find(); if($apply->isEmpty()){ return $this->fail('数据错误'); } if($apply['town_company_id'] != $this->userInfo['company_id']){ return $this->fail('镇街公司信息错误'); } //更新 $apply -> status = 2; $apply -> notice = $params['content']; $apply -> update_time = time(); $result = $apply->save(); if($result){ return $this->success('驳回成功'); }else{ return $this->fail('驳回失败'); } } //镇街公司收到的小组服务公司租赁申请列表 public function rentApplyList() { $data = VehicleVillageApply::where('town_company_id',$this->userInfo['company_id'])->where('status',0)->select(); return $this->success('请求成功',$data->toArray()); } //小组服务公司租赁申请详情 public function rentApplyInfo() { //获取参数 $id = $this->request->get('id'); if(empty($id)){ return $this->fail('缺少必要参数'); } $this->userInfo['company_id'] = 177; //获取数据 $data = VehicleVillageApply::where('id',$id)->find(); if($data->isEmpty() || $data['town_company_id'] != $this->userInfo['company_id'] || $data['status'] != 0){ return $this->fail('获取数据失败'); } //获取镇街公司可租赁车辆列表 $cars = VehicleRent::field('id,car_license')->where('company_id',$this->userInfo['company_id'])->where('status',0)->where('type',0)->select(); return $this->success('请求成功',[ 'apply' => $data->toArray(), 'cars' => $cars->toArray() ]); } public function vehicleIndex() { //获取参数 $params = $this->request->get(); $company_id = $this->userInfo['company_id']; if(empty($company_id)){ return $this->fail('公司信息不存在'); } $pageNo = $params['page_no'] ?? 1; $pageSize = $params['page_size'] ?? 15; //获取签约信息 $contract = VehicleContract::where('company_a_id',$company_id)->limit(2)->select(); //获取车辆列表 $cars = VehicleRent::where('company_id',$company_id)->page($pageNo,$pageSize)->select()->each(function($item){ $item['mileage'] = 0; if($item['status'] == 2){ $company = Company::where('id',$item['rent_company_id'])->find()->append(['province_name', 'city_name', 'area_name', 'street_name', 'village_name','brigade_name']); $item['rent_company'] = $company->toArray(); } }); //设置数据 $data = [ 'contract' => $contract->toArray(), 'carlist' => $cars->toArray(), 'total' =>6, 'rent_num' => 3, 'self_num' =>3, ]; //返回 return $this->success('请求成功',$data); } public function vehicleInfo() { //获取参数 $carId = $this->request->get('car_id'); if(empty($carId)){ return $this->fail('缺少必要参数'); } //获取数据 $data = VehicleRent::where('car_id',$carId)->find(); $data['mileage'] = 0; if($data['status'] == 2){ $data['company'] = Company::where('id',$data['rent_company_id'])->find()->append(['province_name', 'city_name', 'area_name', 'street_name', 'village_name','brigade_name']); } return $this->success('请求成功',$data->toArray()); } public function contractList() { $company_id = $this->userInfo['company_id']; if(empty($company_id)){ return $this->fail('公司信息不存在'); } $lists = VehicleContract::where('company_a_id',$company_id)->select(); $cars = VehicleRent::where('status',1)->select(); return $this->success('请求成功',[ 'contract' => $lists->toArray(), 'car' => $cars->toArray() ]); } }