From 07af16ed9d5b11a378807fca8c1fe9d2c1f1787c Mon Sep 17 00:00:00 2001 From: mzl Date: Wed, 24 Sep 2025 15:24:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=9F=BA=E7=B1=BB=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=90=8E=E7=BD=AE=E6=96=B9=E6=B3=95&&=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=BD=AC=E4=BA=A4=E3=80=81=E4=B8=9A=E5=8A=A1=E5=8D=95?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApprovalRecordsController.php | 30 ++++++++ app/common/service/ApprovalRecordsService.php | 63 ++++++++++++++++ app/common/service/PurchaseOrdersService.php | 75 +++++++++++++++++-- app/common/traits/crud/CrudServiceTrait.php | 11 ++- .../approval/service/ApprovalFlowService.php | 2 +- config/route.php | 2 + 6 files changed, 173 insertions(+), 10 deletions(-) diff --git a/app/admin/controller/ApprovalRecordsController.php b/app/admin/controller/ApprovalRecordsController.php index c7a6b30..95bd2b6 100644 --- a/app/admin/controller/ApprovalRecordsController.php +++ b/app/admin/controller/ApprovalRecordsController.php @@ -114,6 +114,7 @@ class ApprovalRecordsController extends BaseController 'biz_id' => $record['instance']['biz_id'], 'biz_desc' => '业务单号【'.$record['instance']['bizInfo']['order_no'].'】', 'biz_type' => $record['instance']['flow_type'], + 'flow_type' => $record['instance']['flow_type'], 'initiator_name' => $record['instance']['initiator']['name'], 'initiator_avatar' => $record['instance']['initiator']['avatar'], @@ -139,4 +140,33 @@ class ApprovalRecordsController extends BaseController } 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()); + } + } } \ No newline at end of file diff --git a/app/common/service/ApprovalRecordsService.php b/app/common/service/ApprovalRecordsService.php index 8fc6aff..2704ac8 100644 --- a/app/common/service/ApprovalRecordsService.php +++ b/app/common/service/ApprovalRecordsService.php @@ -95,6 +95,24 @@ class ApprovalRecordsService $config['where']['instance_id'] = $p['instance_id']; $config['order']['id'] = 'desc'; 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; @@ -115,4 +133,49 @@ class ApprovalRecordsService $item = $this->logicListAll($config); 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; + } } \ No newline at end of file diff --git a/app/common/service/PurchaseOrdersService.php b/app/common/service/PurchaseOrdersService.php index 54be28b..75b53a5 100644 --- a/app/common/service/PurchaseOrdersService.php +++ b/app/common/service/PurchaseOrdersService.php @@ -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) { - // if ($res->status == 1) { - // $this->startApproval($res, ['resubmitted'=>0]); - // } - - $this->startApproval($res, ['resubmitted'=>0]); + if ($res->status == 1) { + $this->startApproval($res, ['resubmitted'=>0]); + } return $res; } @@ -227,6 +225,28 @@ class PurchaseOrdersService $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 = []) { @@ -271,4 +291,47 @@ class PurchaseOrdersService $info->status = $data['status']; 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; + } } \ No newline at end of file diff --git a/app/common/traits/crud/CrudServiceTrait.php b/app/common/traits/crud/CrudServiceTrait.php index eb563fe..d956cad 100644 --- a/app/common/traits/crud/CrudServiceTrait.php +++ b/app/common/traits/crud/CrudServiceTrait.php @@ -175,9 +175,14 @@ trait CrudServiceTrait protected function postProcess(string $op, mixed $data): mixed { $hook = "afterService{$op}"; - return method_exists($this, $hook) - ? $this->{$hook}($data) - : $data; + if (method_exists($this, $hook)) { + $args = func_get_args(); + array_shift($args); + array_shift($args); + $params = array_merge([$data], $args); + return call_user_func_array([$this, $hook], $params); + } + return $data; } /** diff --git a/app/common/utils/approval/service/ApprovalFlowService.php b/app/common/utils/approval/service/ApprovalFlowService.php index 6f878b3..a97e5ea 100644 --- a/app/common/utils/approval/service/ApprovalFlowService.php +++ b/app/common/utils/approval/service/ApprovalFlowService.php @@ -155,7 +155,7 @@ class ApprovalFlowService } // 3) 有结论:关闭本步其余 pending - $this->closeOtherPending($instanceId, $idx, [$approverId]); + $this->closeOtherPending($instanceId, $round, $idx, [$approverId]); // 4) 拒绝 => 结束 if ($outcome === 'reject') { diff --git a/config/route.php b/config/route.php index 6f42d42..4f26a64 100644 --- a/config/route.php +++ b/config/route.php @@ -317,6 +317,8 @@ Route::group('/admin', function () { Route::any('/action', [app\admin\controller\ApprovalRecordsController::class, 'approve']); 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 () {