12 changed files with 286 additions and 176 deletions
-
26app/controller/Audit/AuditController.php
-
18app/controller/substance/ResourceController.php
-
26app/model/Audit.php
-
46app/service/AuditContentService.php
-
135app/service/AuditResourceService.php
-
78app/service/AuditService.php
-
16app/service/ProcessService.php
-
35app/service/RecycleResourceService.php
-
39app/service/RecycleService.php
-
34app/service/ResourceService.php
-
2app/service/Service.php
-
1route/substance.php
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
namespace app\service; |
|||
|
|||
use app\model\Audit; |
|||
use app\model\Content; |
|||
use app\model\Resource; |
|||
|
|||
/** |
|||
* 该service 负责处理资源相关审核 |
|||
*/ |
|||
class AuditContentService extends AuditService |
|||
{ |
|||
public $model; |
|||
const TARGET_TYPE = 2; |
|||
|
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
$this->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; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
<?php |
|||
|
|||
namespace app\service; |
|||
|
|||
use app\model\Audit; |
|||
use app\model\Resource; |
|||
|
|||
/** |
|||
* 该service 负责处理资源相关审核 |
|||
*/ |
|||
class AuditService extends Service |
|||
{ |
|||
public function __construct($data = []) |
|||
{ |
|||
parent::__construct($data); |
|||
} |
|||
|
|||
/** |
|||
* @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], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* 修改审核表 和 目标表 审核状态 |
|||
* @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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
namespace app\service; |
|||
|
|||
use app\exception\ModelException; |
|||
use app\model\Recycle; |
|||
use app\model\Resource; |
|||
use app\model\ResourceDir; |
|||
use app\model\Share; |
|||
|
|||
class RecycleResourceService extends Service |
|||
{ |
|||
|
|||
const TABLE_NAME = 'resource'; |
|||
//todo 需要一个脚本处理回收站过期的了数据
|
|||
|
|||
/** |
|||
* 添加一个资源到回收站 |
|||
* @param Resource $resource |
|||
* @return bool |
|||
*/ |
|||
public function addOneRecycle(Resource $resource) |
|||
{ |
|||
//todo seller_id user_id 处理
|
|||
$recycle = new Recycle(); |
|||
$recycle->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; |
|||
} |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace app\service; |
|||
|
|||
use app\exception\ModelException; |
|||
use app\model\Recycle; |
|||
use app\model\Resource; |
|||
use app\model\ResourceDir; |
|||
use app\model\Share; |
|||
|
|||
class RecycleService extends Service |
|||
{ |
|||
|
|||
//todo 需要一个脚本处理回收站过期的了数据
|
|||
/** |
|||
* 添加一个资源到回收站 |
|||
* @param Resource $resource |
|||
* @return array |
|||
*/ |
|||
public function putOneResourceInRecycle(Resource $resource) |
|||
{ |
|||
//todo seller_id user_id 处理
|
|||
$resource_dir_service = new ResourceDirService(); |
|||
$recycle = new Recycle(); |
|||
$recycle->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, '加入回收站成功'); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue