Blame view

application/admin/controller/antis/work/Approval.php 5.83 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  <?php
  
  namespace app\admin\controller\antis\work;
  
  use addons\antis\model\File;
  use addons\antis\model\Flow;
  use addons\antis\model\Message;
  use addons\antis\model\OperationLog;
  use app\admin\controller\antis\Base;
  use addons\antis\model\Form;
  use addons\antis\model\FormApproval;
  use addons\antis\model\Approval as ApprovalModel;
  use addons\antis\model\Staff;
  use addons\antis\model\ExamineRecord;
  use think\DB;
  use fast\Tree;
  use think\Exception;
  
  /**
   * 审批列表
   */
  class Approval extends Base {
      public function _initialize() {
          parent::_initialize();
          $this->model = new ApprovalModel();
          $form =FormApproval::where([])->select();
          $this->assign('form', $form);
      }
  
      /**
       * 审批列表
       */
      public function index() {
          $this->request->filter(['strip_tags']);
          if ($this->request->isAjax()) {
              list($where, $sort, $order, $offset, $limit) = $this->buildparams();
              $list   = $this->model->with(['formapproval','createStaff'])->where($where)->where('create_staff_id', 'in', Staff::getMyStaffIds())->order($sort, $order)->paginate($limit);
              $row    = $list->items();
              $result = array("total" => $list->total(), "rows" => $row);
  
              return json($result);
          }
  
          return $this->view->fetch();
      }
  
      /**
       * 添加审批
       */
      public function add() {
          if ($this->request->isAjax()) {
              $data = $this->request->post('row/a');
  
              Db::startTrans();
              try {
                  $formapprovals = FormApproval::where(array('id' => $data['formapproval_id']))->find();
                  $types = Form::where(array('id' => $formapprovals['form_id']))->value('type');
                  $data = Form::updateFormParams($types, $data);
                  $data['data'] = $data;
                  $result = ApprovalModel::createApproval($data);
                  Db::commit();
              } catch (Exception $e) {
                  Db::rollback();
                  $this->error($e->getMessage());
              }
              $this->success('提交成功');
          }
          $formId=input('id','');
          if(!$formId){
              $this->error('联系管理员');
          }
          $flow= Flow::getsteplist(Flow::APPROVAL_STATUS.'_'.$formId);
          if (empty($flow)) {
              $this->error('无可用审批流,请联系管理员');
          }
          $this->assign('flow',$flow);
  
          $formapproval = FormApproval::where(array('id'=>$formId))->find();
          $type = Form::where(array('id'=>$formapproval['form_id']))->value('type');
          $this->assign('form_data', Form::getDataValue($type));
          $this->assign('row', $formapproval);
          $this->assign('staff', Staff::where([])->column('name', 'id'));
          return $this->view->fetch();
      }
  
  
      /**
       * 审批详情
       */
      public function detail($ids = null) {
          $row = $this->model->where([
              'id'       => $ids
          ])->with(['createStaff'])->find();
          $row=$row->toArray();
          $row=array_merge($row,$row['content']);
          $formapproval = FormApproval::where(array('id'=>$row['formapproval_id']))->find();
          $type = Form::where(array('id'=>$formapproval['form_id']))->value('type');
  
          $form = Form::getDataValue($type,$row);
          foreach($form as $k=>$v){
              if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){
                  if(key_exists($v['id'],$row)){
                      if(isset($row[$v['id']]) && $row[$v['id']]){
                          $whereT['id'] = array('in',$row[$v['id']]);
                          $fileinfo = File::where($whereT)->field('id,name,file_path')->select();
                          if($fileinfo){
                              $row[$v['id']] = $fileinfo;
                          }
                      }
                  }
              }elseif($v['component'] == 'select'){
                  if(isset($v['config']['multiple']) &&  $v['config']['multiple'] == true){
                      if(key_exists($v['id'],$row)){
                          if(is_array($row[$v['id']]) && $row[$v['id']]){
                              $row[$v['id']] = implode(',',$row[$v['id']]);
                          }
                      }
                  }
              }
          }
  
          //审批人
          $where['id'] = array('in',$row['check_staff_ids']);
          $staff = Staff::where($where)->column('name');
          $row['staff_id'] = '';
          if($staff){
              $row['staff_id'] = implode(',',$staff);
          }
          $row['name'] = $formapproval['name'];
  
  
          $this->assign('examine_record',ExamineRecord::getList(ExamineRecord::APPROVAL_TYPE,$ids));
  
          $this->assign('flow',Flow::getstepdetail(Flow::APPROVAL_STATUS, $ids));
  
          $this->assign('form_data', $form);
          $this->assign('row', $row);
          return $this->view->fetch();
      }
  
      /**
       * 获取审批人列表
       */
      public function getstaff(){
          $pageSize = input('pageSize');
          $pageNumber = input('pageNumber');
          $where = [];
          if ($keyValue = $this->request->request("keyValue")) {
              $where['id'] = ['in',$keyValue];
          }
          $name       = input('name');
          if(!empty($name)){
              $where['name'] = ['like','%'.$name.'%'];
          }
          $staff = Staff::where($where)->where(['id'=>['neq',$this->_staff->id]])->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
          return json(['list' => $staff->items(), 'total' => $staff->total()]);
      }
  
      /**
       * 删除审批
       */
      public function del($ids = null) {
          if ($this->request->isAjax()) {
              $map['id'] = array('in', $ids);
              $result    = $this->model->destroy($map);
              if (!$result) {
                  $this->error('删除失败');
              }
              $this->success('删除成功');
          }
  
          return $this->view->fetch();
      }
  }