/**
  * 添加租户
  */
 public function add()
 {
     $m = D("Department");
     $model = M("Department");
     if ($m->create()) {
         $data['dep_tnt_id'] = $_SESSION["tnt_id"];
         $data['dep_pid'] = $_POST['dep_pid'];
         $data['dep_isleaf'] = 1;
         $data['dep_note'] = $_POST['dep_note'];
         $data['dep_name'] = $_POST['dep_name'];
         $id = $m->add($data);
         $data['dep_id'] = $id;
         $res = removePre($data, "dep_");
         if ($id) {
             $dt['dep_id'] = $_POST['dep_pid'];
             $dt['dep_isleaf'] = 0;
             $m->save($dt);
             $this->returnAjax(true, "增加机构成功!", $res);
         } else {
             $this->returnAjax(false, "添加失败!");
         }
     } else {
         $this->returnAjax(false, "增加机构失败,原因:[" . $m->getError() . "]");
     }
 }
Ejemplo n.º 2
0
/**
 * 移除数组中字段名称的前缀
 * @param string $array_data 数据数组
 * @param string $pre 要去掉前缀
 * @return string|multitype:unknown
 */
function removePre($array_data, $pre)
{
    if (empty($pre) || empty($array_data)) {
        return $array_data;
    }
    $res = array();
    $len = strlen($pre);
    foreach ($array_data as $key => $value) {
        if (is_numeric($key)) {
            $res[$key] = removePre($value, $pre);
        } else {
            $key = substr($key, $len);
            $res[$key] = $value;
        }
    }
    return $res;
}
 /**
  * 获取所有租户数据
  */
 public function getTenants()
 {
     $m = M("Tenant");
     $fields = array("tnt_username", "tnt_id", "tnt_password", "tnt_tel", "tnt_regtime", "tnt_lasttime", "tnt_note", "tnt_isrun", "tnt_max_persons");
     //判断是否有关键字、若有则进行关键字查询
     if (!empty($_POST['keywords'])) {
         $where['tnt_username'] = array('like', '%' . $_POST['keywords'] . '%');
         $res = $m->field($field)->where($where)->select();
     } else {
         $res = $m->field($field)->select();
     }
     if (!$res) {
         $this->returnAjax(false);
     }
     //去掉前缀,主要为了防止Sql注入漏洞的发生
     $r = removePre($res, "tnt_");
     $this->ajaxReturn($r);
 }
 /**
  * 更新租户信息
  */
 public function update()
 {
     if (empty($_POST['per_id'])) {
         $this->returnAjax(false);
     }
     $res = removePre($_POST, "per_");
     $m = D("Person");
     if ($m->create()) {
         $id = $m->save();
         // $_POST['id'] = $id;
         $id ? $this->returnAjax(true, "修改成员信息成功!", $_POST) : $this->returnAjax(false, "修改成员信息失败!" . $m->getError(), $res);
     } else {
         $this->returnAjax(false, "修改成员信息失败,原因:[" . $m->getError() . "]", $res);
     }
 }
 public function listdep()
 {
     $m = M("Department");
     $res = $m->order("dep_id")->select();
     $mng_id = $_GET['mng_id'];
     $v = "";
     $this->assign("mng_id", $mng_id);
     $mng = M("Manager");
     $w['mng_id'] = $_GET['mng_id'];
     $r = $mng->field("mng_deplist")->where($w)->select();
     if (!empty($r)) {
         $arr = split(",", $r[0]["mng_deplist"]);
         $v .= $this->prn($this->tree(removePre($res, "dep_"), 0), $arr);
     } else {
         $v .= $this->prn($this->tree(removePre($res, "dep_"), 0), array());
     }
     //	print_r($arr);
     $this->assign("listdep", $v);
     $this->display("Index/listdep");
 }
 public function listdep()
 {
     session("code2", array());
     $m = M("Department");
     $res = $m->select();
     $mng_id = $_GET['mng_id'];
     $v = "";
     $this->assign("mng_id", $mng_id);
     $mng = M("Manager");
     $w['mng_id'] = $_GET['mng_id'];
     $r = $mng->field("mng_deplist")->where($w)->select();
     if (!empty($r)) {
         $arr = split(",", $r[0]["mng_deplist"]);
         $v .= $this->prn($this->tree(removePre($res, "dep_"), 0), $arr);
     } else {
         $v .= $this->prn($this->tree(removePre($res, "dep_"), 0), array());
     }
     $v = $this->tree3($arr);
     //	print_r($this->tree3($arr));exit(0);
     //	print_r($arr);
     //二维码
     vendor('phpqrcode.phpqrcode');
     $pic_code = "Public/Code2/code.jpg";
     $uuid = md5(\Org\Util\String::uuid()) . session_id();
     \QRcode::png($uuid, $pic_code, 'M', 16);
     session("sgn_code2", $uuid);
     //		print_r(session("code2"));exit(0);
     $this->assign("pic_code", $pic_code);
     $this->assign("listdep", $v);
     $this->display("Index/signcode");
 }