0
0

PatrolTaskApply.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Db;
  7. class PatrolTaskApply extends Base
  8. {
  9. public function list(){
  10. $page = input('page',1);
  11. $size = input('size',20);
  12. $map[] = ['org_id','=',$this->orgId];
  13. $lists = Db::name('patrol_task_apply')
  14. ->where($map)
  15. ->page($page,$size)
  16. ->order('id desc')
  17. ->select();
  18. foreach ($lists as $k=>$v){
  19. $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title');
  20. $lists[$k]['task_title'] = $taskTitle?$taskTitle:'';
  21. // $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
  22. $lists[$k]['uname'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  23. $lists[$k]['deal_user'] = '';
  24. if($v['deal_user_id'] > 0){
  25. $lists[$k]['deal_user'] = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name');
  26. }
  27. }
  28. HelpHander::success($lists);
  29. }
  30. public function deal(){
  31. $res = model('PatrolTaskApply')->dealApply($this->userId,$this->orgId);
  32. if(!$res){
  33. HelpHander::error(model('PatrolTaskApply')->getError());
  34. }
  35. HelpHander::success('操作成功');
  36. }
  37. public function add(){
  38. $taskId = input('taskId/d',0);
  39. // $endTime = input('endTime','','trim');
  40. $reason = input('reason','','trim');
  41. if($taskId < 0){
  42. HelpHander::error('参数错误');
  43. }
  44. if(!$reason){
  45. HelpHander::error('未填写原因');
  46. }
  47. $task = Db::name('patrol_task')->where('org_id',$this->orgId)->where('id',$taskId)->where('del',0)->find();
  48. if(!$task || $task['patrol_mode'] != 1){
  49. HelpHander::error('参数错误');
  50. }
  51. if($task['status'] != 3){
  52. HelpHander::error('只有未完成的任务可申请');
  53. }
  54. $ret = Db::name('patrol_task_user')->where('patrol_task_id',$taskId)->where('user_id',$this->userId)->find();
  55. if(!$ret){
  56. HelpHander::error('无权限操作');
  57. }
  58. // 检测是否有正在审核中的延期申请
  59. $ret = Db::name('patrol_task_apply')->where('task_id',$taskId)->where('status',0)->find();
  60. if($ret){
  61. HelpHander::error('该任务已存在未处理的申请');
  62. }
  63. $ret = Db::name('patrol_task_apply')->insert([
  64. 'org_id' => $this->orgId,
  65. 'user_id' => $this->userId,
  66. 'task_id' => $taskId,
  67. 'reason' => $reason,
  68. 'status' => 0,
  69. 'create_time' => date('Y-m-d H:i:s'),
  70. 'patrol_mode' => 1
  71. ]);
  72. if(!$ret){
  73. HelpHander::error('操作失败');
  74. }
  75. HelpHander::success([],'操作成功');
  76. }
  77. public function userList(){
  78. $page = input('page',1);
  79. $size = input('size',20);
  80. $record = Db::name('patrol_task_apply')
  81. ->where('user_id',$this->userId)
  82. ->where('org_id',$this->orgId)
  83. ->order('id desc')
  84. ->page($page,$size)
  85. ->select();
  86. $record = $record?$record:[];
  87. foreach ($record as $k=>$v){
  88. $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title');
  89. $record[$k]['task_title'] = $taskTitle?$taskTitle:'';
  90. $uname = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  91. $record[$k]['uname'] = $uname?$uname:'';
  92. $dealUser = '';
  93. if($v['deal_user_id'] > 0){
  94. $dealUser = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name');
  95. }
  96. $record[$k]['deal_user'] = $dealUser?$dealUser:'';
  97. // $record[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
  98. $record[$k]['update_time'] = $v['update_time']?$v['update_time']:'';
  99. }
  100. HelpHander::success($record);
  101. }
  102. public function cancelApply(){
  103. $id = input('id/d',0);
  104. if($id < 0){
  105. HelpHander::error('参数错误');
  106. }
  107. $ret = Db::name('patrol_task_apply')->where('id',$id)->where('user_id',$this->userId)->find();
  108. if(!$ret){
  109. HelpHander::error('记录不存在');
  110. }
  111. if($ret['status'] != 0){
  112. HelpHander::error('申请已处理,无法取消');
  113. }
  114. $res = Db::name('patrol_task_apply')
  115. ->where('id',$id)
  116. ->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
  117. if(!$res){
  118. HelpHander::error('操作失败');
  119. }
  120. HelpHander::success([],'操作成功');
  121. }
  122. }