AutoUser.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\util\ExcelUtil;
  4. use think\Db;
  5. class AutoUser extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sord','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $user = input('user','','trim');
  18. if($user){
  19. $id = Db::name('user')
  20. ->join('user_org uo','user.id=uo.user_id')
  21. ->where('uo.org_id',$this->orgId)
  22. ->where('user.real_name',$user)
  23. ->value('user.id');
  24. $map[] = ['user_id','=',$id];
  25. }
  26. $s = input('start','','trim');
  27. if($s != ''){
  28. $id = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('title',$s)->value('id');
  29. $map[] = ['start','=',$id];
  30. }
  31. $end = input('end','','trim');
  32. if($end != ''){
  33. $id = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('title',$end)->value('id');
  34. $map[] = ['end','=',$id];
  35. }
  36. // $map[] = ['del','=',0];
  37. $map[] = ['org_id','=',$this->orgId];
  38. $map= empty($map) ? true: $map;
  39. //数据查询
  40. $lists = db('auto_user')->where($map)->limit($start,$length)->order($order)->select();
  41. foreach ($lists as $k=>$v){
  42. $lists[$k]['real_name']= Db::name('user')->where('del',0)->where('id',$v['user_id'])->value('real_name');
  43. $lists[$k]['start_name'] = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('id',$v['start'])->value('title');
  44. $lists[$k]['end_name'] = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('id',$v['end'])->value('title');
  45. }
  46. //数据返回
  47. $totalCount = db('auto_user')->where($map)->count();
  48. $totalPage = ceil($totalCount/$length);
  49. $result['page'] = $page;
  50. $result['total'] = $totalPage;
  51. $result['records'] = $totalCount;
  52. $result['rows'] = $lists;
  53. return json($result);
  54. }else{
  55. return $this->fetch();
  56. }
  57. }
  58. /**
  59. * 新增/编辑
  60. */
  61. public function add($id=0){
  62. if(request()->isPost()){
  63. $res = model('AutoUser')->updates();
  64. if($res){
  65. $this->success('操作成功',url('index'));
  66. }else{
  67. $this->error(model('AutoUser')->getError());
  68. }
  69. }else{
  70. if($id){
  71. $info = db('AutoUser')->where('id',$id)->find();
  72. $this->assign('info',$info);
  73. }
  74. // halt($info);
  75. $address = model('address')->getListByTypes('',2,$this->orgId);
  76. $this->assign('address',$address);
  77. $user = (new \app\common\model\WorkTypeMode())->getRolesUserByNum(3, $this->orgId,1);
  78. foreach ($user[0]['user'] as $k =>$v){
  79. $user[0]['user'][$k]['title']= preg_replace('/\(.*?\)/', '', $v['real_name']);
  80. };
  81. $this->assign('user', $user[0]['user']);
  82. return $this->fetch();
  83. }
  84. }
  85. /**
  86. * 删除记录
  87. * @param int $id
  88. */
  89. public function del($id=0){
  90. if(!$id){
  91. $this->error('参数错误');
  92. }
  93. $res = db('AutoUser')->where('id',$id)->delete();
  94. if($res){
  95. $this->success('删除成功');
  96. }else{
  97. $this->error('删除失败');
  98. }
  99. }
  100. /**
  101. * 改变字段值
  102. * @param int $fv
  103. * @param string $fn
  104. * @param int $fv
  105. */
  106. public function changeField($id=0,$fn='',$fv=0){
  107. if(!$fn||!$id){
  108. $this->error('参数错误');
  109. }
  110. $res = db('AutoUser')->where('id',$id)->setField($fn,$fv);
  111. if($res){
  112. $this->success('操作成功');
  113. }else{
  114. $this->error('操作失败');
  115. }
  116. }
  117. }