弹幕、分类下拉、属性下拉、
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\BarrageService;
|
||||
|
||||
class BarrageController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new BarrageService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\Barrage;
|
||||
|
||||
class BarrageLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = Barrage::class;
|
||||
|
||||
}
|
||||
@@ -14,4 +14,8 @@ class SkuAttributeLogic
|
||||
*/
|
||||
protected string $modelClass = SkuAttribute::class;
|
||||
|
||||
public function getList($where)
|
||||
{
|
||||
return SkuAttribute::where($where)->orderBy('sort','desc')->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class Barrage extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'barrage';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'user_id', 'content', 'type', 'color', 'font_size', 'timeline', 'status', 'is_blocked', 'ip', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$data['user_id'] = $request->user->uid;;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,21 @@ class PostCategoryService
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统list
|
||||
*/
|
||||
public function preset($params)
|
||||
{
|
||||
$where = [];
|
||||
if(isset($params['parent_id']) && $params['parent_id']) {
|
||||
$where['parent_id'] = $params['parent_id'];
|
||||
}else{
|
||||
$where['parent_id'] = 0;
|
||||
}
|
||||
$result = $this->logic->getList($where)->toArray();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统list
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\PostCategoryLogic;
|
||||
use app\common\logic\SkuAttributeLogic;
|
||||
use app\common\validate\SkuAttributeValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SkuAttribute;
|
||||
@@ -12,6 +14,7 @@ class SkuAttributeService
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
protected $logic;
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
@@ -22,6 +25,11 @@ class SkuAttributeService
|
||||
*/
|
||||
protected $validator = SkuAttributeValidate::class;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = (new SkuAttributeLogic());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
@@ -58,4 +66,43 @@ class SkuAttributeService
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
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);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceUpdate($data, Request $request)
|
||||
{
|
||||
// $options = [];
|
||||
// foreach ($data['options_json'] as $v){
|
||||
// $options[] = $v['value'];
|
||||
// }
|
||||
// $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统list
|
||||
*/
|
||||
public function preset($params)
|
||||
{
|
||||
$where = [];
|
||||
if(isset($params['category_id']) && $params['category_id']) {
|
||||
$where['category_id'] = $params['category_id'];
|
||||
}
|
||||
$result = $this->logic->getList($where)->toArray();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class BarrageValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user