vehicleModel = $vehicleModel; } /** * 列表 * @time 2022年01月20日 10:42 * @param Request $request */ public function index(Request $request) : \think\Response { $field = $request->get('field')?:'id'; $order = $request->get('order')?:'desc'; return CatchResponse::paginate($this->vehicleModel->getVehicleList($field,$order)); } /** * 保存信息 * @time 2022年01月20日 10:42 * @param Request $request */ public function save(Request $request) : \think\Response { return CatchResponse::success($this->vehicleModel->storeBy($request->post())); } /** * 读取 * @time 2022年01月20日 10:42 * @param $id */ public function read($id) : \think\Response { $data = $this->vehicleModel->findBy($id)->toArray(); $data['department_id'] = (new Department())->where('id',$data['department_id'])->value('department_name'); $data['brand_id'] = (new VehicleBrand())->where('id',$data['brand_id'])->value('name'); $data['color_id'] = (new VehicleColor())->where('id',$data['color_id'])->value('name'); // 被盗情况 $stolen_info = (new StolenVehicle())->where('vehicle_id', $id)->find(); if (!$stolen_info || in_array($stolen_info['result'], [2, 4])) { //0-待处理 1-已受理 2-已找回 3-已理赔 4-误报 $data['status'] = '正常'; } else { $data['status'] = '被盗'; } //车主信息 $data['chezhu'] = (new Users())->where('id',$data['user_id'])->field('realname,phone,idcard')->find(); //身份证隐藏中间8位 $data['chezhu']['idcard'] = $data['chezhu']['idcard']?substr($data['chezhu']['idcard'],0,6)."****".substr($data['chezhu']['idcard'],14,4):''; //车辆照片 $data['photos'] = (new VehiclePhoto())->where('vehicle_id',$id)->field('url,type')->select(); //车辆标签 $data['labels'] = (new Device())->where('bind_id',$id)->field('imei,rfid,online_time')->select(); // var_dump($data); return CatchResponse::success($data); } /** * 更新 * @time 2022年01月20日 10:42 * @param Request $request * @param $id */ public function update(Request $request, $id) : \think\Response { return CatchResponse::success($this->vehicleModel->updateBy($id, $request->post())); } /** * 删除 * @time 2022年01月20日 10:42 * @param $id */ public function delete($id) : \think\Response { return CatchResponse::success($this->vehicleModel->deleteBy($id)); } /** * 导出 * * @time 2022年01月22日 * @param Excel $excel * @param VehicleExport $vehicleExport * @throws \PhpOffice\PhpSpreadsheet\Exception * @return \think\response\Json */ public function export_vehicle(Excel $excel, VehiclesExport $VehicleExport) { // var_dump(Utils::publicPath('export/users'));//导出路径 return CatchResponse::success($excel->save($VehicleExport, Utils::publicPath('export/vehicles'), 'local', '车辆列表')); } }