JianGuanBus.php 5.0 KB

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