调整基类更新后置方法&&增加转交、业务单详情
This commit is contained in:
@@ -114,6 +114,7 @@ class ApprovalRecordsController extends BaseController
|
|||||||
'biz_id' => $record['instance']['biz_id'],
|
'biz_id' => $record['instance']['biz_id'],
|
||||||
'biz_desc' => '业务单号【'.$record['instance']['bizInfo']['order_no'].'】',
|
'biz_desc' => '业务单号【'.$record['instance']['bizInfo']['order_no'].'】',
|
||||||
'biz_type' => $record['instance']['flow_type'],
|
'biz_type' => $record['instance']['flow_type'],
|
||||||
|
'flow_type' => $record['instance']['flow_type'],
|
||||||
|
|
||||||
'initiator_name' => $record['instance']['initiator']['name'],
|
'initiator_name' => $record['instance']['initiator']['name'],
|
||||||
'initiator_avatar' => $record['instance']['initiator']['avatar'],
|
'initiator_avatar' => $record['instance']['initiator']['avatar'],
|
||||||
@@ -139,4 +140,33 @@ class ApprovalRecordsController extends BaseController
|
|||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function businessOrder(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$raw = $this->service->serviceBusinessOrder($request, $request->all());
|
||||||
|
$data = $this->transformData($raw, method_exists($this, 'borderFormat')
|
||||||
|
? [$this, 'borderFormat']
|
||||||
|
: null);
|
||||||
|
return $this->success($data);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function transferApproval(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$raw = $this->service->transferApproval($request, $request->all());
|
||||||
|
$data = $this->transformData($raw, method_exists($this, 'transferFormat')
|
||||||
|
? [$this, 'transferFormat']
|
||||||
|
: null);
|
||||||
|
return $this->success($data);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -95,6 +95,24 @@ class ApprovalRecordsService
|
|||||||
$config['where']['instance_id'] = $p['instance_id'];
|
$config['where']['instance_id'] = $p['instance_id'];
|
||||||
$config['order']['id'] = 'desc';
|
$config['order']['id'] = 'desc';
|
||||||
break;
|
break;
|
||||||
|
case 'border':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
$config['order']['id'] = 'desc';
|
||||||
|
$config['with'] = [
|
||||||
|
'instance',
|
||||||
|
'approver',
|
||||||
|
'instance.flows',
|
||||||
|
'instance.initiator',
|
||||||
|
'instance.bizInfo',
|
||||||
|
|
||||||
|
// 'instance.bizInfo.items',
|
||||||
|
// 'instance.bizInfo.items.options',
|
||||||
|
// 'instance.bizInfo.items.moneyValues',
|
||||||
|
// 'instance.bizInfo.accounts',
|
||||||
|
// 'instance.bizInfo.moneyValues',
|
||||||
|
// 'instance.bizInfo.salesperson',
|
||||||
|
];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
@@ -115,4 +133,49 @@ class ApprovalRecordsService
|
|||||||
$item = $this->logicListAll($config);
|
$item = $this->logicListAll($config);
|
||||||
return $this->postProcess('Logs', $item);
|
return $this->postProcess('Logs', $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function serviceBusinessOrder(Request $request, array $data = [])
|
||||||
|
{
|
||||||
|
$config = $this->buildQueryConfig($request, 'border');
|
||||||
|
$config = $this->borderConfig($config, $data['flow_type']);
|
||||||
|
$item = $this->logicShow($config);
|
||||||
|
$bizInfo = [];
|
||||||
|
$service = match ($data['flow_type']) {
|
||||||
|
'stock_orders' => new \app\common\service\StockOrdersService(),
|
||||||
|
'purchase_orders' => new \app\common\service\PurchaseOrdersService(),
|
||||||
|
default => new \app\common\service\StockOrdersService()
|
||||||
|
};
|
||||||
|
$bizInfo = $service->formatData($item->instance->bizInfo);
|
||||||
|
return $this->postProcess('Border', $bizInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function borderConfig($config, $type = 'stock_orders')
|
||||||
|
{
|
||||||
|
$with = match ($type) {
|
||||||
|
'stock_orders' => [
|
||||||
|
'instance.bizInfo.items',
|
||||||
|
'instance.bizInfo.items.options',
|
||||||
|
'instance.bizInfo.items.moneyValues',
|
||||||
|
'instance.bizInfo.accounts',
|
||||||
|
'instance.bizInfo.moneyValues',
|
||||||
|
'instance.bizInfo.salesperson',
|
||||||
|
],
|
||||||
|
'purchase_orders' => [
|
||||||
|
'instance.bizInfo.items',
|
||||||
|
'instance.bizInfo.items.stockOrder',
|
||||||
|
'instance.bizInfo.items.stockOrderItems'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
$config['with'] = array_merge($config['with'], $with);
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function transferApproval(Request $request, array $data = [])
|
||||||
|
{
|
||||||
|
$service = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||||
|
$result = $service->transferApproval($data['instance_id'], $data['step_index'], $request->user->uid, $data['to_uid'], $data['reason'], 'name');
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ class PurchaseOrdersService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->postProcess(ucfirst($scene), $order);
|
return $this->postProcess(ucfirst($scene), $order, ['is_resubmit'=>$data['is_resubmit']]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,11 +213,9 @@ class PurchaseOrdersService
|
|||||||
*/
|
*/
|
||||||
protected function afterServiceStore($res)
|
protected function afterServiceStore($res)
|
||||||
{
|
{
|
||||||
// if ($res->status == 1) {
|
if ($res->status == 1) {
|
||||||
// $this->startApproval($res, ['resubmitted'=>0]);
|
$this->startApproval($res, ['resubmitted'=>0]);
|
||||||
// }
|
}
|
||||||
|
|
||||||
$this->startApproval($res, ['resubmitted'=>0]);
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +225,28 @@ class PurchaseOrdersService
|
|||||||
$appro->start('purchase_orders', 'purchase_orders', $item->id, ['resubmitted'=>0], $item->buyer_id);
|
$appro->start('purchase_orders', 'purchase_orders', $item->id, ['resubmitted'=>0], $item->buyer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function afterServiceUpdate($res, $data)
|
||||||
|
{
|
||||||
|
if ($data['is_resubmit'] == 0 && $res->status == 1) {
|
||||||
|
$this->startApproval($res);
|
||||||
|
}
|
||||||
|
if ($data['is_resubmit'] == 1) {
|
||||||
|
$instance = \app\common\model\ApprovalInstances::where('biz_id', $res->id)->where('flow_type', 'purchase_orders')->first();
|
||||||
|
if ( $instance === null) {
|
||||||
|
throw new BusinessException('未找到审批实例');
|
||||||
|
}
|
||||||
|
// 审批服务
|
||||||
|
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||||
|
// 重新提交
|
||||||
|
$appro->resubmit($instance->id, $instance->initiator_id, ['resubmitted'=>1], $data['remark']);
|
||||||
|
// 添加到讨论
|
||||||
|
if (!empty($data['remark'])) {
|
||||||
|
$appro->postDiscussion($instance->id, $instance->initiator_id, $data['remark'], false, [], 'name');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function serviceResubmit(Request $request, array $data = [])
|
public function serviceResubmit(Request $request, array $data = [])
|
||||||
{
|
{
|
||||||
@@ -271,4 +291,47 @@ class PurchaseOrdersService
|
|||||||
$info->status = $data['status'];
|
$info->status = $data['status'];
|
||||||
return $info->save();
|
return $info->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function formatData($data)
|
||||||
|
{
|
||||||
|
$contractFile = $data['contract_file'] ? explode(',', $data['contract_file']) : [];
|
||||||
|
$contractFileUrl = [];
|
||||||
|
if (count($contractFile) > 0) {
|
||||||
|
foreach ($contractFile as $file) {
|
||||||
|
$contractFileUrl[] = (new \app\common\service\OssService)->generatePrivateUrl($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = [
|
||||||
|
'id' => $data['id'],
|
||||||
|
'order_no' => $data['order_no'],
|
||||||
|
'pi_no' => $data['pi_no'],
|
||||||
|
'buyer_id' => $data['buyer_id'],
|
||||||
|
'buyer_name' => $data['buyer_name'],
|
||||||
|
'contract_file' => $contractFile,
|
||||||
|
'contract_file_url' => $contractFileUrl,
|
||||||
|
'status' => $data['status'],
|
||||||
|
'remark' => $data['remark']
|
||||||
|
];
|
||||||
|
$temps = [];
|
||||||
|
if (isset($data['items']) && count($data['items']) > 0) {
|
||||||
|
foreach ($data['items'] as $record) {
|
||||||
|
if (!in_array($record['stockOrder']['id'], array_keys($temps))) {
|
||||||
|
$temps[$record['stockOrder']['id']] = [
|
||||||
|
'id' => $record['stockOrder']['id'],
|
||||||
|
'order_no' => $record['stockOrder']['order_no'],
|
||||||
|
'salesperson_snapshot' => $record['stockOrder']['salesperson_snapshot'],
|
||||||
|
'biz_date' => date('Y-m-d', $record['stockOrder']['biz_date'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$temps[$record['stockOrder']['id']]['stock_order_items'][] =[
|
||||||
|
'id' => $record['stockOrderItems']['id'],
|
||||||
|
'model_snapshot' => $record['stockOrderItems']['model_snapshot'],
|
||||||
|
'unique_id' => $record['stockOrderItems']['unique_id'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result['stock_order'] = array_values($temps);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -175,9 +175,14 @@ trait CrudServiceTrait
|
|||||||
protected function postProcess(string $op, mixed $data): mixed
|
protected function postProcess(string $op, mixed $data): mixed
|
||||||
{
|
{
|
||||||
$hook = "afterService{$op}";
|
$hook = "afterService{$op}";
|
||||||
return method_exists($this, $hook)
|
if (method_exists($this, $hook)) {
|
||||||
? $this->{$hook}($data)
|
$args = func_get_args();
|
||||||
: $data;
|
array_shift($args);
|
||||||
|
array_shift($args);
|
||||||
|
$params = array_merge([$data], $args);
|
||||||
|
return call_user_func_array([$this, $hook], $params);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ class ApprovalFlowService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3) 有结论:关闭本步其余 pending
|
// 3) 有结论:关闭本步其余 pending
|
||||||
$this->closeOtherPending($instanceId, $idx, [$approverId]);
|
$this->closeOtherPending($instanceId, $round, $idx, [$approverId]);
|
||||||
|
|
||||||
// 4) 拒绝 => 结束
|
// 4) 拒绝 => 结束
|
||||||
if ($outcome === 'reject') {
|
if ($outcome === 'reject') {
|
||||||
|
|||||||
@@ -317,6 +317,8 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/action', [app\admin\controller\ApprovalRecordsController::class, 'approve']);
|
Route::any('/action', [app\admin\controller\ApprovalRecordsController::class, 'approve']);
|
||||||
|
|
||||||
Route::any('/todo', [app\admin\controller\ApprovalRecordsController::class, 'todo']);
|
Route::any('/todo', [app\admin\controller\ApprovalRecordsController::class, 'todo']);
|
||||||
|
Route::any('/border', [app\admin\controller\ApprovalRecordsController::class, 'businessOrder']);
|
||||||
|
Route::any('/transfer', [app\admin\controller\ApprovalRecordsController::class, 'transferApproval']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group('/stock/order', function () {
|
Route::group('/stock/order', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user