0
0

PatrolTaskApply.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\Task;
  4. use think\Db;
  5. class PatrolTaskApply extends Auth
  6. {
  7. public function index($mode=1){
  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. $status = input('status','','trim');
  18. if($status != ''){
  19. $map[] = ['status','=',$status];
  20. }
  21. $map[] = ['org_id','=',$this->orgId];
  22. $map[] = ['patrol_mode','=',$mode];
  23. $map= empty($map) ? true: $map;
  24. //数据查询
  25. $lists = Db::name('patrol_task_apply')->where($map)
  26. ->limit($start,$length)->order($order)->select();
  27. foreach ($lists as $k=>$v){
  28. $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title');
  29. $lists[$k]['task_title'] = $taskTitle?$taskTitle:'';
  30. // $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
  31. $lists[$k]['uname'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  32. $lists[$k]['deal_user'] = '';
  33. if($v['deal_user_id'] > 0){
  34. $lists[$k]['deal_user'] = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name');
  35. }
  36. }
  37. //数据返回
  38. $totalCount = Db::name('patrol_task_apply')->where($map)->count();
  39. $totalPage = ceil($totalCount/$length);
  40. $result['page'] = $page;
  41. $result['total'] = $totalPage;
  42. $result['records'] = $totalCount;
  43. $result['rows'] = $lists;
  44. return json($result);
  45. }else{
  46. $this->assign('mode',$mode);
  47. return $this->fetch();
  48. }
  49. }
  50. /**
  51. * 处理
  52. */
  53. public function deal($id = 0){
  54. if(request()->isPost()){
  55. $res = model('PatrolTaskApply')->dealApply($this->userId,$this->orgId);
  56. if($res){
  57. $this->success('操作成功',url('deal'));
  58. }else{
  59. $this->error(model('PatrolTaskApply')->getError());
  60. }
  61. }else{
  62. $this->assign('id',$id);
  63. return $this->fetch();
  64. }
  65. }
  66. }