Newfill.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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' => '','companyName'=>''], '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 = \app\admin\common\User::getIns();
  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. $param = $this->request->filter('trim')->post();
  47. $userCommon = \app\admin\common\User::getIns();
  48. $rs = $userCommon->handle('stat', $param);
  49. return json_show($rs['code'], $rs['message'], $rs['data']);
  50. // $id = $this->request->post('id/d', 0, 'trim');
  51. // if ($id == 0) return json_show(1004, "参数id 不能为空");
  52. //
  53. // $s = Db::name('company_item')
  54. // ->field('id,status')
  55. // ->where('id', $id)
  56. // ->findOrEmpty();
  57. //
  58. // if (empty($s)) return json_show(1005, "未找到部门");
  59. //
  60. // $var = $s['status'];
  61. // $di = $s['status'] == 0 ? 1 : 0;
  62. // $s['status'] = $di;
  63. // $s['updatetime'] = date("Y-m-d H:i:s");
  64. // // var_dump($s);
  65. // $rs = Db::name('company_item')->where('id', $id)->save($s);
  66. //
  67. // if ($rs) {
  68. // $orde = ["order_code" => $s['name'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
  69. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", $s['status'], $orde);
  70. // return json_show(0, "更新成功");
  71. // } else return json_show(1005, '更新失败');
  72. }
  73. /*职位*/
  74. public function userp()
  75. {
  76. $param = $this->request->filter('trim')->post();
  77. $userCommon = \app\admin\common\User::getIns();
  78. $rs = $userCommon->handle('userp', $param);
  79. return json_show($rs['code'], $rs['message'], $rs['data']);
  80. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  81. // $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  82. // if ($id == "") {
  83. // return error_show(1004, "参数id不能为空");
  84. // }
  85. // $t = Db::name('depart_user')->where(["id" => $id, "is_del" => 0])->find();
  86. // if (empty($t)) {
  87. // return error_show(1005, "未找到用户");
  88. // }
  89. // $position = isset($this->post['position']) ? intval($this->post['position']) : "";
  90. // if ($position == "") {
  91. // return error_show(1004, "职位不能为空");
  92. // }
  93. // Db::startTrans();
  94. // if ($position == 2) {
  95. // $f = Db::name('depart_user')->where(['itemid' => $t['itemid'], "is_del" => 0, "position" => 2])->find();
  96. // if (!empty($f) && $f['id'] != $id) {
  97. // $f['position'] = 1;
  98. // $f['updatetime'] = date("Y-m-d H:i:s");
  99. // $m = Db::name('depart_user')->save($f);
  100. // $orde = ["order_code" => $t['nickname'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  101. // ActionLog::logAdd($this->post['token'], $orde, "depart_user", 0, $orde);
  102. // if ($m == false) {
  103. // Db::rollback();
  104. // return error_show(1004, "负责人修改失败");
  105. // }
  106. // }
  107. // }
  108. // $t['position'] = $position;
  109. // $t['updatetime'] = date("Y-m-d H:i:s");
  110. // //var_dump($t);
  111. // $ti = Db::name('depart_user')->save($t);
  112. // if ($ti == true) {
  113. // Db::commit();
  114. // return app_show(0, "修改成功");
  115. // } else {
  116. // Db::rollback();
  117. // return error_show(1004, "修改失败");
  118. // }
  119. }
  120. public function add()
  121. {
  122. $param = $this->request->filter('trim')->post();
  123. $userCommon = \app\admin\common\User::getIns();
  124. $rs = $userCommon->handle('add', $param);
  125. return json_show($rs['code'], $rs['message'], $rs['data']);
  126. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  127. // if ($companyNo == '') return json_show(1004, '所属企业不能为空');
  128. //
  129. // $item_name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  130. // if ($item_name == "") {
  131. // return error_show(0, "部门名称不能为空");
  132. // }
  133. // $repeat_name = Db::name("company_item")
  134. // ->where(["is_del" => 0, "name" => $item_name, 'companyNo' => $companyNo])
  135. // ->findOrEmpty();
  136. // if (!empty($repeat_name)) {
  137. // return error_show(1004, "部门名称已存在");
  138. // }
  139. // $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
  140. // if ($pid === "") {
  141. // return error_show(1002, "父级id不能为空");
  142. // }
  143. //
  144. // $spid = ['depart_link' => ""];
  145. // if ($pid != 0) {
  146. // $spid = Db::name('company_item')->where(['id' => $pid, 'is_del' => 0])->find();
  147. // if (empty($spid)) {
  148. // return error_show(1004, "父级数据不能为空");
  149. // }
  150. // }
  151. // $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
  152. // $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
  153. // Db::startTrans();
  154. // try {
  155. // $data = [
  156. // "name" => $item_name,
  157. // "pid" => $pid,
  158. // "level" => $level,
  159. // "weight" => $weight,
  160. // "is_del" => 0,
  161. // 'companyNo' => $companyNo,
  162. // "addtime" => date("Y-m-d H:i:s"),
  163. // "updatetime" => date("Y-m-d H:i:s"),
  164. // ];
  165. //
  166. // $t = Db::name("company_item")->insert($data, true);
  167. // if ($t > 0) {
  168. // $orde = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "create"];
  169. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", 0, $orde);
  170. // $depart_link = $spid['depart_link'] . "{$t}-";
  171. // $level = explode('-', $depart_link);
  172. // $level = array_filter($level);
  173. // $level = count($level);
  174. // $i = ['depart_link' => $depart_link, 'level' => $level];
  175. // $o = Db::name('company_item')->where(['id' => $t])->update($i);
  176. // if ($o) {
  177. // $stn = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  178. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
  179. // Db::commit();
  180. // return error_show(0, "添加成功");
  181. // }
  182. // }
  183. // Db::rollback();
  184. //
  185. // } catch (\Exception $e) {
  186. // Db::rollback();
  187. // return error_show(1003, $e->getMessage());
  188. // }
  189. }
  190. public function refresh()
  191. {
  192. $param = $this->request->filter('trim')->post();
  193. $userCommon = \app\admin\common\User::getIns();
  194. $rs = $userCommon->handle('refresh', $param);
  195. return json_show($rs['code'], $rs['message'], $rs['data']);
  196. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  197. // if ($token == "") {
  198. // return error_show(101, 'token不能为空');
  199. // }
  200. // $effetc = VerifyTokens($token);
  201. // if (!empty($effetc) && $effetc['code'] != 0) {
  202. // return error_show($effetc['code'], $effetc['message']);
  203. // }
  204. // $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  205. // $items = Db::name("company_item")->where(['id' => $id, 'is_del' => 0])->find();
  206. // if ($items == false) {
  207. // return error_show(1003, "部门信息不存在");
  208. // }
  209. // $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
  210. // if ($pid == "") {
  211. // return error_show(1002, "父级id不能为空");
  212. // }
  213. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  214. // if ($companyNo == "") return error_show(1002, "所属企业不能为空");
  215. //
  216. // $spid = ['depart_link' => ""];
  217. // if ($pid != 0) {
  218. // $spid = Db::name('company_item')->where(['id' => $pid, 'is_del' => 0])->find();
  219. // if (empty($spid)) {
  220. // return error_show(1004, "父级数据不能为空");
  221. // }
  222. // }
  223. // $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
  224. // $itemname = isset($this->post['name']) ? trim($this->post['name']) : "";
  225. // if ($itemname == "") {
  226. // return error_show(1002, "部门名称不能为空");
  227. // }
  228. // $repeat_name = Db::name("company_item")->where(["is_del" => 0, "name" => $itemname, 'companyNo' => $companyNo])->where('id', '<>', $id)->find();
  229. // //echo Db::name("company_item")->getLastSql();
  230. // if (!empty($repeat_name)) {
  231. // return error_show(1004, "部门名称已存在");
  232. // }
  233. // $depart_link = $spid['depart_link'] . "{$id}-";
  234. // $itemlevel = explode('-', $depart_link);
  235. // $itemlevel = array_filter($itemlevel);
  236. // $itemlevel = count($itemlevel);
  237. //
  238. // $item = [
  239. // "id" => $id,
  240. // "name" => $itemname,
  241. // "updatetime" => date("Y-m-d H:i:s"),
  242. // "weight" => $weight, "pid" => $pid,
  243. // 'depart_link' => $depart_link,
  244. // 'level' => $itemlevel,
  245. // 'companyNo' => $companyNo
  246. // ];
  247. // $re = Db::name("company_item")->save($item);
  248. // $stn = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  249. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
  250. // return $re ? app_show(0, "信息更新成功") : error_show(1003, "信息更新失败");
  251. }
  252. /*查询*/
  253. public function query()
  254. {
  255. $param = $this->request->filter('trim')->post();
  256. $userCommon = \app\admin\common\User::getIns();
  257. $rs = $userCommon->handle('query', $param);
  258. return json_show($rs['code'], $rs['message'], $rs['data']);
  259. // $companyNo = isset($this->post['companyNo']) ? trim($this->post['companyNo']) : "";
  260. // if ($companyNo == "") return error_show(1004, '所属企业不能为空');
  261. // $effetc = VerifyTokens($token);
  262. // if (!empty($effetc) && $effetc['code'] != 0) {
  263. // return error_show($effetc['code'], $effetc['message']);
  264. // }
  265. // $dati = Db::name("company_item")
  266. // ->where(['pid' => 0, 'is_del' => 0, 'companyNo' => $companyNo])
  267. // ->order("weight desc")
  268. // ->select()
  269. // ->toArray();
  270. // $k = [];
  271. // foreach ($dati as $key => $value) {
  272. // $temp=[];
  273. //$temp= Db::name("company_item")->where(['pid'=>$value['id'],'is_del'=>0])->order("weight desc")->select();
  274. // $value['child'] =$temp;
  275. // $k[]=$value;
  276. // $k[] = crea($value);
  277. // }
  278. // return app_show(0, "获取成功", $k);
  279. }
  280. public function itemdel()
  281. {
  282. $param = $this->request->filter('trim')->post();
  283. $userCommon = \app\admin\common\User::getIns();
  284. $rs = $userCommon->handle('itemdel', $param);
  285. return json_show($rs['code'], $rs['message'], $rs['data']);
  286. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  287. // if ($token == "") {
  288. // return error_show(101, 'token不能为空');
  289. // }
  290. // $effetc = VerifyTokens($token);
  291. // if (!empty($effetc) && $effetc['code'] != 0) {
  292. // return error_show($effetc['code'], $effetc['message']);
  293. // }
  294. // $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  295. // $items = Db::name("company_item")
  296. // ->field('id,is_del,updatetime')
  297. // ->where(['is_del' => 0, 'id' => $id])
  298. // ->findOrEmpty();
  299. // if (empty($items)) {
  300. // return error_show(1003, "部门信息不存在");
  301. // }
  302. // $items['is_del'] = 1;
  303. // $items['updatetime'] = date("Y-m-d H:i:s");
  304. // $result = Db::name("company_item")->save($items);
  305. // $stn = ["order_code" => $items['name'], "status" => 0, "action_remark" => '', "action_type" => "delete"];
  306. // ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "company_item", 0, $stn);
  307. // return $result ? app_show(0, "删除成功") : error_show(1003, "删除失败");
  308. }
  309. }