Browse Source

批量添加审核记录

master
unknown 1 year ago
parent
commit
919f9bc12c
  1. 9
      app/model/Audit.php
  2. 79
      app/model/Resource.php
  3. 31
      app/service/AuditService.php
  4. 42
      app/service/ProcessService.php
  5. 5
      app/service/ResourceService.php

9
app/model/Audit.php

@ -0,0 +1,9 @@
<?php
namespace app\model;
use app\exception\ModelException;
class Audit extends Model
{
}

79
app/model/Resource.php

@ -8,40 +8,47 @@ use app\exception\ModelException;
class Resource extends Model class Resource extends Model
{ {
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');
}
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');
}
} }

31
app/service/AuditService.php

@ -0,0 +1,31 @@
<?php
namespace app\service;
use app\model\Audit;
class AuditService
{
/**
* @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) {
$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);
}
}

42
app/service/ProcessService.php

@ -0,0 +1,42 @@
<?php
namespace app\service;
use app\model\Process;
use app\model\Resource;
class ProcessService
{
public $resource_status_map;
public function __construct()
{
$this->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;
}
}

5
app/service/ResourceService.php

@ -22,7 +22,7 @@ class ResourceService extends Service
//插入资源表 //插入资源表
$resource = Resource::create($param); $resource = Resource::create($param);
//存在授权文件 插入授权文件
//存在授权文件 插入素材
if ($param['copyright_type'] == 2 && isset($param['accredit_files'])) { if ($param['copyright_type'] == 2 && isset($param['accredit_files'])) {
(new FileService())->addAccreditFile($resource, $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_size = $file_size_and_count['file_size'];
$resource->file_count = $file_size_and_count['file_count']; $resource->file_count = $file_size_and_count['file_count'];
//todo 还有状态的啥的 //todo 还有状态的啥的
$process_service = new ProcessService();
$resource->audit_status = $process_service->getResouceUploadStatus($resource, true);
$resource->save(); $resource->save();
} }

Loading…
Cancel
Save