dataRange() ->catchSearch() ->append(['depart_name', 'vehicle_state', 'owner', 'brand_name', 'color_name', 'open_user_name']) ->order($this->aliasField($field), $order) ->paginate(); return $res; } /** * 获取车辆导出列表 */ public function getVehiclesExportList() { $res = $this->dataRange() ->catchSearch() ->append(['depart_name', 'vehicle_state', 'owner', 'brand_name', 'color_name', 'open_user_name']) ->order($this->aliasField('id'), 'desc') ->select(); return $res; } //根据部门搜索 public function searchDepartmentIdAttr($query, $value, $data) { if (count($value)) { $value = $value[count($value) - 1]; return $query->where('department_id', $value); } else { return $query; } } //根据车牌搜索 public function searchLicensePlateAttr($query, $value, $data) { return $query->where('license_plate', 'like', '%' . $value . '%'); } //根据车架号搜索 public function searchFrameNumberAttr($query, $value, $data) { return $query->where('frame_number', 'like', '%' . $value . '%'); } //根据电机号搜索 public function searchMotorNumberAttr($query, $value, $data) { return $query->where('motor_number', 'like', '%' . $value . '%'); } //根据上牌时间搜索 public function searchLicenseTimeAttr($query, $value, $data) { if (empty($value)) { return $query; } return $query->where('license_time', 'between', $value); } //获取部门名称 public function getDepartNameAttr($value) { $depart_id = $this->getData('department_id'); return (new Department)->where('id', $depart_id)->value('department_name'); } //获取车主名称 public function getOwnerAttr($value) { $uid = $this->getData('user_id'); return (new Users)->where('id', $uid)->value('realname'); } //获取开户员工账号 public function getOpenUserNameAttr($value) { $uid = $this->getData('open_user_id'); return (new Users)->where('id', $uid)->value('username'); } //获取车辆品牌名称 public function getBrandNameAttr($value) { $bid = $this->getData('brand_id'); return (new VehicleBrand())->where('id', $bid)->value('name'); } //获取车辆颜色名称 public function getColorNameAttr($value) { $cid = $this->getData('color_id'); return (new VehicleColor())->where('id', $cid)->value('name'); } //获取车辆状态名称 public function getVehicleStateAttr($value) { $id = $this->getData('id'); $stolen_info = (new StolenVehicle())->where('vehicle_id', $id)->find(); if (!$stolen_info || in_array($stolen_info['result'], [2, 4])) { //0-待处理 1-已受理 2-已找回 3-已理赔 4-误报 $value = 0; } else { $value = 1; } return $value; } }