UserSpecial.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 UserSpecial extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'user_id' => input('uid/d',0),
  12. 'znjy' => input('znjy/f',0),
  13. 'jxjy' => input('jxjy/f',0),
  14. 'zfdklx' => input('zfdklx/f',0),
  15. 'zfzj' => input('zfzj/f',0),
  16. 'sylr' => input('sylr/f',0),
  17. 'syjkbx' => input('syjkbx/f',0),
  18. 'ysylbx' => input('ysylbx/f',0),
  19. 'nzjds' => input('nzjds/f',0),
  20. 'gzds' => input('gzds/f',0),
  21. 'grbk' => input('grbk/f',0),
  22. 'zykcjze' => input('zykcjze/f',0),
  23. 'jmsebl' => input('jmsebl/f',0),
  24. 'qtkc' => input('qtkc/f',0),
  25. 'mssr' => input('mssr/f',0),
  26. 'yyezh' => input('yyezh/f',0),
  27. 'grylj' => input('grylj/f',0),
  28. ];
  29. $result = validate('UserSpecial')->check($data,[],'');
  30. if(true !== $result){
  31. HelpHander::error(validate('UserSpecial')->getError());
  32. }
  33. $ubase = Db::name('user_special')->where('user_id',$data['user_id'])->find();
  34. if($ubase){ // 修改
  35. $data['update_time'] = date('Y-m-d H:i:s');
  36. $res = Db::name('user_special')->where('id',$ubase['id'])->update($data);
  37. } else {// 新增
  38. $data['create_time'] = date('Y-m-d H:i:s');
  39. $data['update_time'] = date('Y-m-d H:i:s');
  40. $res = Db::name('user_special')->insert($data);
  41. }
  42. if(!$res){
  43. HelpHander::error('操作失败');
  44. }
  45. return true;
  46. }
  47. public function info($id){
  48. $info = $this->where('id',$id)->find();
  49. if(!$info){
  50. HelpHander::error('数据不存在');
  51. }
  52. $data = $info->toArray();
  53. $data['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
  54. return $data;
  55. }
  56. public function lists($page,$size,$orgId,$name,$phone,$companyId){
  57. if($name != ''){
  58. $map[] = ['ui.name','like','%'.$name.'%'];
  59. }
  60. if($phone != ''){
  61. $map[] = ['u.phone','like','%'.$phone.'%'];
  62. }
  63. if($companyId > 0){
  64. $map[] = ['ui.company_id','=',$companyId];
  65. }
  66. $uids = model('User')->getAdminUsers();
  67. if($uids){
  68. $map[] = ['u.id','not in',$uids];
  69. }
  70. $map[] = ['u.del','=',0];
  71. $map[] = ['r.type','=',3];
  72. $map[] = ['r.org_id','=',$orgId];
  73. $map[] = ['ui.pay_type','in',[1,2]];
  74. $lists = Db::name('user_info')
  75. ->alias('ui')
  76. ->join('user u','ui.user_id = u.id')
  77. ->join('user_roles ur','ur.user_id = u.id')
  78. ->join('roles r','ur.roles_id = r.id')
  79. ->join('user_special us','us.user_id = u.id','left')
  80. ->where($map)
  81. ->field('us.*,u.phone,ui.name,ui.gender,ui.user_id as uid')
  82. ->page($page,$size)
  83. ->order('ui.sorts2 asc,ui.id desc')
  84. ->select();
  85. $lists = $lists?$lists:[];
  86. // foreach ($lists as $k=>$v){
  87. // $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  88. // }
  89. $total = Db::name('user_info')
  90. ->alias('ui')
  91. ->join('user u','ui.user_id = u.id')
  92. ->join('user_roles ur','ur.user_id = u.id')
  93. ->join('roles r','ur.roles_id = r.id')
  94. ->join('user_special us','us.user_id = u.id','left')
  95. ->where($map)->count();
  96. $data = [
  97. 'total' => $total,
  98. 'list' => $lists?$lists:[]
  99. ];
  100. return $data;
  101. }
  102. public function del($id){
  103. $ret = $this->where('id',$id)->delete();
  104. if(!$ret){
  105. HelpHander::error('删除失败');
  106. }
  107. return true;
  108. }
  109. }