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/AuditService.php b/app/service/AuditResourceService.php similarity index 85% rename from app/service/AuditService.php rename to app/service/AuditResourceService.php index d12b7c1..ac5c1db 100644 --- a/app/service/AuditService.php +++ b/app/service/AuditResourceService.php @@ -5,12 +5,37 @@ namespace app\service; use app\model\Audit; use app\model\Resource; -class AuditService extends Service +/** + * 该service 负责处理资源相关审核 + */ +class AuditResourceService extends Service { + + const TARGET_TYPE = 1; + + /** + * 添加一条资源审核记录 (上传/删除) + * @param $target + * @param $type 1上传 2删除 + * @return void + */ + public function addOneAudit($resource, $type) + { + + $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'); + dd($audit); + $audit->save(); + } + /** * @param $ids 资源/内容 数组 * @param $target_type 1资源 2内容 - * @param $type 1上传 2下载 + * @param $type 1上传 2删除 * @param $status 1待审核 2审核通过 3审核失败 * @return void * 批量添加审核记录表 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(); } + }