DepartUser.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\bug\model;
  3. use app\user\model\Account;
  4. class DepartUser extends Base
  5. {
  6. //设置字段信息
  7. protected $schema = [
  8. 'id' =>'bigint',//
  9. 'uid' =>'bigint',//员工id
  10. 'nickname' =>'varchar',//员工名称
  11. 'itemid' =>'bigint',//部门id
  12. 'is_del' =>'int',//是否删除
  13. 'status' =>'int',//员工状态 1在职 2离职
  14. 'addtime' =>'datetime',//
  15. 'updatetime' =>'datetime',//
  16. 'position' =>'int',//职位 1普通2负责人
  17. ];
  18. protected $updateTime='updatetime';
  19. protected $createTime='addtime';
  20. public function GetDepartNameByUid($uid){
  21. $list=Account::where(['id'=>$uid])->with(['accountItem'=>['itemName']])->select();
  22. return array_column($list->toArray(),"depart_name","id");
  23. }
  24. //设置角色部门
  25. public function SetItem($uid,$itemArr=[]){
  26. if(empty($itemArr))return $this->where(["uid"=>$uid,"is_del"=>0])->save(["is_del"=>1]);
  27. else{
  28. $this->where(['uid'=>$uid,'is_del'=>0])->whereNotIn("itemid",$itemArr)->save(['is_del'=>1]);
  29. $inItem=$this->where(['uid'=>$uid,'is_del'=>0])->whereIn("itemid",$itemArr)->column("itemid");
  30. $temp=[];
  31. $acc = Account::with(["userInfo"])->findOrEmpty($uid);
  32. if($acc->isEmpty())throw new \Exception("账户不存在");
  33. foreach ($itemArr as $item){
  34. if(in_array($item,$inItem)) continue;
  35. $depin =[
  36. 'uid'=>$uid,
  37. 'nickname'=>$acc->nickname,
  38. 'itemid'=>$item,
  39. ];
  40. $temp[]=$depin;
  41. }
  42. if(!empty($temp))return $this->saveAll($temp);
  43. }
  44. }
  45. }