From e5441d51aebd3dbe7851a3dfc94758b5b6b3328f Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 18 Sep 2025 06:46:15 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A1=E6=89=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApprovalFlowsController.php | 2 +- .../ApprovalInstancesController.php | 2 +- .../controller/ApprovalRecordsController.php | 72 ++++++- app/admin/logic/ApprovalInstancesLogic.php | 17 -- app/admin/logic/ApprovalRecordsLogic.php | 17 -- app/admin/model/ApprovalFlows.php | 54 ----- app/admin/model/ApprovalInstances.php | 107 ---------- app/admin/model/ApprovalRecords.php | 84 -------- .../logic/ApprovalFlowsLogic.php | 4 +- .../logic/ApprovalInstancesLogic.php | 4 +- .../logic/ApprovalRecordsLogic.php | 4 +- .../approval => }/model/ApprovalCcs.php | 4 +- app/{crm => common}/model/ApprovalFlows.php | 5 +- .../model/ApprovalInstances.php | 36 ++-- app/{crm => common}/model/ApprovalRecords.php | 20 +- .../service/ApprovalFlowsService.php | 6 +- .../service/ApprovalInstancesService.php | 6 +- .../service/ApprovalRecordsService.php | 41 +++- .../service/MessageNotificationsService.php | 2 +- .../service/MessageUserStatusService.php | 2 +- app/common/service/ResourceService.php | 2 +- app/common/service/SysDictService.php | 10 +- app/common/traits/crud/CrudServiceTrait.php | 69 ++++--- .../traits/crud/CrudServiceTrait_bak.php | 194 ++++++++++++++++++ .../utils/approval/model/ApprovalFlows.php | 49 ----- .../approval/model/ApprovalInstances.php | 49 ----- .../utils/approval/model/ApprovalRecords.php | 49 ----- .../approval/service/ApprovalFlowService.php | 3 +- .../validate/ApprovalFlowsValidate.php | 2 +- .../validate/ApprovalInstancesValidate.php | 2 +- .../validate/ApprovalRecordsValidate.php | 2 +- app/controller/IndexController.php | 47 ----- .../controller/ApprovalFlowsController.php | 2 +- .../ApprovalInstancesController.php | 2 +- .../controller/ApprovalRecordsController.php | 56 ++++- app/crm/logic/ApprovalFlowsLogic.php | 17 -- app/crm/service/ApprovalFlowsService.php | 31 --- app/crm/service/ApprovalInstancesService.php | 31 --- app/crm/service/ApprovalRecordsService.php | 91 -------- config/route.php | 4 + 40 files changed, 440 insertions(+), 761 deletions(-) delete mode 100644 app/admin/logic/ApprovalInstancesLogic.php delete mode 100644 app/admin/logic/ApprovalRecordsLogic.php delete mode 100644 app/admin/model/ApprovalFlows.php delete mode 100644 app/admin/model/ApprovalInstances.php delete mode 100644 app/admin/model/ApprovalRecords.php rename app/{admin => common}/logic/ApprovalFlowsLogic.php (77%) rename app/{crm => common}/logic/ApprovalInstancesLogic.php (76%) rename app/{crm => common}/logic/ApprovalRecordsLogic.php (77%) rename app/common/{utils/approval => }/model/ApprovalCcs.php (91%) rename app/{crm => common}/model/ApprovalFlows.php (93%) rename app/{crm => common}/model/ApprovalInstances.php (87%) rename app/{crm => common}/model/ApprovalRecords.php (74%) rename app/{admin => common}/service/ApprovalFlowsService.php (91%) rename app/{admin => common}/service/ApprovalInstancesService.php (78%) rename app/{admin => common}/service/ApprovalRecordsService.php (62%) create mode 100644 app/common/traits/crud/CrudServiceTrait_bak.php delete mode 100644 app/common/utils/approval/model/ApprovalFlows.php delete mode 100644 app/common/utils/approval/model/ApprovalInstances.php delete mode 100644 app/common/utils/approval/model/ApprovalRecords.php rename app/{admin => common}/validate/ApprovalFlowsValidate.php (91%) rename app/{admin => common}/validate/ApprovalInstancesValidate.php (91%) rename app/{admin => common}/validate/ApprovalRecordsValidate.php (91%) delete mode 100644 app/crm/logic/ApprovalFlowsLogic.php delete mode 100644 app/crm/service/ApprovalFlowsService.php delete mode 100644 app/crm/service/ApprovalInstancesService.php delete mode 100644 app/crm/service/ApprovalRecordsService.php diff --git a/app/admin/controller/ApprovalFlowsController.php b/app/admin/controller/ApprovalFlowsController.php index c2babff..ec9bb60 100644 --- a/app/admin/controller/ApprovalFlowsController.php +++ b/app/admin/controller/ApprovalFlowsController.php @@ -3,7 +3,7 @@ namespace app\admin\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; -use app\admin\service\ApprovalFlowsService; +use app\common\service\ApprovalFlowsService; class ApprovalFlowsController extends BaseController { diff --git a/app/admin/controller/ApprovalInstancesController.php b/app/admin/controller/ApprovalInstancesController.php index 483ec40..c7bf7fb 100644 --- a/app/admin/controller/ApprovalInstancesController.php +++ b/app/admin/controller/ApprovalInstancesController.php @@ -3,7 +3,7 @@ namespace app\admin\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; -use app\admin\service\ApprovalInstancesService; +use app\common\service\ApprovalInstancesService; class ApprovalInstancesController extends BaseController { diff --git a/app/admin/controller/ApprovalRecordsController.php b/app/admin/controller/ApprovalRecordsController.php index 1bf914e..2506845 100644 --- a/app/admin/controller/ApprovalRecordsController.php +++ b/app/admin/controller/ApprovalRecordsController.php @@ -3,8 +3,7 @@ namespace app\admin\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; -use app\admin\service\ApprovalRecordsService; -use app\admin\service\SysDictService; +use app\common\service\ApprovalRecordsService; use app\common\model\SysDictItem; use support\Request; @@ -31,16 +30,16 @@ class ApprovalRecordsController extends BaseController foreach ($data['records'] as $key => &$record) { $result = [ 'id' => $record['id'], - 'flows_name' => $record['approvalInstance']['flows']['name'], + 'flows_name' => $record['instance']['flows']['name'], 'instance_id' => $record['instance_id'], - 'biz_id' => $record['approvalInstance']['biz_id'], - 'biz_desc' => '备货单【'.$record['approvalInstance']['bizInfo']['order_no'].'】', - 'biz_type' => $record['approvalInstance']['flow_type'], + 'biz_id' => $record['instance']['biz_id'], + 'biz_desc' => '备货单【'.$record['instance']['bizInfo']['order_no'].'】', + 'biz_type' => $record['instance']['flow_type'], - 'initiator_name' => $record['approvalInstance']['initiator']['name'], - 'initiator_avatar' => $record['approvalInstance']['initiator']['avatar'], + 'initiator_name' => $record['instance']['initiator']['name'], + 'initiator_avatar' => $record['instance']['initiator']['avatar'], 'approver_name' => $record['approver']['name'], 'approver_avatar' => $record['approver']['avatar'], @@ -53,8 +52,8 @@ class ApprovalRecordsController extends BaseController 'comment' => $record['comment'], 'approved_at' => $record['approved_at'], - 'finished_at' => $record['approvalInstance']['finished_at'], - 'deadline_at' => $record['approvalInstance']['deadline_at'], + 'finished_at' => $record['instance']['finished_at'], + 'deadline_at' => $record['instance']['deadline_at'], 'created_at' => $record['created_at'] ]; @@ -87,4 +86,57 @@ class ApprovalRecordsController extends BaseController return $this->error($e->getMessage()); } } + + + public function todo(Request $request) + { + try { + $raw = $this->service->serviceList($request, 'todo'); + $data = $this->transformData($raw, method_exists($this, 'todoFormat') + ? [$this, 'todoFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + protected function todoFormat($data) + { + if (isset($data['records']) && count($data['records']) > 0) { + foreach ($data['records'] as $key => &$record) { + $result = [ + 'id' => $record['id'], + 'flows_name' => $record['instance']['flows']['name'], + + 'instance_id' => $record['instance_id'], + + 'biz_id' => $record['instance']['biz_id'], + 'biz_desc' => '备货单号【'.$record['instance']['bizInfo']['order_no'].'】', + 'biz_type' => $record['instance']['flow_type'], + + 'initiator_name' => $record['instance']['initiator']['name'], + 'initiator_avatar' => $record['instance']['initiator']['avatar'], + + 'approver_name' => $record['approver']['name'], + 'approver_avatar' => $record['approver']['avatar'], + + 'step_index' => $record['step_index'], + 'action' => $record['action'], + 'action_desc' => SysDictItem::where('item_value', $record['action'])->where('status', 1)->value('item_label'), + 'status' => $record['status'], + 'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'), + 'comment' => $record['comment'], + 'approved_at' => $record['approved_at'], + + 'finished_at' => $record['instance']['finished_at'], + 'deadline_at' => $record['instance']['deadline_at'], + + 'created_at' => $record['created_at'] + ]; + $record = $result; + } + } + return $data; + } } \ No newline at end of file diff --git a/app/admin/logic/ApprovalInstancesLogic.php b/app/admin/logic/ApprovalInstancesLogic.php deleted file mode 100644 index bc8ce88..0000000 --- a/app/admin/logic/ApprovalInstancesLogic.php +++ /dev/null @@ -1,17 +0,0 @@ - 'array', - ]; -} \ No newline at end of file diff --git a/app/admin/model/ApprovalInstances.php b/app/admin/model/ApprovalInstances.php deleted file mode 100644 index b09ff5d..0000000 --- a/app/admin/model/ApprovalInstances.php +++ /dev/null @@ -1,107 +0,0 @@ - 'array', // 自动转换 JSON 字段为数组 - 'finished_at' => 'datetime', - 'deadline_at' => 'datetime', - 'created_at' => 'datetime', - 'updated_at' => 'datetime', - ]; - - /** - * 一个审批实例可以有多个审批记录 - */ - public function approvalRecords(): HasMany - { - return $this->hasMany(ApprovalRecords::class, 'instance_id'); - } - - /** - * 获取当前步骤的所有审批记录(pending 状态) - */ - public function currentStepRecords() - { - return $this->approvalRecords() - ->where('step_index', $this->current_step) - ->where('status', 'pending'); - } - - public function flows() - { - return $this->belongsTo(ApprovalFlows::class, 'flow_type', 'type'); - } - - public function initiator() - { - return $this->belongsTo(User::class, 'initiator_id', 'id'); - } - - - public function bizInfo() - { - return $this->hasOne(StockOrders::class, 'id', 'biz_id'); - } -} \ No newline at end of file diff --git a/app/admin/model/ApprovalRecords.php b/app/admin/model/ApprovalRecords.php deleted file mode 100644 index a970ce4..0000000 --- a/app/admin/model/ApprovalRecords.php +++ /dev/null @@ -1,84 +0,0 @@ - 'datetime', - 'created_at' => 'datetime', - 'updated_at' => 'datetime', - ]; - - /** - * 一条审批记录属于一个审批实例 - */ - public function approvalInstance(): BelongsTo - { - return $this->belongsTo(ApprovalInstances::class, 'instance_id'); - } - - /** - * 关联审批人 - */ - public function approver() - { - return $this->belongsTo(User::class, 'approver_id'); - } -} \ No newline at end of file diff --git a/app/admin/logic/ApprovalFlowsLogic.php b/app/common/logic/ApprovalFlowsLogic.php similarity index 77% rename from app/admin/logic/ApprovalFlowsLogic.php rename to app/common/logic/ApprovalFlowsLogic.php index 1608782..2157d28 100644 --- a/app/admin/logic/ApprovalFlowsLogic.php +++ b/app/common/logic/ApprovalFlowsLogic.php @@ -1,9 +1,9 @@ 'array', ]; diff --git a/app/crm/model/ApprovalInstances.php b/app/common/model/ApprovalInstances.php similarity index 87% rename from app/crm/model/ApprovalInstances.php rename to app/common/model/ApprovalInstances.php index b5a9a7b..48fe707 100644 --- a/app/crm/model/ApprovalInstances.php +++ b/app/common/model/ApprovalInstances.php @@ -1,11 +1,10 @@ 'datetime', ]; - /** - * 一个审批实例可以有多个审批记录 - */ - public function approvalRecords(): HasMany + public function records() { - return $this->hasMany(ApprovalRecords::class, 'instance_id'); - } - - /** - * 获取当前步骤的所有审批记录(pending 状态) - */ - public function currentStepRecords() - { - return $this->approvalRecords() - ->where('step_index', $this->current_step) - ->where('status', 'pending'); + return $this->hasMany(ApprovalRecords::class, 'instance_id', 'id'); } public function flows() @@ -99,9 +84,18 @@ class ApprovalInstances extends Model return $this->belongsTo(User::class, 'initiator_id', 'id'); } - public function bizInfo() { - return $this->hasOne(StockOrders::class, 'id', 'biz_id'); + return $this->belongsTo(StockOrders::class, 'biz_id', 'id'); + } + + /** + * 获取当前步骤的所有审批记录(pending 状态) + */ + public function currentStepRecords() + { + return $this->approvalRecords() + ->where('step_index', $this->current_step) + ->where('status', 'pending'); } } \ No newline at end of file diff --git a/app/crm/model/ApprovalRecords.php b/app/common/model/ApprovalRecords.php similarity index 74% rename from app/crm/model/ApprovalRecords.php rename to app/common/model/ApprovalRecords.php index 4f4ea06..660f1a4 100644 --- a/app/crm/model/ApprovalRecords.php +++ b/app/common/model/ApprovalRecords.php @@ -1,10 +1,9 @@ 'datetime', ]; - /** - * 一条审批记录属于一个审批实例 - */ - public function approvalInstance(): BelongsTo + public function instance() { - return $this->belongsTo(ApprovalInstances::class, 'instance_id'); + return $this->belongsTo(ApprovalInstances::class, 'instance_id', 'id'); } - /** - * 关联审批人 - */ + public function approver() { - return $this->belongsTo(User::class, 'approver_id'); + return $this->belongsTo(User::class, 'approver_id', 'id'); } } \ No newline at end of file diff --git a/app/admin/service/ApprovalFlowsService.php b/app/common/service/ApprovalFlowsService.php similarity index 91% rename from app/admin/service/ApprovalFlowsService.php rename to app/common/service/ApprovalFlowsService.php index 3f7a4e9..726f5cf 100644 --- a/app/admin/service/ApprovalFlowsService.php +++ b/app/common/service/ApprovalFlowsService.php @@ -1,10 +1,10 @@ user->uid; // $config['dataLimit']['userField'] = 'approver_id'; break; + case 'todo': + + if ($p['scene'] === 'todo') { + // if (!in_array(1, $request->user->role_ids)) { + $config['where']['approver_id'] = $request->user->uid; + // } + $config['where']['status'] = 'pending'; + $config['where']['instance.status'] = 'processing'; + } + + if ($p['scene'] === 'history') { + if (!in_array(1, $request->user->role_ids)) { + $config['where']['approver_id'] = $request->user->uid; + } + $config['where']['status'] = ['!=', 'pending']; + } + + $config['order']['id'] = 'desc'; + + $config['with'] = [ + 'instance', + 'approver', + 'instance.flows', + 'instance.initiator', + 'instance.bizInfo' + ]; + break; case 'show': $config['where']['id'] = $p['id']; break; diff --git a/app/common/service/MessageNotificationsService.php b/app/common/service/MessageNotificationsService.php index a225a73..cebd4b9 100644 --- a/app/common/service/MessageNotificationsService.php +++ b/app/common/service/MessageNotificationsService.php @@ -86,7 +86,7 @@ class MessageNotificationsService return ['msg_id' => $msgId]; } - public function afterServiceList($data) + public function afterServiceIndex($data) { $data->each(function (&$item) { $temp = explode(',', $item->recipient); diff --git a/app/common/service/MessageUserStatusService.php b/app/common/service/MessageUserStatusService.php index 2162f86..ca324dc 100644 --- a/app/common/service/MessageUserStatusService.php +++ b/app/common/service/MessageUserStatusService.php @@ -97,7 +97,7 @@ class MessageUserStatusService } - protected function afterServiceList($res) + protected function afterServiceIndex($res) { $res->each(function (&$item) { if (isset($item->message)) { diff --git a/app/common/service/ResourceService.php b/app/common/service/ResourceService.php index c1654a5..2d093f8 100644 --- a/app/common/service/ResourceService.php +++ b/app/common/service/ResourceService.php @@ -95,7 +95,7 @@ class ResourceService } - protected function afterServiceListAll($data) + protected function afterServiceDefault($data) { $data = Tree::buildMenuTreeWithReference($data->toArray()); return $data; diff --git a/app/common/service/SysDictService.php b/app/common/service/SysDictService.php index 4f22070..4918017 100644 --- a/app/common/service/SysDictService.php +++ b/app/common/service/SysDictService.php @@ -28,23 +28,25 @@ class SysDictService - public static function pluckValuesByCode(string $dictCode): \Illuminate\Support\Collection + public static function pluckValuesByCode(string $dictCode): array { return SysDict::where('dict_code', $dictCode) ->where('status', 1) ->first()?->items() ->where('status', 1) ->orderBy('sort') - ->pluck('item_value') ?? collect(); + ->pluck('item_value') + ->toArray() ?? []; } - public static function pluckKeyValueByCode(string $dictCode): \Illuminate\Support\Collection + public static function pluckKeyValueByCode(string $dictCode): array { return SysDict::where('dict_code', $dictCode) ->where('status', 1) ->first()?->items() ->where('status', 1) ->orderBy('sort') - ->pluck('item_value', 'item_label') ?? collect(); + ->pluck('item_value', 'item_label') + ->toArray() ?? []; } } \ No newline at end of file diff --git a/app/common/traits/crud/CrudServiceTrait.php b/app/common/traits/crud/CrudServiceTrait.php index dd4536f..eb563fe 100644 --- a/app/common/traits/crud/CrudServiceTrait.php +++ b/app/common/traits/crud/CrudServiceTrait.php @@ -27,63 +27,61 @@ trait CrudServiceTrait } /** 分页列表 */ - public function serviceList(Request $request) + public function serviceList(Request $request, string $scene = 'index') { - if (method_exists($this, 'complexQuery')) { - $result = $this->complexQuery($request->get()); - } else { - $config = $this->buildQueryConfig($request, 'index'); + $result = $this->cqyProcess(ucfirst($scene), $request); + if ($result === false) { + $config = $this->buildQueryConfig($request, $scene); $limit = (int)$request->get('size', 15); $page = (int)$request->get('current', 1); $result = $this->logicList($config, $limit, $page); } - return $this->postProcess('List', $result); + return $this->postProcess(ucfirst($scene), $result); } /** 全量列表 */ - public function serviceListAll(Request $request) + public function serviceListAll(Request $request, string $scene = 'default') { - if (method_exists($this, 'complexQuery')) { - $result = $this->complexQuery($request->get()); - } else { - $config = $this->buildQueryConfig($request, 'default'); + $result = $this->cqyProcess(ucfirst($scene), $request); + if ($result === false) { + $config = $this->buildQueryConfig($request, $scene); $result = $this->logicListAll($config); } - return $this->postProcess('ListAll', $result); + return $this->postProcess(ucfirst($scene), $result); } /** 查看单条 */ - public function serviceShow(Request $request) + public function serviceShow(Request $request, string $scene = 'show') { - $config = $this->buildQueryConfig($request, 'show'); + $config = $this->buildQueryConfig($request, $scene); $item = $this->logicShow($config); - return $this->postProcess('Show', $item); + return $this->postProcess(ucfirst($scene), $item); } /** 创建 */ - public function serviceStore(Request $request, array $data = []) + public function serviceStore(Request $request, array $data = [], string $scene = 'store') { - $data = $this->preProcess('Store', $data, $request); + $data = $this->preProcess(ucfirst($scene), $data, $request); $dl = $this->getDataLimitFromRequest($request); $created = $this->logicCreate($data, $dl); - return $this->postProcess('Store', $created); + return $this->postProcess(ucfirst($scene), $created); } /** 更新 */ - public function serviceUpdate(Request $request, array $data = []) + public function serviceUpdate(Request $request, array $data = [], string $scene = 'update') { - $data = $this->preProcess('Update', $data, $request); - $config = $this->buildQueryConfig($request, 'update'); + $data = $this->preProcess(ucfirst($scene), $data, $request); + $config = $this->buildQueryConfig($request, $scene); $updated = $this->logicUpdateBy($config, $data); - return $this->postProcess('Update', $data); + return $this->postProcess(ucfirst($scene), $data); } /** 删除 */ - public function serviceDestroy(Request $request) + public function serviceDestroy(Request $request, string $scene = 'destroy') { - $config = $this->buildQueryConfig($request, 'destroy'); + $config = $this->buildQueryConfig($request, $scene); $deleted = $this->logicDeleteBy($config); - return $this->postProcess('Destroy', $deleted); + return $this->postProcess(ucfirst($scene), $deleted); } /** ----------------- 公共辅助方法 ----------------- */ @@ -182,13 +180,18 @@ trait CrudServiceTrait : $data; } - - /** - * 处理复杂查询 - * 覆盖此方法,实现复杂查询逻辑 + /** + * 复杂/自定义查询 + * + * @param string $op 场景 + * @param mixed $data 原始返回值 + * @return mixed 处理后的返回值 */ - // protected function complexQuery(array $params): array - // { - // throw new BusinessException('请在子类实现 complexQuery'); - // } + protected function cqyProcess(string $op, Request $request): mixed + { + $hook = "complexQuery{$op}"; + return method_exists($this, $hook) + ? $this->{$hook}($request) + : false; + } } \ No newline at end of file diff --git a/app/common/traits/crud/CrudServiceTrait_bak.php b/app/common/traits/crud/CrudServiceTrait_bak.php new file mode 100644 index 0000000..4b2e012 --- /dev/null +++ b/app/common/traits/crud/CrudServiceTrait_bak.php @@ -0,0 +1,194 @@ +validator; + } + + /** 分页列表 */ + public function serviceList(Request $request) + { + if (method_exists($this, 'complexQuery')) { + $result = $this->complexQuery($request->get()); + } else { + $config = $this->buildQueryConfig($request, 'index'); + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $result = $this->logicList($config, $limit, $page); + } + return $this->postProcess('List', $result); + } + + /** 全量列表 */ + public function serviceListAll(Request $request) + { + if (method_exists($this, 'complexQuery')) { + $result = $this->complexQuery($request->get()); + } else { + $config = $this->buildQueryConfig($request, 'default'); + $result = $this->logicListAll($config); + } + return $this->postProcess('ListAll', $result); + } + + /** 查看单条 */ + public function serviceShow(Request $request) + { + $config = $this->buildQueryConfig($request, 'show'); + $item = $this->logicShow($config); + return $this->postProcess('Show', $item); + } + + /** 创建 */ + public function serviceStore(Request $request, array $data = []) + { + $data = $this->preProcess('Store', $data, $request); + $dl = $this->getDataLimitFromRequest($request); + $created = $this->logicCreate($data, $dl); + return $this->postProcess('Store', $created); + } + + /** 更新 */ + public function serviceUpdate(Request $request, array $data = []) + { + $data = $this->preProcess('Update', $data, $request); + $config = $this->buildQueryConfig($request, 'update'); + $updated = $this->logicUpdateBy($config, $data); + return $this->postProcess('Update', $data); + } + + /** 删除 */ + public function serviceDestroy(Request $request) + { + $config = $this->buildQueryConfig($request, 'destroy'); + $deleted = $this->logicDeleteBy($config); + return $this->postProcess('Destroy', $deleted); + } + + /** ----------------- 公共辅助方法 ----------------- */ + + /** + * 构造 CrudUtil 查询配置 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'default': + $config['where']['status'] = 1; + $config['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'index': + $config['where']['status'] = 1; + $config['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'show': + $config['where']['id'] = $p['id']; + $config['where']['status'] = 1; + break; + case 'store': + break; + case 'update': + $config['where']['id'] = $p['id']; + break; + case 'destroy': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } + + /** 解析 withFields 字符串 "rel:field,field;..." */ + protected function parseWithFields(string $str): array + { + if (!$str) { + return []; + } + $out = []; + foreach (explode(';', $str) as $pair) { + [$rel, $flds] = explode(':', $pair); + $out[$rel] = explode(',', $flds); + } + return $out; + } + + /** 从请求读取 dataLimitType, dataLimitField */ + protected function getDataLimitFromRequest(Request $req): array + { + $type = $req->get('dataLimitType'); + if (!$type) { + return []; + } + return [ + 'type' => $type, + 'field' => $req->get('dataLimitField', 'admin_id'), + ]; + } + + /** + * $data 前置处理 + * + * @param array $data + * @param Request $request + * @return array + */ + protected function preProcess(string $op, mixed $data, Request $request): mixed + { + $hook = "beforeService{$op}"; + return method_exists($this, $hook) + ? $this->{$hook}($data, $request) + : $data; + } + + /** + * 根据操作类型,调用对应的后置钩子 + * + * @param string $op 操作:List, Show, Store, Update, Destroy + * @param mixed $data 原始返回值 + * @return mixed 处理后的返回值 + */ + protected function postProcess(string $op, mixed $data): mixed + { + $hook = "afterService{$op}"; + return method_exists($this, $hook) + ? $this->{$hook}($data) + : $data; + } + + + /** + * 处理复杂查询 + * 覆盖此方法,实现复杂查询逻辑 + */ + // protected function complexQuery(array $params): array + // { + // throw new BusinessException('请在子类实现 complexQuery'); + // } +} \ No newline at end of file diff --git a/app/common/utils/approval/model/ApprovalFlows.php b/app/common/utils/approval/model/ApprovalFlows.php deleted file mode 100644 index 7c6fea1..0000000 --- a/app/common/utils/approval/model/ApprovalFlows.php +++ /dev/null @@ -1,49 +0,0 @@ -toArray()); + $approvalType = array_flip(\app\common\service\SysDictService::pluckKeyValueByCode('approval_type')); switch ($instance->flow_type) { case 'stock_orders': // 备货单 diff --git a/app/admin/validate/ApprovalFlowsValidate.php b/app/common/validate/ApprovalFlowsValidate.php similarity index 91% rename from app/admin/validate/ApprovalFlowsValidate.php rename to app/common/validate/ApprovalFlowsValidate.php index 9b64000..4e4cb4d 100644 --- a/app/admin/validate/ApprovalFlowsValidate.php +++ b/app/common/validate/ApprovalFlowsValidate.php @@ -1,6 +1,6 @@ ', 141]; - $list = (new \app\common\utils\MigrationResources())->getFullResourceTreeOptimized('resources', $where); - - - $keys = ['system_id','name','desc','type','code','parent_id','url','icon','open_type','link', - 'is_hide','is_hide_tab','no_auth','is_home','instance','keep_alive','sort','status']; - foreach ($list as $key=>$item) { - - - $temp = []; - - foreach ($item as $k=>$v) { - - if (isset($item['children']) && count($item['children']) > 0) { - $temp = $item['children']; - } - - if (!in_array($k, $keys)) { - unset($item[$k]); - } - - $id = Db::table('resources')->insertGetId($item); - - if ($temp) { - foreach ($temp as $kc=>$vc) { - - foreach ($vc as $kk => $vv) { - if (!in_array($kk, $keys)) { - unset($vc[$kk]); - } - } - - $vc['parent_id'] = $id; - - Db::table('resources')->insert($vc); - } - - } - - } - } - } - - - public function test(Request $request) { // 菜单迁移 diff --git a/app/crm/controller/ApprovalFlowsController.php b/app/crm/controller/ApprovalFlowsController.php index 7eacb12..c97fa87 100644 --- a/app/crm/controller/ApprovalFlowsController.php +++ b/app/crm/controller/ApprovalFlowsController.php @@ -3,7 +3,7 @@ namespace app\crm\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; -use app\crm\service\ApprovalFlowsService; +use app\common\service\ApprovalFlowsService; class ApprovalFlowsController extends BaseController { diff --git a/app/crm/controller/ApprovalInstancesController.php b/app/crm/controller/ApprovalInstancesController.php index e854af6..3643489 100644 --- a/app/crm/controller/ApprovalInstancesController.php +++ b/app/crm/controller/ApprovalInstancesController.php @@ -3,7 +3,7 @@ namespace app\crm\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; -use app\crm\service\ApprovalInstancesService; +use app\common\service\ApprovalInstancesService; class ApprovalInstancesController extends BaseController { diff --git a/app/crm/controller/ApprovalRecordsController.php b/app/crm/controller/ApprovalRecordsController.php index 3edc6b5..ca68d9f 100644 --- a/app/crm/controller/ApprovalRecordsController.php +++ b/app/crm/controller/ApprovalRecordsController.php @@ -3,7 +3,7 @@ namespace app\crm\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; -use app\crm\service\ApprovalRecordsService; +use app\common\service\ApprovalRecordsService; use app\common\model\SysDictItem; use support\Request; @@ -86,4 +86,58 @@ class ApprovalRecordsController extends BaseController return $this->error($e->getMessage()); } } + + + + public function todo(Request $request) + { + try { + $raw = $this->service->serviceList($request, 'todo'); + $data = $this->transformData($raw, method_exists($this, 'todoFormat') + ? [$this, 'todoFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + protected function todoFormat($data) + { + if (isset($data['records']) && count($data['records']) > 0) { + foreach ($data['records'] as $key => &$record) { + $result = [ + 'id' => $record['id'], + 'flows_name' => $record['approvalInstance']['flows']['name'], + + 'instance_id' => $record['instance_id'], + + 'biz_id' => $record['approvalInstance']['biz_id'], + 'biz_desc' => '备货单号【'.$record['approvalInstance']['bizInfo']['order_no'].'】', + 'biz_type' => $record['approvalInstance']['flow_type'], + + 'initiator_name' => $record['approvalInstance']['initiator']['name'], + 'initiator_avatar' => $record['approvalInstance']['initiator']['avatar'], + + 'approver_name' => $record['approver']['name'], + 'approver_avatar' => $record['approver']['avatar'], + + 'step_index' => $record['step_index'], + 'action' => $record['action'], + 'action_desc' => SysDictItem::where('item_value', $record['action'])->where('status', 1)->value('item_label'), + 'status' => $record['status'], + 'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'), + 'comment' => $record['comment'], + 'approved_at' => $record['approved_at'], + + 'finished_at' => $record['approvalInstance']['finished_at'], + 'deadline_at' => $record['approvalInstance']['deadline_at'], + + 'created_at' => $record['created_at'] + ]; + $record = $result; + } + } + return $data; + } } \ No newline at end of file diff --git a/app/crm/logic/ApprovalFlowsLogic.php b/app/crm/logic/ApprovalFlowsLogic.php deleted file mode 100644 index 8a5260f..0000000 --- a/app/crm/logic/ApprovalFlowsLogic.php +++ /dev/null @@ -1,17 +0,0 @@ -validator; - } -} \ No newline at end of file diff --git a/app/crm/service/ApprovalInstancesService.php b/app/crm/service/ApprovalInstancesService.php deleted file mode 100644 index 86e6e57..0000000 --- a/app/crm/service/ApprovalInstancesService.php +++ /dev/null @@ -1,31 +0,0 @@ -validator; - } -} \ No newline at end of file diff --git a/app/crm/service/ApprovalRecordsService.php b/app/crm/service/ApprovalRecordsService.php deleted file mode 100644 index 16c070d..0000000 --- a/app/crm/service/ApprovalRecordsService.php +++ /dev/null @@ -1,91 +0,0 @@ -validator; - } - - - protected function buildQueryConfig(Request $request, string $scene = 'default'): array - { - $p = $request->all(); - - $config = []; - $config['model'] = $this->modelClass; - switch ($scene) { - case 'index': - $config['order']['id'] = 'desc'; - - $config['with'] = [ - 'approvalInstance', - 'approver', - 'approvalInstance.flows', - 'approvalInstance.initiator', - 'approvalInstance.bizInfo' - ]; - - $config['dataLimit']['type'] = 'relation'; - $config['dataLimit']['userId'] = $request->user->uid; - $config['dataLimit']['userField'] = 'approver_id'; - break; - case 'show': - $config['where']['id'] = $p['id']; - break; - case 'store': - break; - case 'update': - $config['where']['id'] = $p['id']; - break; - case 'destroy': - $config['where']['id'] = $p['id']; - break; - case 'logs': - $config['where']['instance_id'] = $p['instance_id']; - $config['order']['id'] = 'desc'; - break; - } - - return $config; - } - - - public function serviceApprove(Request $request) - { - $param = $request->all(); - $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - return $appro->approve($param['instance_id'], $request->user->uid, $param['action'], $param['comment']); - } - - - public function serviceLogs(Request $request) - { - $config = $this->buildQueryConfig($request, 'logs'); - $item = $this->logicListAll($config); - return $this->postProcess('Logs', $item); - } -} \ No newline at end of file diff --git a/config/route.php b/config/route.php index 75a2ebe..d44e903 100644 --- a/config/route.php +++ b/config/route.php @@ -305,6 +305,8 @@ Route::group('/admin', function () { Route::any('/list', [app\admin\controller\ApprovalRecordsController::class, 'index']); Route::any('/logs', [app\admin\controller\ApprovalRecordsController::class, 'logs']); Route::any('/action', [app\admin\controller\ApprovalRecordsController::class, 'approve']); + + Route::any('/todo', [app\admin\controller\ApprovalRecordsController::class, 'todo']); }); Route::group('/stock/order', function () { @@ -395,6 +397,8 @@ Route::group('/crm', function () { Route::any('/list', [app\crm\controller\ApprovalRecordsController::class, 'index']); Route::any('/logs', [app\crm\controller\ApprovalRecordsController::class, 'logs']); Route::any('/action', [app\crm\controller\ApprovalRecordsController::class, 'approve']); + + Route::any('/todo', [app\admin\controller\ApprovalRecordsController::class, 'todo']); }); // 汽车颜色