diff --git a/app/model/Audit.php b/app/model/Audit.php new file mode 100644 index 0000000..9e57e17 --- /dev/null +++ b/app/model/Audit.php @@ -0,0 +1,9 @@ +belongsTo(User::class); - } - - /** - * 资源 普通素材 一对多 - */ - public function files() - { - return $this->hasMany(File::class, 'resource_id', 'id')->where('type', 1); - } - - /** - * 资源 授权素材 一对多 - */ - public function accreditFiles() - { - return $this->hasMany(File::class, 'resource_id', 'id')->where('type', 2); - } - - /** - * 资源 所有素材 - */ - public function allFiles() - { - return $this->hasMany(File::class, 'resource_id', 'id'); - } - - /** - * 子资源 - */ - public function childrenResources() - { - return $this->hasMany(Resource::class, 'parent_id', 'id'); - } + const STATUS_MAP = [ + 'not' => 0, + 'wait' => 1, + 'success' => 2, + 'fail' => 3 + ]; + + public function user() + { + return $this->belongsTo(User::class); + } + + /** + * 资源 普通素材 一对多 + */ + public function files() + { + return $this->hasMany(File::class, 'resource_id', 'id')->where('type', 1); + } + + /** + * 资源 授权素材 一对多 + */ + public function accreditFiles() + { + return $this->hasMany(File::class, 'resource_id', 'id')->where('type', 2); + } + + /** + * 资源 所有素材 + */ + public function allFiles() + { + return $this->hasMany(File::class, 'resource_id', 'id'); + } + + /** + * 子资源 + */ + public function childrenResources() + { + return $this->hasMany(Resource::class, 'parent_id', 'id'); + } } diff --git a/app/service/AuditService.php b/app/service/AuditService.php new file mode 100644 index 0000000..36a0d71 --- /dev/null +++ b/app/service/AuditService.php @@ -0,0 +1,31 @@ +saveAll($audit_ary); + + } +} diff --git a/app/service/ProcessService.php b/app/service/ProcessService.php new file mode 100644 index 0000000..8f2ce19 --- /dev/null +++ b/app/service/ProcessService.php @@ -0,0 +1,42 @@ +resource_status_map = Resource::STATUS_MAP; + } + + /** + * @param $insert_audit_flag 是否需要插入审核表 + * @return int + * 通过流程表 获取资源上传后的状态 + */ + public function getResouceUploadStatus($resource, $insert_audit_flag = false) + { + $status = $this->resource_status_map['not']; + + $process = (Process::where('flag', 'resource_upload')->find()); + //流程停用开启 上传后状态直接是审核通过 + if ($process->stop_using == 1) { + $status = $this->resource_status_map['success']; + } + + //自动发起开启 上传后状态直接是等待审核 + if ($process->auto_propose == 1) { + $status = $this->resource_status_map['wait']; + if ($insert_audit_flag) { + (new AuditService())->addAudit([$resource->id], 1); + } + } + + return $status; + } +} diff --git a/app/service/ResourceService.php b/app/service/ResourceService.php index 00b6cbc..bfcc3f1 100644 --- a/app/service/ResourceService.php +++ b/app/service/ResourceService.php @@ -22,7 +22,7 @@ class ResourceService extends Service //插入资源表 $resource = Resource::create($param); - //存在授权文件 插入授权文件表 + //存在授权文件 插入素材表 if ($param['copyright_type'] == 2 && isset($param['accredit_files'])) { (new FileService())->addAccreditFile($resource, $param['accredit_files']); } @@ -49,6 +49,9 @@ class ResourceService extends Service $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->save(); }