Run.php
6.32 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
namespace addons\fastflow\controller;
use addons\qingdong\controller\StaffApi;
use app\admin\controller\fastflow\flow\CustomMessage;
use app\admin\model\fastflow\flow\EbillCopy;
use app\admin\model\fastflow\flow\Ebill;
use app\common\controller\Backend;
use addons\fastflow\model\api;
use think\Hook;
use think\Loader;
/**
* 流程运行
*
* @icon fa fa-o
*/
class Run extends StaffApi
{
protected $model = null;
protected $noNeedLogin = ['*'];
public function _initialize()
{
Hook::add('fastflow_after_end', 'app\\admin\\behavior\\Fastflow');
$this->api = new api(new CustomMessage(), $this);
}
public function tran($params)
{
if (!isset($params['thread_id'])) {
return ['code' => 0, 'msg' => '未选择流程'];
}
$thread = (new api())->getThreadById($params['thread_id']);
// $thread = $this->api->getThreadById($thread_id);
return (new api())->tranFlow($thread,$params);
}
public function start($params)
{
if (!isset($params['flow_id'])) {
return ['code' => 0, 'msg' => '未选择流程'];
}
$startAuth = (new api())->checkStartAuth($params['flow_id']);
if (!$startAuth) {
return ['code' => 0, 'msg' => '您没有权限发起该流程审批'];
}
if ($params['ebill_id'] != '') {
//先清除之前附加的ebill
$ebill_copy_model = new EbillCopy();
$ebill_copy_model->where(['bill' => $params['bill'], "bill_id" => $params['bill_id']])->delete();
$this->appendEbill($params['bill_id'], $params['ebill_id']);
}
return $this->api->startFlow($params);
}
public function agree($params)
{
return $this->api->agreeFlow($params);
}
public function revoke($params)
{
return $this->api->revokeFlow($params);
}
public function back($params)
{
return $this->api->backFlow($params);
}
public function sign()
{
if ($this->request->isGet()) {
$thread_id = input('thread_id');
$process = $this->api->getProcess($this->api->getThreadById($thread_id)['process_id']);
$flow_id = $process['flow_id'];
$scope = $this->api->getSignScope();
$ebill_copy_id = $this->getEbillCopyId($process['bill'], $process['bill_id']);
$this->view->assign(['thread_id' => $thread_id, 'flow_id' => $flow_id, 'scope' => $scope, 'ebill_id' => $ebill_copy_id]);
$this->assignconfig([
'bill' => $process['bill'],
'bill_id' => $process['bill_id'],
'thread_id' => $thread_id,
'controller_url' => $this->getBillControllerUrl($process['bill']),
'bill_fields' => $this->getBillFields($process['bill']),
'can_edit_fields' => $this->getCanEditFields($process['bill'], $process['bill_id'], $thread_id),
'ebill_id' => $ebill_copy_id,
]);
return $this->view->fetch();
}
if ($this->request->isPost()) {
return $this->api->signFlow(input('row/a'));
}
}
public function getSelectpageWorkers()
{
return (new api())->getSelectpageWorkers();
}
public function getStartDynamicSteps()
{
return (new api())->getStartDynamicSteps();
}
private function getCanEditFields($bill, $bill_id, $thread_id = null)
{
return (new api())->getCanEditFields($bill, $bill_id, $thread_id);
}
private function getBillFields($bill)
{
return (new api())->getBillFields($bill);
}
private function getBillControllerUrl($bill)
{
$flowBillRow = (new \app\admin\model\fastflow\flow\Bill())->where(['bill_table' => $bill])->find();
$url = Loader::parseName($flowBillRow['controller'], 0);
$url = str_replace('/_', '/', $url);
return $url;
}
private function appendEbill($bill_id, $ebill_id)
{
$ebill_row = (new Ebill())->find($ebill_id)->toArray();
$ebill_copy_model = new EbillCopy();
if ($ebill_row) {
unset($ebill_row['id']);
unset($ebill_row['createtime']);
unset($ebill_row['updatetime']);
$ebill_row['bill_id'] = $bill_id;
$ebill_copy_model->insert($ebill_row);
}
}
private function getEbillCopyId($bill, $bill_id)
{
$ebill_copy = (new EbillCopy())->where(['bill' => $bill, 'bill_id' => $bill_id])->find();
if ($ebill_copy) {
$ebill_copy = $ebill_copy->toArray();
return $ebill_copy['id'];
}
return null;
}
//添加签章数据,状态0,待发起
public function addSignature()
{
$params = input('');
$bill_row = $this->api->getBillRow($params['bill'], $params['bill_id']);
return ['code' => 1, 'msg' => '操作成功'];
}
//发起审批之前回调
public function beforeStartCallback(&$params)
{
Hook::listen('fastflow_before_start', $params);
}
//发起审批之后回调
public function afterStartCallback(&$params)
{
Hook::listen('fastflow_after_start', $params);
}
//同意之前回调
public function beforeAgreeCallback(&$params)
{
Hook::listen('fastflow_before_agree', $params);
}
//同意之后回调
public function afterAgreeCallback(&$params)
{
Hook::listen('fastflow_after_agree', $params);
}
//驳回之前回调
public function beforeBackCallback(&$params)
{
Hook::listen('fastflow_before_back', $params);
}
//驳回之后回调
public function afterBackCallback(&$params)
{
Hook::listen('fastflow_after_back', $params);
}
//会签之前回调
public function beforeSignCallback(&$params)
{
Hook::listen('fastflow_before_sign', $params);
}
//会签之后回调
public function afterSignCallback(&$params)
{
Hook::listen('fastflow_after_sign', $params);
}
//结束之前回调
public function beforeEndCallback(&$params)
{
Hook::listen('fastflow_before_end', $params);
}
//结束之后回调
public function afterEndCallback(&$params)
{
// halt(123);
Hook::listen('fastflow_after_end', $params);
}
}