input('search', "")); $start = $end = null; $fieldSearchable = $this->repository->getFieldsSearchable(); foreach ($search as $value) { if (!empty($value)) { list($one, $tow) = explode(":", $value); if (!empty($fieldSearchable[$one])) { if ($fieldSearchable[$one] == 'like') $tow = "%{$tow}%"; $where[] = [$one, $fieldSearchable[$one], $tow]; } elseif ($one == 'start') { $start = $tow . " 00:00:00"; } elseif ($one == 'end') { $end = $tow . " 23:59:59"; } else { continue; } } } return function ($query) use ($where, $start, $end) { if ($start) $where[] = ['created_at', '>=', $start]; if ($end) $where[] = ['created_at', '<=', $end]; if ($where) { $query->where($where); } }; } protected function _indexJoin() { return MenuUrl::from('menu_urls as u')->leftJoin('menus as m', 'u.menu_id', '=', 'm.id'); } protected function _indexSelect() { return ['u.url_name', 'u.id', 'u.url', 'u.created_at', 'u.updated_at', 'm.menu_name']; } /** * 修改数据组建 * @param $id * @return array */ function _editGet($id) { $model = $this->repository->find($id); $option = [ [ 'value' => '0', 'label' => "请选择菜单", 'disabled' => false, 'notice' => '*' ] ]; $menu_list = Menu::where('p_id', 0)->select(['id', 'menu_name'])->get(); foreach ($menu_list as $menu) { $option[] = [ 'value' => $menu->{'id'}, 'label' => $menu->{'menu_name'}, 'disabled' => false, 'notice' => '*' ]; } return ['model' => $model, 'one_list' => json_encode($option, JSON_UNESCAPED_SLASHES)]; } /** * 更新路由菜单信息 * @return bool * @throws \Exception */ function _updatePost() { $data = request()->input(); if (empty($data['url_name'])) { $this->errorMsg = '请输入地址名称'; return false; } if (empty($data['child_id'])) { $this->errorMsg = '请选择对应菜单'; return false; } DB::beginTransaction(); //删除二级信息 $this->delAuth($data['id'],'1'); //删除三级信息 $this->delAuth($data['id'],'2'); //添加二级信息 $this->addAuth($data['menu_id'],$data['id']); //添加三级信息 $this->addAuth($data['child_id'],$data['id']); MenuUrl::where('id', $data['id'])->update($data); DB::commit(); return true; } /** * 删除授权ID * @param $del_id * @param string $type */ private function delAuth($del_id,$type='1'){ $old_menu_id = MenuUrl::where('id', $del_id)->value($type=='1'?'menu_id':'child_id'); if (!empty($old_menu_id)) { $old_url_ids = Menu::where('id', $old_menu_id)->value('url_ids'); $old_url_ids = explode(',', $old_url_ids); $old_url_ids = array_diff($old_url_ids, [$del_id]); Menu::where('id', $old_menu_id)->update(['url_ids' => implode(',', $old_url_ids)]); } } /** * 添加授权ID * @param $menu_id * @param $add_id */ private function addAuth($menu_id,$add_id){ $menu_url_ids = Menu::where('id', $menu_id)->value('url_ids'); $menu_url_ids = explode(',', $menu_url_ids); $menu_url_ids[] = $add_id; Menu::where('id', $menu_id)->update(['url_ids' => implode(',', $menu_url_ids)]); } }