Approval.php 5.4 KB

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