JianGuanBus.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\api\business;
  3. use app\api\exception\ApiException;
  4. use app\api\model\Ccjc;
  5. use app\api\model\Orgs;
  6. use app\common\lib\auth\JwtAuth;
  7. class JianGuanBus
  8. {
  9. private $rymc;
  10. public function __construct()
  11. {
  12. $jwtAuth=JwtAuth::getInstance(); //实例化jwtAuth
  13. $this->rymc = $jwtAuth->getRymc(); //setRybh是在middleware/jwtAuth中完成的
  14. }
  15. //查询任务列表数据
  16. public function selectTask($data)
  17. {
  18. //如果需要查询的字段不为空就push一个查询条件
  19. $where=[];//初始化$where
  20. //任务年度
  21. if ($data['year']!='') array_push($where, ['year', '=', $data['year']]);
  22. //任务状态:0:未发布,1:执行中,2:已结束未完成,3:已结束已完成
  23. if ($data['ispublic'] != '') array_push($where, ['ispublic', '=', $data['ispublic']]);
  24. //任务开始时间
  25. if ($data['starttime'] != '') array_push($where, ['starttime', '>=', $data['starttime']]);
  26. //任务结束时间
  27. if ($data['endtime'] != '') array_push($where, ['endtime', '<=', $data['endtime']]);
  28. //任务分类:例行or专项
  29. if ($data['task_class'] != '') array_push($where, ['task_class', '=', $data['task_class']]);
  30. //任务名称:模糊查询
  31. if ($data['task_name'] != '' ) array_push($where, ['task_name', 'LIKE', '%'.$data['task_name'].'%']);
  32. $result = (new Ccjc())->getInfoByTaskClass($where,(int)$data['pageNum'],(int)$data['pageSize'])->toArray();
  33. $count = (new Ccjc())->getInfoListCount($where);
  34. return ['rows'=>$result, 'total'=>$count,];
  35. }
  36. //创建任务
  37. public function createTask($data,$orgs_data)
  38. {
  39. $data['creater'] = $this->rymc;
  40. //创建任务
  41. $task_id = (new Ccjc())->createTask($data);
  42. for($i=0;$i<count($orgs_data);$i++){
  43. $orgs[$i]['task_id']=$task_id;
  44. $orgs[$i]['unit_id']=$orgs_data[$i]['id'];
  45. $orgs[$i]['unit_name']=$orgs_data[$i]['name'];
  46. }
  47. $result = (new Orgs())->createOrgsInfo($orgs);
  48. return $result;
  49. }
  50. //删除任务
  51. public function deleteTaskItem($data,$data_count)
  52. {
  53. for ($i = 0; $i < $data_count; $i++) {
  54. //从数据库中查询选取的数据
  55. $task_info[$i] = (new Ccjc())->getTaskInfoByTaskID($data[$i]['id']);
  56. }
  57. //将数据库中的数据和选取的数据进行校验
  58. for ($i = 0; $i < $data_count; $i++) {
  59. //如果查询结果存在null值,则未选取有效数据
  60. if ($task_info[$i] == null) {
  61. throw new ApiException(config('status.none_data'));
  62. }
  63. //判断操作者是否具有操作权限(是否为创建者)
  64. if ($task_info[$i]['creater'] != $this->rymc) {
  65. throw new ApiException(config('status.none_authority'));
  66. }
  67. }
  68. //进行删除操作
  69. for ($i = 0; $i < $data_count; $i++) {
  70. $result[$i] = (new Ccjc())->deleteItemById($data[$i]['id']);//删除的结果为布尔值
  71. }
  72. //检查删除结果是否都为真
  73. for ($i = 0; $i < $data_count; $i++) {
  74. if ($result[$i] != 1) {
  75. throw new ApiException(config('status.data_abnormal'));
  76. }
  77. }
  78. return '成功删除'."$data_count".'条数据';
  79. }
  80. //修改任务发布状态(发布/废止)
  81. public function updateTaskUpdateInfo($data,$data_count)
  82. {
  83. //从数据库中获取任务信息
  84. for ($i = 0; $i < $data_count; $i++) {
  85. $task[$i]=(new Ccjc())->getTaskInfoByTaskID($data[$i]['id'])->toArray();
  86. }
  87. //是否发布,0:未发布,1:已发布,2:废止;3:已结束未完成;4:已结束已完成;5:执行中
  88. for ($i = 0; $i < $data_count; $i++) {
  89. //只有未发布的,状态可以变成发布(0->1)
  90. if ($data[$i]['ispublic']==1 && $task[$i]['ispublic'] != 0) {
  91. throw new ApiException(config('status.err_enPublic_status'));//当前任务不可发布
  92. }
  93. //只已发布的,状态可以变成废止(1->2)
  94. if ($data[$i]['ispublic'] == 2 && $task[$i]['ispublic'] != 1) {
  95. throw new ApiException(config('status.err_disPublic_status'));//当前任务不可废止
  96. }
  97. //只有创建者creater是当前操作员才可以发布
  98. if ($task[$i]['creater'] != $this->rymc) {
  99. throw new ApiException(config('status.none_authority'));//无权操作此项数据
  100. }
  101. }
  102. //将releaser赋值为当前操作者的人员名称
  103. for ($i = 0; $i < $data_count; $i++) {
  104. $data[$i]['releaser'] = $this->rymc;
  105. }
  106. //写入数据库
  107. $result = (new Ccjc())->updateTaskByArrCondition($data);
  108. return $result;
  109. }
  110. }