diff --git a/application/admin/controller/CfHotelInfo.php b/application/admin/controller/CfHotelInfo.php index 9285722..742851d 100644 --- a/application/admin/controller/CfHotelInfo.php +++ b/application/admin/controller/CfHotelInfo.php @@ -2,7 +2,11 @@ namespace app\admin\controller; +use app\admin\model\Area; use app\common\controller\Backend; +use think\Db; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 配置-酒店详情 @@ -35,6 +39,152 @@ class CfHotelInfo extends Backend * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ - + /** + * 查看 + */ + public function index() + { + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $list = $this->model + ->where($where) + ->order($sort, $order) + ->paginate($limit); + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } + + + /** + * 添加 + */ + public function add() + { + if ($this->request->isPost()) { + + $params = $this->request->post("row/a"); + if ($params) { + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException(true)->validate($validate); + } + $area=new Area(); + if ($params["area"]){ + $params["area_name"]=$area->where("id","=",$params["area"])->value("name"); + } + if ($params["province"]){ + $params["province_name"]=$area->where("id","=",$params["province"])->value("name"); + } + if ($params["city"]){ + $params["city_name"]=$area->where("id","=",$params["city"])->value("name"); + } + $params['create_id']=$this->auth->id; + $params['group_id']=$this->auth->getGroupId(); + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were inserted')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + return $this->view->fetch(); + } + + + /** + * 编辑 + */ + public function edit($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + if (!in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + } + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $params = $this->preExcludeFields($params); + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException(true)->validate($validate); + } + $area=new Area(); + if ($params["area"]){ + $params["area_name"]=$area->where("id","=",$params["area"])->value("name"); + } + if ($params["province"]){ + $params["province_name"]=$area->where("id","=",$params["province"])->value("name"); + } + if ($params["city"]){ + $params["city_name"]=$area->where("id","=",$params["city"])->value("name"); + } + $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were updated')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + $this->view->assign("row", $row); + return $this->view->fetch(); + } } diff --git a/application/admin/controller/example/Baidumap.php b/application/admin/controller/example/Baidumap.php new file mode 100644 index 0000000..c6f5ac5 --- /dev/null +++ b/application/admin/controller/example/Baidumap.php @@ -0,0 +1,39 @@ +model = model('AdminLog'); + } + + /** + * 查找地图 + */ + public function map() + { + return $this->view->fetch(); + } + + /** + * 搜索列表 + */ + public function selectpage() + { + $this->model = model('Area'); + return parent::selectpage(); + } +} diff --git a/application/admin/controller/example/Bootstraptable.php b/application/admin/controller/example/Bootstraptable.php new file mode 100644 index 0000000..9e1a9c6 --- /dev/null +++ b/application/admin/controller/example/Bootstraptable.php @@ -0,0 +1,131 @@ +model = model('AdminLog'); + } + + /** + * 查看 + */ + public function index() + { + if ($this->request->isAjax()) { + list($where, $sort, $order, $offset, $limit) = $this->buildparams(null); + $list = $this->model + ->where($where) + ->order($sort, $order) + ->limit($offset, $limit) + ->paginate($limit); + $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['money' => mt_rand(100000, 999999), 'price' => 200]); + + return json($result); + } + return $this->view->fetch(); + } + + /** + * 详情 + */ + public function detail($ids) + { + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + if ($this->request->isAjax()) { + $this->success("Ajax请求成功", null, ['id' => $ids]); + } + $this->view->assign("row", $row->toArray()); + return $this->view->fetch(); + } + + /** + * 启用 + */ + public function start($ids = '') + { + $this->success("模拟启动成功"); + } + + /** + * 暂停 + */ + public function pause($ids = '') + { + $this->success("模拟暂停成功"); + } + + /** + * 切换 + */ + public function change($ids = '') + { + //你需要在此做具体的操作逻辑 + + $this->success("模拟切换成功"); + } + + /** + * 联动搜索 + */ + public function cxselect() + { + $type = $this->request->get('type'); + $group_id = $this->request->get('group_id'); + $list = null; + if ($group_id !== '') { + if ($type == 'group') { + $groupIds = $this->auth->getChildrenGroupIds(true); + $list = \app\admin\model\AuthGroup::where('id', 'in', $groupIds)->field('id as value, name')->select(); + } else { + $adminIds = \app\admin\model\AuthGroupAccess::where('group_id', 'in', $group_id)->column('uid'); + $list = \app\admin\model\Admin::where('id', 'in', $adminIds)->field('id as value, username AS name')->select(); + } + } + $this->success('', null, $list); + } + + /** + * 搜索下拉列表 + */ + public function searchlist() + { + $result = $this->model->limit(10)->select(); + $searchlist = []; + foreach ($result as $key => $value) { + $searchlist[] = ['id' => $value['url'], 'name' => $value['url']]; + } + $data = ['searchlist' => $searchlist]; + $this->success('', null, $data); + } +} diff --git a/application/admin/controller/example/Colorbadge.php b/application/admin/controller/example/Colorbadge.php new file mode 100644 index 0000000..d828b55 --- /dev/null +++ b/application/admin/controller/example/Colorbadge.php @@ -0,0 +1,22 @@ +model = model('AdminLog'); + } +} diff --git a/application/admin/controller/example/Controllerjump.php b/application/admin/controller/example/Controllerjump.php new file mode 100644 index 0000000..01bd6d3 --- /dev/null +++ b/application/admin/controller/example/Controllerjump.php @@ -0,0 +1,22 @@ +model = model('AdminLog'); + } +} diff --git a/application/admin/controller/example/Customform.php b/application/admin/controller/example/Customform.php new file mode 100644 index 0000000..77546b8 --- /dev/null +++ b/application/admin/controller/example/Customform.php @@ -0,0 +1,30 @@ +model = model('AdminLog'); + } + + public function index() + { + if ($this->request->isPost()) { + $this->success("提交成功", null, ['data' => json_encode($this->request->post("row/a"), JSON_UNESCAPED_UNICODE)]); + } + return $this->view->fetch(); + } +} diff --git a/application/admin/controller/example/Customsearch.php b/application/admin/controller/example/Customsearch.php new file mode 100644 index 0000000..719656d --- /dev/null +++ b/application/admin/controller/example/Customsearch.php @@ -0,0 +1,24 @@ +model = model('AdminLog'); + $ipList = $this->model->whereTime('createtime', '-37 days')->group("ip")->column("ip,ip as aa"); + $this->view->assign("ipList", $ipList); + } +} diff --git a/application/admin/controller/example/Cxselect.php b/application/admin/controller/example/Cxselect.php new file mode 100644 index 0000000..70c882d --- /dev/null +++ b/application/admin/controller/example/Cxselect.php @@ -0,0 +1,21 @@ +model = model('AdminLog'); + } + + /** + * 查看 + */ + public function index() + { + + return $this->view->fetch(); + } + + /** + * 详情 + */ + public function detail($ids) + { + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + $this->view->assign("row", $row->toArray()); + return $this->view->fetch(); + } +} diff --git a/application/admin/controller/example/Multitable.php b/application/admin/controller/example/Multitable.php new file mode 100644 index 0000000..73edeb9 --- /dev/null +++ b/application/admin/controller/example/Multitable.php @@ -0,0 +1,90 @@ +loadlang('general/attachment'); + $this->loadlang('general/crontab'); + return $this->view->fetch(); + } + + public function table1() + { + $this->model = model('Attachment'); + //设置过滤方法 + $this->request->filter(['strip_tags']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $total = $this->model + ->where($where) + ->order($sort, $order) + ->count(); + + $list = $this->model + ->where($where) + ->order($sort, $order) + ->limit($offset, $limit) + ->select(); + + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch('index'); + } + + public function table2() + { + $this->model = model('AdminLog'); + //设置过滤方法 + $this->request->filter(['strip_tags']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $total = $this->model + ->where($where) + ->order($sort, $order) + ->count(); + + $list = $this->model + ->where($where) + ->order($sort, $order) + ->limit($offset, $limit) + ->select(); + + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch('index'); + } +} diff --git a/application/admin/controller/example/Relationmodel.php b/application/admin/controller/example/Relationmodel.php new file mode 100644 index 0000000..3342b94 --- /dev/null +++ b/application/admin/controller/example/Relationmodel.php @@ -0,0 +1,44 @@ +model = model('AdminLog'); + } + + /** + * 查看 + */ + public function index() + { + $this->relationSearch = true; + $this->searchFields = "admin.username,id"; + if ($this->request->isAjax()) { + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $list = $this->model + ->with("admin") + ->where($where) + ->order($sort, $order) + ->paginate($limit); + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } +} diff --git a/application/admin/controller/example/Tablelink.php b/application/admin/controller/example/Tablelink.php new file mode 100644 index 0000000..1590501 --- /dev/null +++ b/application/admin/controller/example/Tablelink.php @@ -0,0 +1,81 @@ +model = model('AdminLog'); + } + + + public function table1() + { + $this->model = model('Admin'); + //设置过滤方法 + $this->request->filter(['strip_tags']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $total = $this->model + ->where($where) + ->order($sort, $order) + ->count(); + + $list = $this->model + ->where($where) + ->order($sort, $order) + ->limit($offset, $limit) + ->select(); + + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch('index'); + } + + public function table2() + { + $this->model = model('AdminLog'); + //设置过滤方法 + $this->request->filter(['strip_tags']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $total = $this->model + ->where($where) + ->order($sort, $order) + ->count(); + + $list = $this->model + ->where($where) + ->order($sort, $order) + ->limit($offset, $limit) + ->select(); + + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch('index'); + } +} diff --git a/application/admin/controller/example/Tabletemplate.php b/application/admin/controller/example/Tabletemplate.php new file mode 100644 index 0000000..f51e4f9 --- /dev/null +++ b/application/admin/controller/example/Tabletemplate.php @@ -0,0 +1,58 @@ +model = model('AdminLog'); + } + + /** + * 查看 + */ + public function index() + { + if ($this->request->isAjax()) { + list($where, $sort, $order, $offset, $limit) = $this->buildparams(null); + $total = $this->model + ->where($where) + ->order($sort, $order) + ->count(); + $list = $this->model + ->where($where) + ->order($sort, $order) + ->limit($offset, $limit) + ->select(); + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch(); + } + + /** + * 详情 + */ + public function detail($ids) + { + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + $this->view->assign("row", $row->toArray()); + return $this->view->fetch(); + } +} diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index 4c68e23..e2d9c5b 100755 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -264,6 +264,23 @@ class Auth extends \fast\Auth } /** + * 重构接口,获取当前管理员部门 + * @param null $uid + * @return int + */ + public function getGroupId($uid = null) + { + $groups = $this->getGroups($uid); + foreach ($groups as $K => $v) { + if ($v["pid"]==1){ + //一级部门 + return (int)$v['group_id']; + } + } + return 0; + } + + /** * 取出当前管理员所拥有权限的分组 * @param boolean $withself 是否包含当前所在的分组 * @return array diff --git a/application/admin/model/Area.php b/application/admin/model/Area.php new file mode 100644 index 0000000..357d07e --- /dev/null +++ b/application/admin/model/Area.php @@ -0,0 +1,15 @@ + -