JianGuanBus.php 5.5 KB

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