123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace app\admin\controller\qingdongams\work;
- use addons\qingdongams\model\File;
- use addons\qingdongams\model\Flow;
- use addons\qingdongams\model\Message;
- use addons\qingdongams\model\OperationLog;
- use app\admin\controller\qingdongams\Base;
- use addons\qingdongams\model\Form;
- use addons\qingdongams\model\FormApproval;
- use addons\qingdongams\model\Approval as ApprovalModel;
- use addons\qingdongams\model\Staff;
- use addons\qingdongams\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']))->with(['form'])->find();
- $type = Form::where(array('id'=>$formapproval['form_id']))->value('type');
- $form = Form::getDataValue($type,$row);
- $content = Form::getDataDetail($formapproval['form']['type'], $row['content']);
- $row=array_merge($row,$content);
- //审批人
- $where['id'] = array('in',$row['check_staff_ids']);
- $where['status'] = 1;
- $staff = Staff::where($where)->column('name');
- $row['staff_id'] = '';
- if($staff){
- $row['staff_id'] = implode(',',$staff);
- }
- $row['name'] = $formapproval['name'];
- //标记通知已读
- Message::setRead(Message::APPROVAL_TYPE, $ids, $this->_staff->id);
- $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],'status'=>1])->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();
- }
- }
|