2025-12-11 16:11:38 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
|
|
|
|
|
use app\common\validate\BarrageValidate;
|
|
|
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
|
|
|
use app\common\model\Barrage;
|
|
|
|
|
use support\Redis;
|
|
|
|
|
use support\Request;
|
|
|
|
|
|
|
|
|
|
class BarrageService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use CrudServiceTrait;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 指定当前要操作的模型
|
|
|
|
|
*/
|
|
|
|
|
protected string $modelClass = Barrage::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected $validator = BarrageValidate::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取验证器
|
|
|
|
|
*/
|
|
|
|
|
public function getValidator()
|
|
|
|
|
{
|
|
|
|
|
return new $this->validator;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 16:26:00 +08:00
|
|
|
/**
|
|
|
|
|
* 构造 CrudUtil 查询配置
|
|
|
|
|
*/
|
|
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
|
|
|
|
{
|
|
|
|
|
$p = $request->all();
|
|
|
|
|
|
|
|
|
|
$config = [];
|
|
|
|
|
$config['model'] = $this->modelClass;
|
|
|
|
|
switch ($scene) {
|
|
|
|
|
case 'default':
|
2025-12-17 14:30:10 +08:00
|
|
|
$config['order']['is_blocked'] = '0';
|
2025-12-11 16:26:00 +08:00
|
|
|
$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;
|
|
|
|
|
}
|
2025-12-11 16:11:38 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加前置处理
|
|
|
|
|
*/
|
|
|
|
|
public function beforeServiceStore($data, Request $request)
|
|
|
|
|
{
|
|
|
|
|
$data['user_id'] = $request->user->uid;;
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
}
|