From f9fc2dbfb4b7b114ff398074c663ff9302e17507 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Jul 2024 13:24:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=A0=B8=20=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Audit/AuditController.php | 26 +++-- app/controller/substance/ResourceController.php | 18 +++ app/model/Audit.php | 26 ----- app/service/AuditContentService.php | 46 ++++++++ app/service/AuditResourceService.php | 141 +++++++++++------------- app/service/AuditService.php | 78 +++++++++++++ app/service/ProcessService.php | 16 +-- app/service/RecycleResourceService.php | 35 ++++++ app/service/RecycleService.php | 39 ------- app/service/ResourceService.php | 34 +++--- app/service/Service.php | 2 +- route/substance.php | 1 + 12 files changed, 286 insertions(+), 176 deletions(-) create mode 100644 app/service/AuditContentService.php create mode 100644 app/service/AuditService.php create mode 100644 app/service/RecycleResourceService.php delete mode 100644 app/service/RecycleService.php diff --git a/app/controller/Audit/AuditController.php b/app/controller/Audit/AuditController.php index 2806749..648bbd6 100644 --- a/app/controller/Audit/AuditController.php +++ b/app/controller/Audit/AuditController.php @@ -60,16 +60,16 @@ class AuditController $audit_service = new AuditService(); //批量审核操作 只支持同文档类型 同操作类型 $target_type_and_type_info = $audit_service->checkIdsTargetTypeAndType($request->param('ids')); + if (!$target_type_and_type_info) { throw new \Exception('批量操作只支持同类型操作'); } - //区分 资源还是内容 - if ($target_type_and_type_info['target_type'] == 1) { - //资源上传 批量审核通过 - $res = (new AuditService())->resourceApprove($request->param(), $target_type_and_type_info['type']); - } + //根据target_type创建资源/内容操作子类 + $audit_target_service = ($audit_service::createAuditTargetService($target_type_and_type_info['target_type'])); + //资源上传 批量审核通过 + $res = $audit_target_service->approve($request->param(), $target_type_and_type_info['type']); Db::commit(); return json($res); @@ -93,8 +93,20 @@ class AuditController //保存到数据库 Db::startTrans(); try { - // 1. 保存站点到数据库 - $res = (new AuditService())->reject($request->param()); + $audit_service = new AuditService(); + //批量审核操作 只支持同文档类型 同操作类型 + $target_type_and_type_info = $audit_service->checkIdsTargetTypeAndType($request->param('ids')); + + if (!$target_type_and_type_info) { + throw new \Exception('批量操作只支持同类型操作'); + } + + //根据target_type创建资源/内容操作子类 + $audit_target_service = ($audit_service::createAuditTargetService($target_type_and_type_info['target_type'])); + + //资源上传 批量审核驳回 + $res = $audit_target_service->reject($request->param(), $target_type_and_type_info['type']); + Db::commit(); return json($res); } catch (\Exception $e) { diff --git a/app/controller/substance/ResourceController.php b/app/controller/substance/ResourceController.php index 66a87b0..8392eea 100644 --- a/app/controller/substance/ResourceController.php +++ b/app/controller/substance/ResourceController.php @@ -3,6 +3,7 @@ namespace app\controller\substance; use app\model\Resource; +use app\service\AuditResourceService; use app\service\ResourceService; use app\service\ShareService; use app\validate\ResourceValidate; @@ -171,6 +172,23 @@ class ResourceController return json($res); } + public function uploadAudit(Request $request) + { + Db::startTrans(); + try { + //修改资源表状态 + Resource::whereIn('id', $request->param('ids'))->update(['audit_status' => 1]); + //添加审核记录 + (new AuditResourceService())->addAudit($request->param('ids'), 1); + Db::commit(); + return jsonReturn(0, Lang::get('批量添加审核成功')); + } catch (\Exception $e) { + Db::rollback(); + return jsonReturn(-5, $e->getMessage()); + } + + } + /** * 删除 */ diff --git a/app/model/Audit.php b/app/model/Audit.php index adc3cd3..05cf69e 100644 --- a/app/model/Audit.php +++ b/app/model/Audit.php @@ -35,30 +35,4 @@ class Audit extends Model return $this->belongsTo(User::class, 'audit_user_id'); } - - /** - * @param $target_type - * @return Content|Resource|false - * 根据target_type 返回target类 - */ - static function getTargetModelByTargetType($target_type) - { - switch ($target_type) { - case 1: - return new Resource(); - break; - case 2: - return new Content(); - } - return false; - } - - static function getTargetTypeByTarget($target) - { - if ($target instanceof Resource) { - return 1; - } elseif ($target instanceof Content) { - return 2; - } - } } diff --git a/app/service/AuditContentService.php b/app/service/AuditContentService.php new file mode 100644 index 0000000..8fa4388 --- /dev/null +++ b/app/service/AuditContentService.php @@ -0,0 +1,46 @@ +model = new Content(); + } + + /** + * 添加一条资源审核记录 (上传/删除) + * @param $resource + * @param $type + * @return true + */ + public function addOneAudit($resource, $type) + { + //状态不是待审核 无需添加 + if ($resource->audit_status != 1) { + return true; + } + + $audit = new Audit(); + $audit->target_id = $resource->id; + $audit->target_type = $this::TARGET_TYPE; + $audit->type = $type; + $audit->launch_user_id = $this->user_id; + $audit->launch_time = date('Y-m-d H:i:s'); + $audit->save(); + return true; + } + +} diff --git a/app/service/AuditResourceService.php b/app/service/AuditResourceService.php index ac5c1db..1b2b5d5 100644 --- a/app/service/AuditResourceService.php +++ b/app/service/AuditResourceService.php @@ -8,138 +8,123 @@ use app\model\Resource; /** * 该service 负责处理资源相关审核 */ -class AuditResourceService extends Service +class AuditResourceService extends AuditService { + //操作的模型 + public $model; const TARGET_TYPE = 1; + public function __construct() + { + parent::__construct(); + $this->model = new Resource(); + } + + /** * 添加一条资源审核记录 (上传/删除) - * @param $target - * @param $type 1上传 2删除 - * @return void + * @param $resource + * @param $type 1 上传 2 删除 + * @param $status 1 待审核 2 审核通过 3 审核驳回 + * @return true */ - public function addOneAudit($resource, $type) + public function addOneAudit($resource, $type, $status = 1) { - $audit = new Audit(); $audit->target_id = $resource->id; $audit->target_type = $this::TARGET_TYPE; $audit->type = $type; + $audit->status = $status; $audit->launch_user_id = $this->user_id; $audit->launch_time = date('Y-m-d H:i:s'); - dd($audit); + $audit->save(); + return true; } /** - * @param $ids 资源/内容 数组 - * @param $target_type 1资源 2内容 - * @param $type 1上传 2删除 - * @param $status 1待审核 2审核通过 3审核失败 + * 批量添加资源审核记录 (上传/删除) + * @param $ids 资源ids + * @param $type 1 上传 2 删除 + * @param $status 1 待审核 2 审核通过 3 审核驳回 * @return void - * 批量添加审核记录表 + * @throws \Exception */ - public function addAudit($ids, $target_type, $type = 1, $status = 1) + public function addAudit($ids, $type, $status = 1) { $audit_ary = []; foreach ($ids as $id) { //todo user_id - $audit['launch_user_id'] = 1; + $audit['launch_user_id'] = $this->user_id; $audit['launch_time'] = date('Y-m-d H:i:s'); $audit['target_id'] = $id; - $audit['target_type'] = $target_type; + $audit['target_type'] = $this::TARGET_TYPE; $audit['type'] = $type; $audit['status'] = $status; $audit_ary [] = $audit; } $audit = new Audit(); $audit->saveAll($audit_ary); - + return true; } /** - * @param $ids - * @return array|false 是同一种 返回文档类型和操作 不是返回false - * 检测批量操作的时候是同一种文档(素材/内容) 是否是同一种操作(上传/删除) + * 资源上传/删除 审核通过 + * @param $param + * @param $type 1 上传 2 删除 + * @return array */ - public function checkIdsTargetTypeAndType($ids) + public function approve($param, $type = 0) { - $target_type_ary = []; - $type_ary = []; - $audits = Audit::whereIn('id', $ids)->field('id,target_type,type')->select(); - foreach ($audits as $audit) { - - if (!in_array($audit->target_type, $target_type_ary)) { - $target_type_ary[] = $audit->target_type; - } - - if (!in_array($audit->type, $type_ary)) { - $type_ary[] = $audit->type; - } - } - if (count($target_type_ary) > 1 || count($type_ary) > 1) { - return false; + if (!$type) { + //这里type 可以通过 param ids直接获取 } - return [ - 'target_type' => $target_type_ary[0], - 'type' => $type_ary[0], - ]; - } - - public function resourceApprove($param, $type) - { switch ($type) { case 1: //上传审核通过 - - //审核记录改为通过 - Audit::whereIn('id', $param['ids'])->update(['status' => 2]); - //上传审核的资源ids - $upload_target_ids_ary = Audit::whereIn('id', $param['ids'])->where('type', 1)->column('target_id'); - Resource::whereIn('id', $upload_target_ids_ary)->update(['audit_status' => 2]); + $this->changeAuditAndTargetStatus($param, 2, 'audit_status'); break; case 2: //删除审核通过 - break; - } + $upload_target_ids_ary = $this->changeAuditAndTargetStatus($param, 2, 'del_audit_status'); + //放入回收站 需要遍历处理 + $recycle_resource_service = new RecycleResourceService(); + foreach ($upload_target_ids_ary as $target_id) { + $resource = $this->model::find($target_id); + $recycle_resource_service->addOneRecycle($resource); + $resource->is_del = 1; + $resource->save(); + }; + break; + } return dataReturn($this->sucCode, '审核通过成功'); } + /** + * 资源上传/删除 审核驳回 * @param $param + * @param $type 1 上传 2 删除 * @return array - * 批量审核通过 */ - public function approve($param) - { - dd($param); - //审核记录改为通过 - Audit::whereIn('id', $param['ids'])->update(['status' => 2]); - - //上传审核的资源ids - $upload_target_ids_ary = Audit::whereIn('id', $param['ids'])->where('type', 1)->column('target_id'); - $delete_target_ids_ary = Audit::whereIn('id', $param['ids'])->where('type', 2)->column('target_id'); - - $target_model = Audit::getTargetModelByTargetType($param['target_type']); - $target_model->whereIn('id', $upload_target_ids_ary)->update(['audit_status' => 2]); - $target_model->whereIn('id', $delete_target_ids_ary)->update(['del_audit_status' => 2]); - - return dataReturn($this->sucCode, '审核通过成功'); - } - - public function reject($param) + public function reject($param, $type = 0) { - - //审核记录改为驳回 - Audit::whereIn('id', $param['ids'])->update(['status' => 3, 'reason' => $param['reason'], 'desc' => $param['desc']]); - - //修改资源/内容审核状态为驳回 - $target_ids_ary = Audit::whereIn('id', $param['ids'])->column('target_id'); - $target_model = Audit::getTargetModelByTargetType($param['target_type']); - $target_model->whereIn('id', $target_ids_ary)->update(['audit_status' => 3]); + if (!$type) { + //这里type 可以通过 param ids直接获取 + } + switch ($type) { + case 1: + //上传审核驳回 + $this->changeAuditAndTargetStatus($param, 3, 'audit_status'); + break; + case 2: + //删除审核驳回 + $this->changeAuditAndTargetStatus($param, 3, 'del_audit_status'); + break; + } return dataReturn($this->sucCode, '审核驳回成功'); } diff --git a/app/service/AuditService.php b/app/service/AuditService.php new file mode 100644 index 0000000..9c396f4 --- /dev/null +++ b/app/service/AuditService.php @@ -0,0 +1,78 @@ +field('id,target_type,type')->select(); + foreach ($audits as $audit) { + + if (!in_array($audit->target_type, $target_type_ary)) { + $target_type_ary[] = $audit->target_type; + } + + if (!in_array($audit->type, $type_ary)) { + $type_ary[] = $audit->type; + } + } + if (count($target_type_ary) > 1 || count($type_ary) > 1) { + return false; + } + return [ + 'target_type' => $target_type_ary[0], + 'type' => $type_ary[0], + ]; + } + + /** + * 修改审核表 和 目标表 审核状态 + * @param $param + * @param $status 1 待审核 2 审核通过 3 审核驳回 + * @param $target_field 目标表目标字段 + * @return array + */ + public function changeAuditAndTargetStatus($param, $status, $target_field) + { + Audit::whereIn('id', $param['ids'])->update([ + 'status' => $status, + 'reason' => isset($param['reason']) ? $param['reason'] : '', + 'desc' => isset($param['desc']) ? $param['desc'] : '']); + //上传审核的资源ids + $upload_target_ids_ary = Audit::whereIn('id', $param['ids'])->column('target_id'); + $this->model::whereIn('id', $upload_target_ids_ary)->update([$target_field => $status]); + + return $upload_target_ids_ary; + } + + public static function createAuditTargetService($type) + { + switch ($type) { + case '1': + return new AuditResourceService(); + case '2': + return new AuditContentService(); + default: + return false; + } + } +} diff --git a/app/service/ProcessService.php b/app/service/ProcessService.php index 24cbc4b..427f550 100644 --- a/app/service/ProcessService.php +++ b/app/service/ProcessService.php @@ -16,26 +16,20 @@ class ProcessService /** * @param $resource 资源 - * @param $insert_audit_flag 是否需要插入审核表 * @return int * 通过流程表 获取资源上传后的状态 */ - public function getResouceUploadStatus($resource, $insert_audit_flag = false) + public function getAuditStatusByProcess($flag) { - $status = $this->resource_status_map['not']; - - $process = (Process::where('flag', 'resource_upload')->find()); + $status = 0; + $process = (Process::where('flag', $flag)->find()); //流程停用开启 上传后状态直接是审核通过 if ($process->stop_using == 1) { - $status = $this->resource_status_map['success']; + $status = 2; } elseif ($process->auto_propose == 1) { //自动发起开启 上传后状态直接是等待审核 - $status = $this->resource_status_map['wait']; - if ($insert_audit_flag) { - (new AuditService())->addAudit([$resource->id], 1); - } + $status = 1; } - return $status; } } diff --git a/app/service/RecycleResourceService.php b/app/service/RecycleResourceService.php new file mode 100644 index 0000000..1ea3383 --- /dev/null +++ b/app/service/RecycleResourceService.php @@ -0,0 +1,35 @@ +seller_id = $this->seller_id; + $recycle->target_id = $resource->id; + $recycle->table_name = $this::TABLE_NAME; + $recycle->user_id = $this->user_id; + $recycle->dir_name = (new ResourceDirService())->getResourceDirNamePath($resource); + $recycle->expire_time = getdaysLater(90); + $recycle->save(); + return true; + } +} diff --git a/app/service/RecycleService.php b/app/service/RecycleService.php deleted file mode 100644 index 6fb368b..0000000 --- a/app/service/RecycleService.php +++ /dev/null @@ -1,39 +0,0 @@ -seller_id = 1; - $recycle->target_id = $resource->id; - $recycle->table_name = 'resource'; - $recycle->user_id = 1; - $recycle->dir_name = $resource_dir_service->getResourceDirNamePath($resource); - $recycle->expire_time = getdaysLater(90); - $recycle->save(); - - //修改资源的删除状态 - $resource->is_del = 1; - $resource->save(); - - return dataReturn(0, '加入回收站成功'); - } -} diff --git a/app/service/ResourceService.php b/app/service/ResourceService.php index 5bfbe42..f7c1ce8 100644 --- a/app/service/ResourceService.php +++ b/app/service/ResourceService.php @@ -48,11 +48,15 @@ class ResourceService extends Service $file_size_and_count = $this->getFileSizeAndCount($resource); $resource->file_size = $file_size_and_count['file_size']; $resource->file_count = $file_size_and_count['file_count']; - //todo 还有状态的啥的 - $process_service = new ProcessService(); - $resource->audit_status = $process_service->getResouceUploadStatus($resource, true); - + $resource->audit_status = (new ProcessService())->getAuditStatusByProcess('resource_upload'); $resource->save(); + + //如果资源状态是待审核 添加审核记录 + if ($resource->audit_status == 1) { + (new AuditResourceService())->addOneAudit($resource, 1); + } + + } /** @@ -105,7 +109,6 @@ class ResourceService extends Service return dataReturn($this->sucCode, $this->copyMsg); } - /** * 删除普通资源数据 * @param $ids 需要删除的普通资源ids @@ -113,26 +116,29 @@ class ResourceService extends Service */ public function delete($ids) { - $recycle_service = new RecycleService(); + $recycle_resource_service = new RecycleResourceService(); $audit_resource_service = new AuditResourceService(); - $resource_status_map = Resource::STATUS_MAP; - foreach ($ids as $resource_id) { - //已经是删除状态的资源 无需处理 + + //删除流程不同 需要一个个处理 $resource = Resource::where('is_del', 0)->find($resource_id); if (!$resource) { continue; } - if ($resource->audit_status == $resource_status_map['success']) { - //todo 审核通过的资源 删除走审核流程 + if ($resource->audit_status == 2) { + //添加资源删除审核记录 $audit_resource_service->addOneAudit($resource, 2); + $resource->del_audit_status = 1; + $resource->save(); } else { - //其他状态的资源 删除直接放入回收站 - $audit_resource_service->putOneResourceInRecycle($resource); + // 删除放入回收站 + $recycle_resource_service->addOneRecycle($resource); + //修改资源的删除状态 + $resource->is_del = 1; + $resource->save(); } - } return dataReturn($this->sucCode, $this->delMsg); } diff --git a/app/service/Service.php b/app/service/Service.php index c47aae0..2c5e9f7 100644 --- a/app/service/Service.php +++ b/app/service/Service.php @@ -44,7 +44,7 @@ class Service $this->delMsg = lang('删除成功'); $this->user = User::find(1); $this->user_id = $this->user->id; -// $this->seller_id = $this->getSeller(); + $this->seller_id = 123; } diff --git a/route/substance.php b/route/substance.php index 9451cb8..2caf6b8 100644 --- a/route/substance.php +++ b/route/substance.php @@ -20,6 +20,7 @@ Route::group('resource', function () { Route::post('/move_to', 'moveTo'); Route::post('/copy_to', 'copyTo'); Route::post('/delete', 'delete'); + Route::post('/upload_audit', 'uploadAudit'); })->prefix('substance.resource/')->middleware('login');