弹幕屏蔽

This commit is contained in:
2025-12-11 16:26:00 +08:00
parent 291d06fd94
commit 69a30ae5e4
5 changed files with 83 additions and 8 deletions
@@ -4,6 +4,7 @@ namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\BarrageService;
use support\Request;
class BarrageController extends BaseController
{
@@ -16,6 +17,25 @@ class BarrageController extends BaseController
$this->service = new BarrageService();
}
/**
* 获取列表
*
* @param Request $request 请求对象
* @return mixed 返回分页数据及总数
*/
public function index(Request $request)
{
try {
$raw = $this->service->serviceList($request, 'default');
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
? [$this, 'indexFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
/**
* 列表页数据格式化
*
@@ -53,9 +53,9 @@ class SkuAttributeController extends BaseController
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['options_json'])){
$data['options_json'] = json_decode($data['options_json'], true);
// foreach ($data['options_json'] as $k => $v){
// $data['options_json'][$k] = ['value' => $v];
// }
foreach ($data['options_json'] as $k => $v){
$data['options_json'][$k] = ['value' => $v];
}
}
return $data;
}
@@ -4,6 +4,7 @@ namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\BarrageService;
use support\Request;
class BarrageController extends BaseController
{
@@ -16,6 +17,25 @@ class BarrageController extends BaseController
$this->service = new BarrageService();
}
/**
* 获取列表
*
* @param Request $request 请求对象
* @return mixed 返回分页数据及总数
*/
public function index(Request $request)
{
try {
$raw = $this->service->serviceList($request, 'index');
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
? [$this, 'indexFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
/**
* 列表页数据格式化
*
+35
View File
@@ -31,6 +31,41 @@ class BarrageService
return new $this->validator;
}
/**
* 构造 CrudUtil 查询配置
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'default':
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
break;
case 'index':
$config['order']['is_blocked'] = '0';
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
break;
case 'show':
$config['where']['id'] = $p['id'];
$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
/**
* 添加前置处理
+5 -5
View File
@@ -72,11 +72,11 @@ class SkuAttributeService
*/
public function beforeServiceStore($data, Request $request)
{
// $options = [];
// foreach ($data['options_json'] as $v){
// $options[] = $v['value'];
// }
// $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE);
$options = [];
foreach ($data['options_json'] as $v){
$options[] = $v['value'];
}
$data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE);
return $data;
}