UserRetired.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class UserRetired extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'user_id' => input('uid/d',0),
  12. 'jbgz' => input('jbgz/f','','trim'),
  13. 'txbt' => input('txbt/f','','trim'),
  14. 'bz' => input('bz/f','','trim'),
  15. 'zysdbt' => input('zysdbt/f','','trim'),
  16. 'fb' => input('fb/f','','trim'),
  17. 'bljx' => input('bljx/f','','trim'),
  18. 'jbtxf' => input('jbtxf/f','','trim'),
  19. 'wybt' => input('wybt/f','','trim'),
  20. 'dktc' => input('dktc/f','','trim')
  21. ];
  22. $result = validate('UserRetired')->check($data,[],'');
  23. if(true !== $result){
  24. HelpHander::error(validate('UserRetired')->getError());
  25. }
  26. $ubase = Db::name('user_retired')->where('user_id',$data['user_id'])->find();
  27. if($ubase){ // 修改
  28. $data['update_time'] = date('Y-m-d H:i:s');
  29. $res = Db::name('user_retired')->where('id',$ubase['id'])->update($data);
  30. } else {// 新增
  31. $data['create_time'] = date('Y-m-d H:i:s');
  32. $data['update_time'] = date('Y-m-d H:i:s');
  33. $res = Db::name('user_retired')->insert($data);
  34. }
  35. if(!$res){
  36. HelpHander::error('操作失败');
  37. }
  38. return true;
  39. }
  40. public function info($uid){
  41. $info = Db::name('user_info')
  42. ->alias('ui')
  43. ->join('user_retired ure','ure.user_id = ui.user_id','left')
  44. ->where('ui.user_id',$uid)
  45. ->field('ure.*,ui.name as user_name,ui.gender,ui.user_id as uid')
  46. ->find();
  47. if(!$info){
  48. HelpHander::error('数据不存在');
  49. }
  50. return $info;
  51. }
  52. public function lists($page,$size,$orgId,$name,$phone){
  53. if($name != ''){
  54. $map[] = ['ui.name','like','%'.$name.'%'];
  55. }
  56. if($phone != ''){
  57. $map[] = ['u.phone','like','%'.$phone.'%'];
  58. }
  59. $map[] = ['ui.company_id','=',1];
  60. $uids = model('User')->getAdminUsers();
  61. if($uids){
  62. $map[] = ['u.id','not in',$uids];
  63. }
  64. $map[] = ['u.del','=',0];
  65. $map[] = ['r.type','=',3];
  66. $map[] = ['r.org_id','=',$orgId];
  67. $map[] = ['ui.pay_type','=',5];
  68. $lists = Db::name('user_info')
  69. ->alias('ui')
  70. ->join('user u','ui.user_id = u.id')
  71. ->join('user_roles ur','ur.user_id = u.id')
  72. ->join('roles r','ur.roles_id = r.id')
  73. ->join('user_retired ure','ure.user_id = u.id','left')
  74. ->where($map)
  75. ->field('ure.*,u.phone,ui.name,ui.gender,ui.user_id as uid')
  76. ->page($page,$size)
  77. ->order('u.id desc')
  78. ->select();
  79. $lists = $lists?$lists:[];
  80. // $map = empty($map)?true:$map;
  81. // $lists = Db::name('user_retired')
  82. // ->alias('ur')
  83. // ->join('user u','u.id = ur.user_id')
  84. // ->join('user_info ui','ui.user_id = ur.user_id')
  85. // ->where($map)
  86. // ->field('ur.*,u.phone,ui.name,ui.gender')
  87. // ->page($page,$size)
  88. // ->order('id desc')
  89. // ->select();
  90. $total = Db::name('user_info')
  91. ->alias('ui')
  92. ->join('user u','ui.user_id = u.id')
  93. ->join('user_roles ur','ur.user_id = u.id')
  94. ->join('roles r','ur.roles_id = r.id')
  95. ->join('user_retired ure','ure.user_id = u.id','left')
  96. ->where($map)->count();
  97. $data = [
  98. 'total' => $total,
  99. 'list' => $lists?$lists:[]
  100. ];
  101. return $data;
  102. }
  103. public function del($id){
  104. $ret = $this->where('id',$id)->delete();
  105. if(!$ret){
  106. HelpHander::error('删除失败');
  107. }
  108. return true;
  109. }
  110. public function changeStatus($id,$enable){
  111. $ret = Db::name('user_retired')->where('id',$id)->setField('status',$enable);
  112. if(!$ret){
  113. HelpHander::error('操作失败');
  114. }
  115. return true;
  116. }
  117. public function retiredUser($page,$size,$name,$phone,$orgId){
  118. $uids = Db::name('user_retired')->column('user_id');
  119. $map[] = ['ui.is_working','=',4];
  120. if($phone){
  121. $map[] = ['u.phone','like','%'.$phone.'%'];
  122. }
  123. if($name){
  124. $map[] = ['ui.name','like','%'.$name.'%'];
  125. }
  126. if($uids){
  127. $map[] = ['u.id','not in',$uids];
  128. }
  129. $lists = Db::name('user')
  130. ->alias('u')
  131. ->join('user_info ui','ui.user_id = u.id')
  132. ->where($map)
  133. ->field('u.id,u.phone,ui.name,ui.out_time,ui.out_reason,ui.gender')
  134. ->page($page,$size)
  135. ->order('ui.out_time desc,ui.id desc')
  136. ->select();
  137. $total = Db::name('user')
  138. ->alias('u')
  139. ->join('user_info ui','ui.user_id = u.id')
  140. ->where($map)->count();
  141. $data = [
  142. 'total' => $total,
  143. 'list' => $lists?$lists:[]
  144. ];
  145. return $data;
  146. }
  147. }