User.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. class User extends Base
  7. {
  8. public function info(){
  9. $info = model('User')->info($this->userId,$this->orgId);
  10. if($info){
  11. $orgName = Db::name('org')
  12. ->where('id',$this->orgId)
  13. ->value('name');
  14. $info['orgName'] = $orgName;
  15. $info['h5pre'] = config('app.addr_url');
  16. HelpHander::success($info);
  17. }else{
  18. HelpHander::error(model('User')->getError());
  19. }
  20. }
  21. //维修人员分组列表
  22. public function wxGroup(){
  23. $list= Db::name('repair_group')
  24. ->where([
  25. 'org_id'=>$this->orgId,
  26. 'del'=>0,
  27. 'enable'=>1
  28. ])->field('id,title')->select();
  29. HelpHander::success($list);
  30. }
  31. //维修分组人员
  32. public function wxGroupUser(){
  33. $id = input('id/d',0);
  34. $userIds = Db::name('repair_group')
  35. ->where([
  36. 'del'=>0,
  37. 'enable'=>1,
  38. 'id'=>$id
  39. ])
  40. ->value('users');
  41. $list = explode(',',$userIds);
  42. $users = [];
  43. $ids = Db::name('roles')
  44. ->where('org_id',$this->orgId)
  45. ->where('parent_id',7)
  46. ->where('del',0)
  47. ->where('enable',1)
  48. ->column('id');
  49. $user = Db::name('user')
  50. ->alias('a')
  51. ->join('user_org b','a.id = b.user_id')
  52. ->join('user_roles c','a.id = c.user_id')
  53. ->where('a.del',0)
  54. ->where('a.enable',1)
  55. ->where('b.org_id',$this->orgId)
  56. ->where('c.roles_id','in',$ids)
  57. ->column('real_name','a.id');
  58. foreach ($list as $k=>$v){
  59. $users[] = ['id'=>$v,'real_name'=>$user[$v]];
  60. }
  61. HelpHander::success($users);
  62. }
  63. public function exusers(){
  64. $id = input('id/d',0);
  65. $work = input('work/d',1);
  66. if(!in_array($work,[-1,0,1])){
  67. HelpHander::error('参数错误');
  68. }
  69. $users = model('WorkTypeMode')->getRolesUserApp($id,$this->orgId,$work);
  70. HelpHander::success($users);
  71. }
  72. //品控执行人列表
  73. public function qualityUserList(){
  74. $users = model('WorkTypeMode')->getRolesUser(18,$this->orgId,1);
  75. $list = [];
  76. foreach ($users as $k=>$v){
  77. foreach ($v['user'] as $v1){
  78. $list[] = $v1;
  79. }
  80. }
  81. HelpHander::success($list);
  82. }
  83. //品控知会人列表
  84. public function qualityIformUserList(){
  85. $id = input('id/d',0);
  86. $users = model('WorkTypeMode')->commonRolesUserList($id,$this->orgId);
  87. HelpHander::success($users);
  88. }
  89. //公共角色列表
  90. public function commonRoles(){
  91. $commons = model('Roles')->getCommonList(1);
  92. $a = [];
  93. foreach ($commons as $k=>$v){
  94. $a[] = [
  95. 'id'=>$v['id'],
  96. 'title'=>$v['name'],
  97. ];
  98. }
  99. HelpHander::success($a);
  100. }
  101. //获取二级调度角色
  102. public function getTwoDispatchRoles(){
  103. $type = input('id/d',1);
  104. $list = model('user')->get_two_dispatch_role1($this->orgId,$type);
  105. HelpHander::success($list);
  106. }
  107. //判断工人是否可以自发
  108. public function isSpontaneous(){
  109. $workType = input('WorkTypeMode/d',1);
  110. $roles = input('rolesId/d',0);
  111. if(!in_array($workType,[0,1,2,3,4])){
  112. HelpHander::error('订单类型错误');
  113. }
  114. $rolesInfo = Db::name('roles')
  115. ->where('id',$roles)
  116. ->find();
  117. if($rolesInfo['parent_id'] >0){
  118. $roles = $rolesInfo['parent_id'];
  119. }
  120. $map[] = ['','exp',Db::raw("FIND_IN_SET(".$roles.",roles)")];
  121. $info = Db::name('work_type_mode')
  122. ->where($map)
  123. ->column('id');
  124. if(empty($info)){
  125. $off = 0;
  126. }else{
  127. if(!in_array($workType,$info)){
  128. $off = 0;
  129. }else{
  130. $off = 1;
  131. }
  132. }
  133. HelpHander::success($off);
  134. }
  135. public function updateHeadImage(){
  136. $headimage = input('imageUrl','','trim');
  137. $ret=Db::name('user')
  138. ->where('id',$this->userId)
  139. ->update(['head_image'=>$headimage]);
  140. if($ret){
  141. HelpHander::success(null,'修改成功');
  142. }else{
  143. HelpHander::error('修改失败');
  144. }
  145. }
  146. }