User.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. public function exusers(){
  22. $id = input('id/d',0);
  23. $work = input('work/d',1);
  24. if(!in_array($work,[-1,0,1])){
  25. HelpHander::error('参数错误');
  26. }
  27. $users = model('WorkTypeMode')->getRolesUserApp($id,$this->orgId,$work);
  28. HelpHander::success($users);
  29. }
  30. //品控执行人列表
  31. public function qualityUserList(){
  32. $users = model('WorkTypeMode')->getRolesUser(18,$this->orgId,1);
  33. $list = [];
  34. foreach ($users as $k=>$v){
  35. foreach ($v['user'] as $v1){
  36. $list[] = $v1;
  37. }
  38. }
  39. HelpHander::success($list);
  40. }
  41. //品控知会人列表
  42. public function qualityIformUserList(){
  43. $id = input('id/d',0);
  44. $users = model('WorkTypeMode')->commonRolesUserList($id,$this->orgId);
  45. HelpHander::success($users);
  46. }
  47. //公共角色列表
  48. public function commonRoles(){
  49. $commons = model('Roles')->getCommonList(1);
  50. $a = [];
  51. foreach ($commons as $k=>$v){
  52. $a[] = [
  53. 'id'=>$v['id'],
  54. 'title'=>$v['name'],
  55. ];
  56. }
  57. HelpHander::success($a);
  58. }
  59. //获取二级调度角色
  60. public function getTwoDispatchRoles(){
  61. $type = input('id/d',1);
  62. $list = model('user')->get_two_dispatch_role1($this->orgId,$type);
  63. HelpHander::success($list);
  64. }
  65. //判断工人是否可以自发
  66. public function isSpontaneous(){
  67. $workType = input('WorkTypeMode/d',1);
  68. $roles = input('rolesId/d',0);
  69. if(!in_array($workType,[0,1,2,3,4])){
  70. HelpHander::error('订单类型错误');
  71. }
  72. $rolesInfo = Db::name('roles')
  73. ->where('id',$roles)
  74. ->find();
  75. if($rolesInfo['parent_id'] >0){
  76. $roles = $rolesInfo['parent_id'];
  77. }
  78. $map[] = ['','exp',Db::raw("FIND_IN_SET(".$roles.",roles)")];
  79. $info = Db::name('work_type_mode')
  80. ->where($map)
  81. ->column('id');
  82. if(empty($info)){
  83. $off = 0;
  84. }else{
  85. if(!in_array($workType,$info)){
  86. $off = 0;
  87. }else{
  88. $off = 1;
  89. }
  90. }
  91. HelpHander::success($off);
  92. }
  93. public function updateHeadImage(){
  94. $headimage = input('imageUrl','','trim');
  95. $ret=Db::name('user')
  96. ->where('id',$this->userId)
  97. ->update(['head_image'=>$headimage]);
  98. if($ret){
  99. HelpHander::success(null,'修改成功');
  100. }else{
  101. HelpHander::error('修改失败');
  102. }
  103. }
  104. public function updatePassword(){
  105. $data = [
  106. 'oldpass' => input('password','','trim'), //旧密码
  107. 'pass' => input('newPassword','','trim'), //新密码
  108. 'pass_confirm' => input('newPassword','','trim'),//确认密码
  109. 'id' => $this->userId
  110. ];
  111. $data['oldpass'] = aes_decrypt($data['oldpass']);
  112. $data['pass'] = aes_decrypt($data['pass']);
  113. $data['pass_confirm'] = aes_decrypt($data['pass_confirm']);
  114. $ret = model('User')->modifyPass($data);
  115. if(!$ret){
  116. HelpHander::error(model('User')->getError());
  117. }
  118. $token = model('Token')->updateToken($data['id']);
  119. if(!$token){
  120. HelpHander::error(model('Token')->getError());
  121. }
  122. $params = ['user_id' => $data['id'],'code' => $token];
  123. HelpHander::success($params,'修改成功,请重置登录信息');
  124. }
  125. //上下班
  126. public function worker(){
  127. $worker = input('work/d',0);
  128. $info = Db::name('user')->where('id',$this->userId)->where('del',0)->find();
  129. if(!$info){
  130. HelpHander::error('用户不存在');
  131. }
  132. if($worker == $info['work']){
  133. HelpHander::success([],'操作成功');
  134. }else{
  135. $res = Db::name('user')
  136. ->where('id',$this->userId)
  137. ->update([
  138. 'work'=>$worker,
  139. 'update_time'=>getTime(),
  140. ]);
  141. }
  142. $res?HelpHander::success([],'操作成功'):HelpHander::error('操作失败');
  143. }
  144. }