123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- use think\facade\Validate;
- class Newfill extends Base
- {
- public function list()
- {
- $post = $this->request->only(['pid' => '', 'name' => '', 'nickname' => '', 'companyNo' => ''], 'post', 'trim');
- $userCommon = new \app\admin\common\User();
- $rs = $userCommon->handle('ulist',$post);
- return json_show($rs['code'], $rs['message'],$rs['data']);
- }
-
- public function stat()
- {
- $id = $this->request->post('id/d', 0, 'trim');
- if ($id == 0) return json_show(1004, "参数id 不能为空");
- $s = Db::name('company_item')
- ->field('id,status')
- ->where('id', $id)
- ->findOrEmpty();
- if (empty($s)) return json_show(1005, "未找到部门");
- $var = $s['status'];
- $di = $s['status'] == 0 ? 1 : 0;
- $s['status'] = $di;
- $s['updatetime'] = date("Y-m-d H:i:s");
-
- $rs = Db::name('company_item')->where('id', $id)->save($s);
- if ($rs) {
- $orde = ["order_code" => $s['name'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", $s['status'], $orde);
- return json_show(0, "更新成功");
- } else return json_show(1005, '更新失败');
- }
-
- public function userp()
- {
- $id = isset($this->post['id']) ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1004, "参数id不能为空");
- }
- $t = Db::name('depart_user')->where(["id" => $id, "is_del" => 0])->find();
- if (empty($t)) {
- return error_show(1005, "未找到用户");
- }
- $position = isset($this->post['position']) ? intval($this->post['position']) : "";
- if ($position == "") {
- return error_show(1004, "职位不能为空");
- }
- Db::startTrans();
- if ($position == 2) {
- $f = Db::name('depart_user')->where(['itemid' => $t['itemid'], "is_del" => 0, "position" => 2])->find();
- if (!empty($f) && $f['id'] != $id) {
- $f['position'] = 1;
- $f['updatetime'] = date("Y-m-d H:i:s");
- $m = Db::name('depart_user')->save($f);
- $orde = ["order_code" => $t['nickname'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd($this->post['token'], $orde, "depart_user", 0, $orde);
- if ($m == false) {
- Db::rollback();
- return error_show(1004, "负责人修改失败");
- }
- }
- }
- $t['position'] = $position;
- $t['updatetime'] = date("Y-m-d H:i:s");
-
- $ti = Db::name('depart_user')->save($t);
- if ($ti == true) {
- Db::commit();
- return app_show(0, "修改成功");
- } else {
- Db::rollback();
- return error_show(1004, "修改失败");
- }
- }
- public function add()
- {
- $param = $this->request->filter('trim')->post();
- $userCommon = new \app\admin\common\User();
- $rs = $userCommon->handle('add',$param);
- return json_show($rs['code'],$rs['message'],$rs['data']);
- }
- public function refresh()
- {
- $id = isset($this->post['id']) ? intval($this->post['id']) : "";
- $items = Db::name("company_item")->where(['id' => $id, 'is_del' => 0])->find();
- if ($items == false) {
- return error_show(1003, "部门信息不存在");
- }
- $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
- if ($pid == "") {
- return error_show(1002, "父级id不能为空");
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo == "") return error_show(1002, "所属企业不能为空");
- $spid = ['depart_link' => ""];
- if ($pid != 0) {
- $spid = Db::name('company_item')->where(['id' => $pid, 'is_del' => 0])->find();
- if (empty($spid)) {
- return error_show(1004, "父级数据不能为空");
- }
- }
- $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
- $itemname = isset($this->post['name']) ? trim($this->post['name']) : "";
- if ($itemname == "") {
- return error_show(1002, "部门名称不能为空");
- }
- $repeat_name = Db::name("company_item")->where(["is_del" => 0, "name" => $itemname, 'companyNo' => $companyNo])->where('id', '<>', $id)->find();
-
- if (!empty($repeat_name)) {
- return error_show(1004, "部门名称已存在");
- }
- $depart_link = $spid['depart_link'] . "{$id}-";
- $itemlevel = explode('-', $depart_link);
- $itemlevel = array_filter($itemlevel);
- $itemlevel = count($itemlevel);
- $item = [
- "id" => $id,
- "name" => $itemname,
- "updatetime" => date("Y-m-d H:i:s"),
- "weight" => $weight, "pid" => $pid,
- 'depart_link' => $depart_link,
- 'level' => $itemlevel,
- 'companyNo' => $companyNo
- ];
- $re = Db::name("company_item")->save($item);
- $stn = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
- return $re ? app_show(0, "信息更新成功") : error_show(1003, "信息更新失败");
- }
-
- public function query()
- {
- $userCommon = new \app\admin\common\User();
- $rs = $userCommon->handle('query');
- return json_show($rs['code'], $rs['message'],$rs['data']);
- $k = [];
-
-
-
-
- }
- public function itemdel()
- {
- $id = isset($this->post['id']) ? intval($this->post['id']) : "";
- $items = Db::name("company_item")
- ->field('id,is_del,updatetime')
- ->where(['is_del' => 0, 'id' => $id])
- ->findOrEmpty();
- if (empty($items)) {
- return error_show(1003, "部门信息不存在");
- }
- $items['is_del'] = 1;
- $items['updatetime'] = date("Y-m-d H:i:s");
- $result = Db::name("company_item")->save($items);
- $stn = ["order_code" => $items['name'], "status" => 0, "action_remark" => '', "action_type" => "delete"];
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
- return $result ? app_show(0, "删除成功") : error_show(1003, "删除失败");
- }
- }
|