Blame view

application/admin/controller/antis/work/Formapproval.php 4.19 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
  <?php
  
  namespace app\admin\controller\antis\work;
  
  use app\common\controller\Backend;
  use addons\antis\model\Form;
  use addons\antis\model\Staff;
  use addons\antis\model\FormApproval as FormApprovalModel;
  use think\Db;
  use think\Exception;
  use addons\antis\library\Pingyin;
  
  /**
   * 审批字段管理
   */
  class Formapproval extends Backend {
  	protected $relationSearch = true;
  
      /**
       * @var \addons\antis\model\FormApproval
       */
  	protected $model = null;
  
  
  	public function _initialize() {
  		parent::_initialize();
  		$this->model = new FormApprovalModel();
  	}
  
  
  	/**
  	 * 查看
  	 */
  	public function index() {
  		//设置过滤方法
  		$this->request->filter(['strip_tags', 'trim']);
  		if ($this->request->isAjax()) {
  
  			$forms = $this->model->where([])->select();
  			$forms = collection($forms)->toArray();
  
  
  			$result = array("total" => count($forms), "rows" => $forms);
  
  			return json($result);
  		}
  
  		return $this->view->fetch();
  	}
  
      /**
       * 添加审批流程
       */
  	public function add() {
  		if ($this->request->isAjax()) {
  			$data             = $this->request->post('row/a');
  			if(!$data['name']){
                  $this->error('审批流程标题不能为空');
              }
              $pingyin = new Pingyin();
  			$english = $pingyin->get_all_py($data['name']);
  			$formFind = Form::where(array('type'=>$english))->find();
  			if($formFind){
                  $english = $english.genRandomString(5);
              }
  			//表单
              $formRes = array(
                  'name'=>$data['name'],
                  'type'=>$english,
              );
  			$resForm = Form::create($formRes);
              $insetId = Form::getLastInsID();
              $data['form_id'] = $insetId;
  
  			$result           = $this->model->allowField(true)->save($data);
  			if (!$result || !$resForm) {
  				$this->error('提交失败');
  			}
  			$this->success('提交成功');
  		}
  		$staffname = Staff::where(['status' => 1])->column('id,name');
  		$staffs    = ['' => '无'];
  		foreach ($staffname as $id => $name) {
  			$staffs[$id] = $name;
  		}
  		$this->view->assign('staffs', $staffs);
  
  		return $this->view->fetch();
  	}
  
  
      /**
       * 修改审批流程
       */
  	public function edit($ids = null) {
          $row=$this->model->get($ids);
          if ($this->request->isAjax()) {
              $data             = $this->request->post('row/a');
              $result           = $this->model->allowField(true)->save($data,['id'=>$ids]);
              if($row['form_id']){
                  Form::where(array('id'=>$row['form_id']))->update(array('name'=>$data['name']));
              }
              if (!$result) {
                  $this->error('提交失败');
              }
              $this->success('提交成功');
          }
          $staffname = Staff::where(['status' => 1])->column('id,name');
          $staffs    = ['' => '无'];
          foreach ($staffname as $id => $name) {
              $staffs[$id] = $name;
          }
          $this->view->assign('staffs', $staffs);
          $this->view->assign('row', $row);
          return $this->view->fetch();
  	}
      /**
       * 删除审批流程
       */
      public function del($ids = null) {
          if ($this->request->isAjax()) {
              $map['id'] = $ids;
              $row=$this->model->get($ids);
              if(!$row){
                  $this->error('数据不存在');
              }
              Form::destroy(array('id'=>$row['form_id']));
              $result    = $this->model->destroy($map);
              if (!$result) {
                  $this->error('删除失败');
              }
              $this->success('删除成功');
          }
  
          return $this->view->fetch();
      }
  
      /**
       * 获取员工列表
       */
      public function get_staff()
      {
  
          $pageSize = input('pageSize');
          $pageNumber = input('pageNumber');
          $where = [];
          if ($keyValue = $this->request->request("keyValue")) {
              $where['id'] = ['in',explode(',',$keyValue)];
          }
          $name = input('name');
          if (!empty($name)) {
              $where['name'] = ['like', '%' . $name . '%'];
          }
          $customer = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
          return json(['list' => $customer->items(), 'total' => $customer->total()]);
      }
  }