123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace app\api\business;
- use app\api\exception\ApiException;
- use app\api\model\Ccjc;
- use app\api\model\Orgs;
- use app\common\lib\auth\JwtAuth;
- class JianGuanBus
- {
- private $rymc;
- public function __construct()
- {
- $jwtAuth=JwtAuth::getInstance(); //实例化jwtAuth
- $this->rymc = $jwtAuth->getRymc(); //setRybh是在middleware/jwtAuth中完成的
- }
- //查询任务列表数据
- public function selectTask($data)
- {
- //如果需要查询的字段不为空就push一个查询条件
- $where=[];//初始化$where
- //任务年度
- if ($data['year']!='') array_push($where, ['year', '=', $data['year']]);
- //任务状态:0:未发布,1:执行中,2:已结束未完成,3:已结束已完成
- if ($data['ispublic'] != '') array_push($where, ['ispublic', '=', $data['ispublic']]);
- //任务开始时间
- if ($data['starttime'] != '') array_push($where, ['starttime', '>=', $data['starttime']]);
- //任务结束时间
- if ($data['endtime'] != '') array_push($where, ['endtime', '<=', $data['endtime']]);
- //任务分类:例行or专项
- if ($data['task_class'] != '') array_push($where, ['task_class', '=', $data['task_class']]);
- //任务名称:模糊查询
- if ($data['task_name'] != '' ) array_push($where, ['task_name', 'LIKE', '%'.$data['task_name'].'%']);
- $result = (new Ccjc())->getInfoByTaskClass($where,(int)$data['pageNum'],(int)$data['pageSize'])->toArray();
- $count = (new Ccjc())->getInfoListCount($where);
- return ['rows'=>$result, 'total'=>$count,];
- }
- //创建任务
- public function createTask($data,$orgs_data)
- {
- $data['creater'] = $this->rymc;
- //创建任务
- $task_id = (new Ccjc())->createTask($data);
- for($i=0;$i<count($orgs_data);$i++){
- $orgs[$i]['task_id']=$task_id;
- $orgs[$i]['unit_id']=$orgs_data[$i]['id'];
- $orgs[$i]['unit_name']=$orgs_data[$i]['name'];
- }
- $result = (new Orgs())->createOrgsInfo($orgs);
- return $result;
- }
- //删除任务
- public function deleteTaskItem($data,$data_count)
- {
- for ($i = 0; $i < $data_count; $i++) {
- //从数据库中查询选取的数据
- $task_info[$i] = (new Ccjc())->getTaskInfoByTaskID($data[$i]['id']);
- }
- //将数据库中的数据和选取的数据进行校验
- for ($i = 0; $i < $data_count; $i++) {
- //如果查询结果存在null值,则未选取有效数据
- if ($task_info[$i] == null) {
- throw new ApiException(config('status.none_data'));
- }
- //判断操作者是否具有操作权限(是否为创建者)
- if ($task_info[$i]['creater'] != $this->rymc) {
- throw new ApiException(config('status.none_authority'));
- }
- }
- //进行删除操作
- for ($i = 0; $i < $data_count; $i++) {
- $result[$i] = (new Ccjc())->deleteItemById($data[$i]['id']);//删除的结果为布尔值
- }
- //检查删除结果是否都为真
- for ($i = 0; $i < $data_count; $i++) {
- if ($result[$i] != 1) {
- throw new ApiException(config('status.data_abnormal'));
- }
- }
- return '成功删除'."$data_count".'条数据';
- }
- //修改任务发布状态(发布/废止)
- public function updateTaskUpdateInfo($data,$data_count)
- {
- //从数据库中获取任务信息
- for ($i = 0; $i < $data_count; $i++) {
- $task[$i]=(new Ccjc())->getTaskInfoByTaskID($data[$i]['id'])->toArray();
- }
- //是否发布,0:未发布,1:已发布,2:废止;3:已结束未完成;4:已结束已完成;5:执行中
- for ($i = 0; $i < $data_count; $i++) {
- //只有未发布的,状态可以变成发布(0->1)
- if ($data[$i]['ispublic']==1 && $task[$i]['ispublic'] != 0) {
- throw new ApiException(config('status.err_enPublic_status'));//当前任务不可发布
- }
- //只已发布的,状态可以变成废止(1->2)
- if ($data[$i]['ispublic'] == 2 && $task[$i]['ispublic'] != 1) {
- throw new ApiException(config('status.err_disPublic_status'));//当前任务不可废止
- }
- //只有创建者creater是当前操作员才可以发布
- if ($task[$i]['creater'] != $this->rymc) {
- throw new ApiException(config('status.none_authority'));//无权操作此项数据
- }
- }
- //将releaser赋值为当前操作者的人员名称
- for ($i = 0; $i < $data_count; $i++) {
- $data[$i]['releaser'] = $this->rymc;
- }
- //写入数据库
- $result = (new Ccjc())->updateTaskByArrCondition($data);
- return $result;
- }
- }
|