From e6062b63248c1aa09eb5e8f9acb81dd87b6f6016 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Jul 2024 19:05:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/Audit.php | 9 +++ app/service/AuditResourceService.php | 146 +++++++++++++++++++++++++++++++++++ app/service/AuditService.php | 121 ----------------------------- app/service/RecycleService.php | 2 +- app/service/ResourceService.php | 6 +- app/service/Service.php | 30 +++---- 6 files changed, 176 insertions(+), 138 deletions(-) create mode 100644 app/service/AuditResourceService.php delete mode 100644 app/service/AuditService.php diff --git a/app/model/Audit.php b/app/model/Audit.php index c9afdc7..adc3cd3 100644 --- a/app/model/Audit.php +++ b/app/model/Audit.php @@ -52,4 +52,13 @@ class Audit extends Model } return false; } + + static function getTargetTypeByTarget($target) + { + if ($target instanceof Resource) { + return 1; + } elseif ($target instanceof Content) { + return 2; + } + } } diff --git a/app/service/AuditResourceService.php b/app/service/AuditResourceService.php new file mode 100644 index 0000000..ac5c1db --- /dev/null +++ b/app/service/AuditResourceService.php @@ -0,0 +1,146 @@ +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'); + dd($audit); + $audit->save(); + } + + /** + * @param $ids 资源/内容 数组 + * @param $target_type 1资源 2内容 + * @param $type 1上传 2删除 + * @param $status 1待审核 2审核通过 3审核失败 + * @return void + * 批量添加审核记录表 + */ + public function addAudit($ids, $target_type, $type = 1, $status = 1) + { + $audit_ary = []; + foreach ($ids as $id) { + //todo user_id + $audit['launch_user_id'] = 1; + $audit['launch_time'] = date('Y-m-d H:i:s'); + $audit['target_id'] = $id; + $audit['target_type'] = $target_type; + $audit['type'] = $type; + $audit['status'] = $status; + $audit_ary [] = $audit; + } + $audit = new Audit(); + $audit->saveAll($audit_ary); + + } + + /** + * @param $ids + * @return array|false 是同一种 返回文档类型和操作 不是返回false + * 检测批量操作的时候是同一种文档(素材/内容) 是否是同一种操作(上传/删除) + */ + public function checkIdsTargetTypeAndType($ids) + { + $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; + } + 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]); + break; + case 2: + //删除审核通过 + break; + } + + + return dataReturn($this->sucCode, '审核通过成功'); + } + + /** + * @param $param + * @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) + { + + //审核记录改为驳回 + 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]); + return dataReturn($this->sucCode, '审核驳回成功'); + } + +} diff --git a/app/service/AuditService.php b/app/service/AuditService.php deleted file mode 100644 index d12b7c1..0000000 --- a/app/service/AuditService.php +++ /dev/null @@ -1,121 +0,0 @@ -saveAll($audit_ary); - - } - - /** - * @param $ids - * @return array|false 是同一种 返回文档类型和操作 不是返回false - * 检测批量操作的时候是同一种文档(素材/内容) 是否是同一种操作(上传/删除) - */ - public function checkIdsTargetTypeAndType($ids) - { - $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; - } - 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]); - break; - case 2: - //删除审核通过 - break; - } - - - return dataReturn($this->sucCode, '审核通过成功'); - } - - /** - * @param $param - * @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) - { - - //审核记录改为驳回 - 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]); - return dataReturn($this->sucCode, '审核驳回成功'); - } - -} diff --git a/app/service/RecycleService.php b/app/service/RecycleService.php index 7c643cc..6fb368b 100644 --- a/app/service/RecycleService.php +++ b/app/service/RecycleService.php @@ -17,7 +17,7 @@ class RecycleService extends Service * @param Resource $resource * @return array */ - public function putResourceInRecycle(Resource $resource) + public function putOneResourceInRecycle(Resource $resource) { //todo seller_id user_id 处理 $resource_dir_service = new ResourceDirService(); diff --git a/app/service/ResourceService.php b/app/service/ResourceService.php index fa95685..5bfbe42 100644 --- a/app/service/ResourceService.php +++ b/app/service/ResourceService.php @@ -114,6 +114,8 @@ class ResourceService extends Service public function delete($ids) { $recycle_service = new RecycleService(); + $audit_resource_service = new AuditResourceService(); + $resource_status_map = Resource::STATUS_MAP; foreach ($ids as $resource_id) { @@ -125,10 +127,10 @@ class ResourceService extends Service if ($resource->audit_status == $resource_status_map['success']) { //todo 审核通过的资源 删除走审核流程 - + $audit_resource_service->addOneAudit($resource, 2); } else { //其他状态的资源 删除直接放入回收站 - $recycle_service->putResourceInRecycle($resource); + $audit_resource_service->putOneResourceInRecycle($resource); } } diff --git a/app/service/Service.php b/app/service/Service.php index f77c333..c47aae0 100644 --- a/app/service/Service.php +++ b/app/service/Service.php @@ -2,6 +2,8 @@ namespace app\service; +use app\model\User; + class Service { // msg @@ -15,36 +17,35 @@ class Service // 成功编码 public $sucCode = 0; // 软删除数据 - public $delData; - // 错误编码 - public $errorCode = '50011'; - public $listCacheKey; - public $detailCacheKey; public $className; + public $user; + + public $user_id; + + public $seller_id; + protected $hidden = [ - 'password', 'seller_id' +// 'password', 'seller_id' ]; public function __construct($data = []) { - $this->delData = [ - 'is_del' => 2, - 'delete_time' => time(), - 'update_time' => time(), - ]; + $this->className = $this->getClassName(); - $this->listCacheKey = $this->className . '_cache_list'; - $this->detailCacheKey = $this->className . '_cache_detail'; + $this->moveMsg = lang('移动成功'); $this->copyMsg = lang('复制成功'); $this->getMsg = lang('获取成功'); $this->addMsg = lang('添加成功'); $this->updateMsg = lang('修改成功'); $this->delMsg = lang('删除成功'); - // parent::__construct($data); + $this->user = User::find(1); + $this->user_id = $this->user->id; +// $this->seller_id = $this->getSeller(); + } public function getClassName(): string @@ -52,4 +53,5 @@ class Service $reflection = new \ReflectionClass($this); return $reflection->getShortName(); } + }