|
@@ -11,42 +11,40 @@ use think\facade\Validate;
|
|
|
//系统的组织架构
|
|
|
class Newfill extends Base
|
|
|
{
|
|
|
- public function __construct(App $app)
|
|
|
- {
|
|
|
- parent::__construct($app);
|
|
|
- }
|
|
|
-
|
|
|
public function list()
|
|
|
{
|
|
|
$post = $this->request->only(['pid' => '', 'name' => '', 'nickname' => '', 'companyNo' => ''], 'post', 'trim');
|
|
|
|
|
|
- $depart = $condition = [['is_del', '=', 0]];
|
|
|
- if ($post['pid'] !== '') $condition[] = ["pid", "=", $post['pid']];
|
|
|
- if ($post['name'] != "") $condition[] = ["name", "like", "%{$post['name']}%"];
|
|
|
- if ($post['nickname'] != '') {
|
|
|
- $is = Db::name("depart_user")
|
|
|
- ->where([['nickname', 'like', "%{$post['nickname']}%"]])
|
|
|
- ->column('itemid');
|
|
|
-
|
|
|
- if (empty($is)) return json_show(1004, "未找到数据");
|
|
|
-
|
|
|
- $condition[] = ["id", "in", $is];
|
|
|
- }
|
|
|
- if ($post['pid'] === '' && $post['name'] == '' && $post['nickname'] == '') $condition[] = ["pid", "=", 0];
|
|
|
-
|
|
|
- $pidlist = Db::name("company_item")
|
|
|
- ->where($condition)
|
|
|
- ->column("pid");
|
|
|
- if (!empty($pidlist)) $depart[] = [["itemid", "in", $pidlist]];
|
|
|
- else {
|
|
|
- if ($post['pid'] === "") $depart[] = ['itemid', '=', 0];
|
|
|
- else $depart[] = ['itemid', '=', $post['pid']];
|
|
|
- }
|
|
|
+// $depart = $condition = [['is_del', '=', 0]];
|
|
|
+// if ($post['pid'] !== '') $condition[] = ["pid", "=", $post['pid']];
|
|
|
+// if ($post['name'] != "") $condition[] = ["name", "like", "%{$post['name']}%"];
|
|
|
+// if ($post['nickname'] != '') {
|
|
|
+// $is = Db::name("depart_user")
|
|
|
+// ->where([['nickname', 'like', "%{$post['nickname']}%"]])
|
|
|
+// ->column('itemid');
|
|
|
+//
|
|
|
+// if (empty($is)) return json_show(1004, "未找到数据");
|
|
|
+//
|
|
|
+// $condition[] = ["id", "in", $is];
|
|
|
+// }
|
|
|
+// if ($post['pid'] === '' && $post['name'] == '' && $post['nickname'] == '') $condition[] = ["pid", "=", 0];
|
|
|
+//
|
|
|
+// $pidlist = Db::name("company_item")
|
|
|
+// ->where($condition)
|
|
|
+// ->column("pid");
|
|
|
+// if (!empty($pidlist)) $depart[] = [["itemid", "in", $pidlist]];
|
|
|
+// else {
|
|
|
+// if ($post['pid'] === "") $depart[] = ['itemid', '=', 0];
|
|
|
+// else $depart[] = ['itemid', '=', $post['pid']];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $item = Db::name("depart_user")->where($depart)->select()->toArray();
|
|
|
+// $list = Db::name("company_item")->where($condition)->select()->toArray();
|
|
|
|
|
|
- $item = Db::name("depart_user")->where($depart)->select()->toArray();
|
|
|
- $list = Db::name("company_item")->where($condition)->select()->toArray();
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('ulist',$post);
|
|
|
|
|
|
- return app_show(0, "获取成功", ["depart" => $list, "item" => $item]);
|
|
|
+ return json_show($rs['code'], $rs['message'],$rs['data']);//"获取成功", ["depart" => $list, "item" => $item]);
|
|
|
}
|
|
|
|
|
|
/*状态*/
|
|
@@ -123,77 +121,76 @@ class Newfill extends Base
|
|
|
|
|
|
public function add()
|
|
|
{
|
|
|
-// $token = isset($this->post['token']) ? trim($this->post['token']) : "";
|
|
|
-// if($token==""){
|
|
|
-// return error_show(101,'token不能为空');
|
|
|
-// }
|
|
|
-// $effetc = VerifyTokens($token);
|
|
|
-// if(!empty($effetc) && $effetc['code']!=0){
|
|
|
-// return error_show($effetc['code'],$effetc['message']);
|
|
|
-// }
|
|
|
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
|
|
|
- if ($companyNo == '') return json_show(1004, '所属企业不能为空');
|
|
|
+ $param = $this->request->filter('trim')->post();
|
|
|
|
|
|
- $item_name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
|
|
|
- if ($item_name == "") {
|
|
|
- return error_show(0, "部门名称不能为空");
|
|
|
- }
|
|
|
- $repeat_name = Db::name("company_item")
|
|
|
- ->where(["is_del" => 0, "name" => $item_name, 'companyNo' => $companyNo])
|
|
|
- ->findOrEmpty();
|
|
|
- if (!empty($repeat_name)) {
|
|
|
- return error_show(1004, "部门名称已存在");
|
|
|
- }
|
|
|
- $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
|
|
|
- if ($pid === "") {
|
|
|
- return error_show(1002, "父级id不能为空");
|
|
|
- }
|
|
|
- //$spid = Db::name('company_item')->where(['id'=>$pid,'is_del'=>0])->find();
|
|
|
- $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, "父级数据不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
- $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
|
|
|
- $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $data = [
|
|
|
- "name" => $item_name,
|
|
|
- "pid" => $pid,
|
|
|
- "level" => $level,
|
|
|
- "weight" => $weight,
|
|
|
- "is_del" => 0,
|
|
|
- 'companyNo' => $companyNo,
|
|
|
- "addtime" => date("Y-m-d H:i:s"),
|
|
|
- "updatetime" => date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $rs = $userCommon->handle('add',$param);
|
|
|
|
|
|
- $t = Db::name("company_item")->insert($data, true);
|
|
|
- if ($t > 0) {
|
|
|
- $orde = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "creat"];
|
|
|
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", 0, $orde);
|
|
|
- $depart_link = $spid['depart_link'] . "{$t}-";
|
|
|
- $level = explode('-', $depart_link);
|
|
|
- $level = array_filter($level);
|
|
|
- $level = count($level);
|
|
|
- $i = ['depart_link' => $depart_link, 'level' => $level];
|
|
|
- $o = Db::name('company_item')->where(['id' => $t])->update($i);
|
|
|
- if ($o) {
|
|
|
- $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);
|
|
|
- Db::commit();
|
|
|
- return error_show(0, "添加成功");
|
|
|
- }
|
|
|
- }
|
|
|
- Db::rollback();
|
|
|
+ return json_show($rs['code'],$rs['message'],$rs['data']);
|
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1003, $e->getMessage());
|
|
|
- }
|
|
|
+// $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
|
|
|
+// if ($companyNo == '') return json_show(1004, '所属企业不能为空');
|
|
|
+//
|
|
|
+// $item_name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
|
|
|
+// if ($item_name == "") {
|
|
|
+// return error_show(0, "部门名称不能为空");
|
|
|
+// }
|
|
|
+// $repeat_name = Db::name("company_item")
|
|
|
+// ->where(["is_del" => 0, "name" => $item_name, 'companyNo' => $companyNo])
|
|
|
+// ->findOrEmpty();
|
|
|
+// if (!empty($repeat_name)) {
|
|
|
+// return error_show(1004, "部门名称已存在");
|
|
|
+// }
|
|
|
+// $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "";
|
|
|
+// if ($pid === "") {
|
|
|
+// return error_show(1002, "父级id不能为空");
|
|
|
+// }
|
|
|
+//
|
|
|
+// $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, "父级数据不能为空");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
|
|
|
+// $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "1";
|
|
|
+// Db::startTrans();
|
|
|
+// try {
|
|
|
+// $data = [
|
|
|
+// "name" => $item_name,
|
|
|
+// "pid" => $pid,
|
|
|
+// "level" => $level,
|
|
|
+// "weight" => $weight,
|
|
|
+// "is_del" => 0,
|
|
|
+// 'companyNo' => $companyNo,
|
|
|
+// "addtime" => date("Y-m-d H:i:s"),
|
|
|
+// "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+// ];
|
|
|
+//
|
|
|
+// $t = Db::name("company_item")->insert($data, true);
|
|
|
+// if ($t > 0) {
|
|
|
+// $orde = ["order_code" => $repeat_name['name'], "status" => 0, "action_remark" => '', "action_type" => "creat"];
|
|
|
+// ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, "company_item", 0, $orde);
|
|
|
+// $depart_link = $spid['depart_link'] . "{$t}-";
|
|
|
+// $level = explode('-', $depart_link);
|
|
|
+// $level = array_filter($level);
|
|
|
+// $level = count($level);
|
|
|
+// $i = ['depart_link' => $depart_link, 'level' => $level];
|
|
|
+// $o = Db::name('company_item')->where(['id' => $t])->update($i);
|
|
|
+// if ($o) {
|
|
|
+// $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);
|
|
|
+// Db::commit();
|
|
|
+// return error_show(0, "添加成功");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// Db::rollback();
|
|
|
+//
|
|
|
+// } catch (\Exception $e) {
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1003, $e->getMessage());
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
public function refresh()
|