123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace app\manage\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- /**
- *
- */
- class Constant extends Base {
- public function index() {
- // 查询出全部的机构,显示上级机构使用
- $rs = Db::table("constant")->select();
- $this->assign("constants", $rs);
- return $this->fetch('index');
- }
- /**
- * 列表数据
- */
- public function datas() {
- $parent_id = "";
- if (!empty($_GET["parent_id"])) {
- $parent_id = $_GET["parent_id"];
- }
- $rs = self::itsChild($parent_id);
- echo json_encode($rs);
- }
- public function itsChild($pid) {
- $rs = Db::table("constant")->where("parent_id", $pid)->order("ordernum", "1")->select();
- foreach ($rs as $key => $val) {
- $rs[$key]["text"] = $val["name"];
- $rs[$key]["children"] = self::itsChild($val["id"]);
- }
- return $rs;
- }
- /**
- * 更新或创建机构信息
- */
- public function save() {
- $request = Request::instance();
- $params = $request->param();
- $id = $params["id"];
- $data = array();
- $data["name"] = $params["name"];
- $data["parent_id"] = $params["parent_id"];
- $data["constant_key"] = $params["constant_key"];
- $data["constant_value"] = $params["constant_value"];
- $data["remark"] = $params["remark"];
- $data["sign"] = isset($params["sign"]) ? $params["sign"] : "0";
- $data["ordernum"] = isset($params["ordernum"]) ? $params["ordernum"] : "0";
- // ID有值,认为是更新
- if (empty($id)) {
- // 如果是新创建,且是父节点时,id = key
- // 无值,认为是添加
- if ($data["sign"] == "1") {
- // 父节点,ID = key
- $data["id"] = $data["constant_key"];
- } else {
- // 非父节点,ID自动生成
- $data["id"] = UUIDs::uuid16();
- }
- Db::table("constant")->insert($data);
- echo "insert_ok;" . $data["id"];
- SysLogs::log("constant", "C", json_encode($data));
- } else {
- // 更新
- Db::table("constant")->where("id", $id)->update($data);
- echo "update_ok";
- SysLogs::log("constant", "C", $id . " --> " . json_encode($data));
- }
- }
- /**
- * 编辑窗口
- * @return type
- */
- public function edit() {
- // 查询出全部的机构,显示上级机构使用
- $rs = self::itsCombChild("");
- $this->assign("insJson", json_encode($rs));
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- if ($id != null) {
- $constants = Db::table("constant")->where("id", $id)->select();
- if (count($constants) > 0) {
- $this->assign("constant", $constants[0]);
- }
- }
- }
- return $this->fetch('edit');
- }
- public function combs() {
- $rs = self::itsCombChild("");
- echo json_encode($rs);
- }
- public function itsCombChild($pid) {
- $retArr = Array();
- $whereArr = Array();
- $whereArr["parent_id"] = $pid;
- $whereArr["sign"] = "1";
- $rs = Db::table("constant")->where($whereArr)->order("ordernum", "1")->select();
- foreach ($rs as $key => $val) {
- $rs[$key]["text"] = $val["name"];
- $childrens = self::itsCombChild($val["id"]);
- $rs[$key]["children"] = $childrens;
- array_push($retArr, $rs[$key]);
- }
- return $retArr;
- }
- /**
- * 删除记录
- */
- public function delete() {
- $params = Request::instance()->param();
- if (isset($params["ids"])) {
- $ids = $params["ids"];
- if (!empty($ids)) {
- $idArr = explode(",", $ids);
- if (count($idArr) > 0) {
- Db::table("constant")->where("id", "in", $idArr)->delete();
- SysLogs::log("constant", "D", "ids --> " . json_encode($idArr));
- }
- echo "delete_ok";
- return;
- }
- }
- echo "fail";
- }
- }
|