adminModel = new AdminList(); $this->model = new DepartmentModel(); $this->uid = get_login_admin('id'); } public function datalist() { if (request()->isAjax()) { // 获取单位名称 $session_admin = get_config('app.session_admin'); $unit_name = Session::get($session_admin)['unit_name']; // halt($unit_name); $param = get_params(); if (!empty($param['keywords'])) { $where[] = ['id|username|nickname|desc|mobile', 'like', '%' . $param['keywords'] . '%']; } $where = [ ["delete_time","=",0], ["pid","=",0], ["type","=",1] ]; $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $order = empty($param['order']) ? 'id desc' : $param['order']; $list = $this->model->where($where)->field('id,title,leader_id,phone,landline,address,company_type,authorization_module') ->order($order)->paginate($rows, false, ['query' => $param]) ->each(function ($item){ $item->leader = Db::name("admin")->where("id",$item->leader_id)->value("nickname"); $item->username = Db::name("admin")->where("id",$item->leader_id)->value("username"); }); // halt($admin); return table_assign(0, '', $list); } else { return view(); } } public function add() { if (request()->isAjax()) { $param = get_params(); // 检验完整性 // try { // validate(FinancialValidate::class)->check($param); // } catch (ValidateException $e) { // // 验证失败 输出错误信息 // return to_assign(1, $e->getError()); // } $param = array_merge($param,['type'=>1]); $insertId = 0; try { $param['create_time'] = time(); $insertId = $this->model->strict(false)->field(true)->insertGetId($param); add_log('add', $insertId, $param); } catch(\Exception $e) { return to_assign(1, '操作失败,原因:'.$e->getMessage()); } return to_assign(0,'操作成功',['aid'=>$insertId]); // halt($param); }else{ return view(); } } /** * 编辑 */ public function edit() { $param = get_params(); // halt($param); if (request()->isAjax()) { // 检验完整性 try { validate(FinancialValidate::class)->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } try { $param['update_time'] = time(); $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param); add_log('edit', $param['id'], $param); } catch(\Exception $e) { return to_assign(1, '操作失败,原因:'.$e->getMessage()); } return to_assign(); }else{ $id = isset($param['id']) ? $param['id'] : 0; $detail = $this->model->where('id', $id)->find(); // halt($id); if (!empty($detail)) { View::assign('detail', $detail); return view(); } else{ throw new \think\exception\HttpException(404, '找不到页面'); } } } /** * 查看信息 */ public function read() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $detail = $this->model->where('id', $id)->find(); if (!empty($detail)) { View::assign('detail', $detail); return view(); } else{ throw new \think\exception\HttpException(404, '找不到页面'); } } /** * 删除 * type=0,逻辑删除,默认 * type=1,物理删除 */ public function del() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $type = isset($param['type']) ? $param['type'] : 0; if($type==0){ //逻辑删除 try { $param['delete_time'] = time(); $this->model->where('id', $id)->update(['delete_time'=>time()]); add_log('delete', $id); } catch(\Exception $e) { return to_assign(1, '操作失败,原因:'.$e->getMessage()); } } else{ //物理删除 try { $this->model->where('id', $id)->delete(); add_log('delete', $id); } catch(\Exception $e) { return to_assign(1, '操作失败,原因:'.$e->getMessage()); } } return to_assign(); } }