Newfill.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. use app\admin\model\ActionLog;
  7. use think\facade\Validate;
  8. //系统的组织架构
  9. class Newfill extends Base
  10. {
  11. public function list()
  12. {
  13. $post = $this->request->only(['pid' => '', 'name' => '', 'nickname' => '', 'companyNo' => ''], 'post', 'trim');
  14. // $depart = $condition = [['is_del', '=', 0]];
  15. // if ($post['pid'] !== '') $condition[] = ["pid", "=", $post['pid']];
  16. // if ($post['name'] != "") $condition[] = ["name", "like", "%{$post['name']}%"];
  17. // if ($post['nickname'] != '') {
  18. // $is = Db::name("depart_user")
  19. // ->where([['nickname', 'like', "%{$post['nickname']}%"]])
  20. // ->column('itemid');
  21. //
  22. // if (empty($is)) return json_show(1004, "未找到数据");
  23. //
  24. // $condition[] = ["id", "in", $is];
  25. // }
  26. // if ($post['pid'] === '' && $post['name'] == '' && $post['nickname'] == '') $condition[] = ["pid", "=", 0];
  27. //
  28. // $pidlist = Db::name("company_item")
  29. // ->where($condition)
  30. // ->column("pid");
  31. // if (!empty($pidlist)) $depart[] = [["itemid", "in", $pidlist]];
  32. // else {
  33. // if ($post['pid'] === "") $depart[] = ['itemid', '=', 0];
  34. // else $depart[] = ['itemid', '=', $post['pid']];
  35. // }
  36. //
  37. // $item = Db::name("depart_user")->where($depart)->select()->toArray();
  38. // $list = Db::name("company_item")->where($condition)->select()->toArray();
  39. $userCommon = new \app\admin\common\User();
  40. $rs = $userCommon->handle('ulist',$post);
  41. return json_show($rs['code'], $rs['message'],$rs['data']);//"获取成功", ["depart" => $list, "item" => $item]);
  42. }
  43. /*状态*/
  44. public function stat()
  45. {
  46. $id = $this->request->post('id/d', 0, 'trim');
  47. if ($id == 0) return json_show(1004, "参数id 不能为空");
  48. $s = Db::name('company_item')
  49. ->field('id,status')
  50. ->where('id', $id)
  51. ->findOrEmpty();
  52. if (empty($s)) return json_show(1005, "未找到部门");
  53. $var = $s['status'];
  54. $di = $s['status'] == 0 ? 1 : 0;
  55. $s['status'] = $di;
  56. $s['updatetime'] = date("Y-m-d H:i:s");
  57. // var_dump($s);
  58. $rs = Db::name('company_item')->where('id', $id)->save($s);
  59. if ($rs) {
  60. $orde = ["order_code" => $s['name'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
  61. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", $s['status'], $orde);
  62. return json_show(0, "更新成功");
  63. } else return json_show(1005, '更新失败');
  64. }
  65. /*职位*/
  66. public function userp()
  67. {
  68. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  69. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  70. if ($id == "") {
  71. return error_show(1004, "参数id不能为空");
  72. }
  73. $t = Db::name('depart_user')->where(["id" => $id, "is_del" => 0])->find();
  74. if (empty($t)) {
  75. return error_show(1005, "未找到用户");
  76. }
  77. $position = isset($this->post['position']) ? intval($this->post['position']) : "";
  78. if ($position == "") {
  79. return error_show(1004, "职位不能为空");
  80. }
  81. Db::startTrans();
  82. if ($position == 2) {
  83. $f = Db::name('depart_user')->where(['itemid' => $t['itemid'], "is_del" => 0, "position" => 2])->find();
  84. if (!empty($f) && $f['id'] != $id) {
  85. $f['position'] = 1;
  86. $f['updatetime'] = date("Y-m-d H:i:s");
  87. $m = Db::name('depart_user')->save($f);
  88. $orde = ["order_code" => $t['nickname'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  89. ActionLog::logAdd($this->post['token'], $orde, "depart_user", 0, $orde);
  90. if ($m == false) {
  91. Db::rollback();
  92. return error_show(1004, "负责人修改失败");
  93. }
  94. }
  95. }
  96. $t['position'] = $position;
  97. $t['updatetime'] = date("Y-m-d H:i:s");
  98. //var_dump($t);
  99. $ti = Db::name('depart_user')->save($t);
  100. if ($ti == true) {
  101. Db::commit();
  102. return app_show(0, "修改成功");
  103. } else {
  104. Db::rollback();
  105. return error_show(1004, "修改失败");
  106. }
  107. }
  108. public function add()
  109. {
  110. $param = $this->request->filter('trim')->post();
  111. $userCommon = new \app\admin\common\User();
  112. $rs = $userCommon->handle('add',$param);
  113. return json_show($rs['code'],$rs['message'],$rs['data']);
  114. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  115. // if ($companyNo == '') return json_show(1004, '所属企业不能为空');
  116. //
  117. // $item_name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  118. // if ($item_name == "") {
  119. // return error_show(0, "部门名称不能为空");
  120. // }
  121. // $repeat_name = Db::name("company_item")
  122. // ->where(["is_del" => 0, "name" => $item_name, 'companyNo' => $companyNo])
  123. // ->findOrEmpty();
  124. // if (!empty($repeat_name)) {
  125. // return error_show(1004, "部门名称已存在");
  126. // }
  127. // $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
  128. // if ($pid === "") {
  129. // return error_show(1002, "父级id不能为空");
  130. // }
  131. //
  132. // $spid = ['depart_link' => ""];
  133. // if ($pid != 0) {
  134. // $spid = Db::name('company_item')->where(['id' => $pid, 'is_del' => 0])->find();
  135. // if (empty($spid)) {
  136. // return error_show(1004, "父级数据不能为空");
  137. // }
  138. // }
  139. // $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
  140. // $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
  141. // Db::startTrans();
  142. // try {
  143. // $data = [
  144. // "name" => $item_name,
  145. // "pid" => $pid,
  146. // "level" => $level,
  147. // "weight" => $weight,
  148. // "is_del" => 0,
  149. // 'companyNo' => $companyNo,
  150. // "addtime" => date("Y-m-d H:i:s"),
  151. // "updatetime" => date("Y-m-d H:i:s"),
  152. // ];
  153. //
  154. // $t = Db::name("company_item")->insert($data, true);
  155. // if ($t > 0) {
  156. // $orde = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "creat"];
  157. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", 0, $orde);
  158. // $depart_link = $spid['depart_link'] . "{$t}-";
  159. // $level = explode('-', $depart_link);
  160. // $level = array_filter($level);
  161. // $level = count($level);
  162. // $i = ['depart_link' => $depart_link, 'level' => $level];
  163. // $o = Db::name('company_item')->where(['id' => $t])->update($i);
  164. // if ($o) {
  165. // $stn = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  166. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
  167. // Db::commit();
  168. // return error_show(0, "添加成功");
  169. // }
  170. // }
  171. // Db::rollback();
  172. //
  173. // } catch (\Exception $e) {
  174. // Db::rollback();
  175. // return error_show(1003, $e->getMessage());
  176. // }
  177. }
  178. public function refresh()
  179. {
  180. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  181. // if ($token == "") {
  182. // return error_show(101, 'token不能为空');
  183. // }
  184. // $effetc = VerifyTokens($token);
  185. // if (!empty($effetc) && $effetc['code'] != 0) {
  186. // return error_show($effetc['code'], $effetc['message']);
  187. // }
  188. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  189. $items = Db::name("company_item")->where(['id' => $id, 'is_del' => 0])->find();
  190. if ($items == false) {
  191. return error_show(1003, "部门信息不存在");
  192. }
  193. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
  194. if ($pid == "") {
  195. return error_show(1002, "父级id不能为空");
  196. }
  197. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  198. if ($companyNo == "") return error_show(1002, "所属企业不能为空");
  199. $spid = ['depart_link' => ""];
  200. if ($pid != 0) {
  201. $spid = Db::name('company_item')->where(['id' => $pid, 'is_del' => 0])->find();
  202. if (empty($spid)) {
  203. return error_show(1004, "父级数据不能为空");
  204. }
  205. }
  206. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
  207. $itemname = isset($this->post['name']) ? trim($this->post['name']) : "";
  208. if ($itemname == "") {
  209. return error_show(1002, "部门名称不能为空");
  210. }
  211. $repeat_name = Db::name("company_item")->where(["is_del" => 0, "name" => $itemname, 'companyNo' => $companyNo])->where('id', '<>', $id)->find();
  212. //echo Db::name("company_item")->getLastSql();
  213. if (!empty($repeat_name)) {
  214. return error_show(1004, "部门名称已存在");
  215. }
  216. $depart_link = $spid['depart_link'] . "{$id}-";
  217. $itemlevel = explode('-', $depart_link);
  218. $itemlevel = array_filter($itemlevel);
  219. $itemlevel = count($itemlevel);
  220. $item = [
  221. "id" => $id,
  222. "name" => $itemname,
  223. "updatetime" => date("Y-m-d H:i:s"),
  224. "weight" => $weight, "pid" => $pid,
  225. 'depart_link' => $depart_link,
  226. 'level' => $itemlevel,
  227. 'companyNo' => $companyNo
  228. ];
  229. $re = Db::name("company_item")->save($item);
  230. $stn = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  231. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
  232. return $re ? app_show(0, "信息更新成功") : error_show(1003, "信息更新失败");
  233. }
  234. /*查询*/
  235. public function query()
  236. {
  237. $userCommon = new \app\admin\common\User();
  238. $rs = $userCommon->handle('query');
  239. return json_show($rs['code'], $rs['message'],$rs['data']);
  240. // $companyNo = isset($this->post['companyNo']) ? trim($this->post['companyNo']) : "";
  241. // if ($companyNo == "") return error_show(1004, '所属企业不能为空');
  242. // $effetc = VerifyTokens($token);
  243. // if (!empty($effetc) && $effetc['code'] != 0) {
  244. // return error_show($effetc['code'], $effetc['message']);
  245. // }
  246. // $dati = Db::name("company_item")
  247. // ->where(['pid' => 0, 'is_del' => 0, 'companyNo' => $companyNo])
  248. // ->order("weight desc")
  249. // ->select()
  250. // ->toArray();
  251. $k = [];
  252. // foreach ($dati as $key => $value) {
  253. // $temp=[];
  254. //$temp= Db::name("company_item")->where(['pid'=>$value['id'],'is_del'=>0])->order("weight desc")->select();
  255. // $value['child'] =$temp;
  256. // $k[]=$value;
  257. // $k[] = crea($value);
  258. // }
  259. // return app_show(0, "获取成功", $k);
  260. }
  261. public function itemdel()
  262. {
  263. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  264. // if ($token == "") {
  265. // return error_show(101, 'token不能为空');
  266. // }
  267. // $effetc = VerifyTokens($token);
  268. // if (!empty($effetc) && $effetc['code'] != 0) {
  269. // return error_show($effetc['code'], $effetc['message']);
  270. // }
  271. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  272. $items = Db::name("company_item")
  273. ->field('id,is_del,updatetime')
  274. ->where(['is_del' => 0, 'id' => $id])
  275. ->findOrEmpty();
  276. if (empty($items)) {
  277. return error_show(1003, "部门信息不存在");
  278. }
  279. $items['is_del'] = 1;
  280. $items['updatetime'] = date("Y-m-d H:i:s");
  281. $result = Db::name("company_item")->save($items);
  282. $stn = ["order_code" => $items['name'], "status" => 0, "action_remark" => '', "action_type" => "delete"];
  283. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
  284. return $result ? app_show(0, "删除成功") : error_show(1003, "删除失败");
  285. }
  286. }