弹幕、分类下拉、属性下拉、
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\admin\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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,27 @@ class PostCategoryController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类树
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function preset(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$params = $request->all();
|
||||||
|
$result = $this->service->preset($params);
|
||||||
|
foreach ($result as $k => $r){
|
||||||
|
unset($r['created_at']);
|
||||||
|
unset($r['updated_at']);
|
||||||
|
$result[$k] = $this->indexFormat($r);
|
||||||
|
}
|
||||||
|
return $this->success($result, '获取分类下拉');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表页数据格式化
|
* 列表页数据格式化
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace app\admin\controller;
|
|||||||
use app\common\controller\BaseController;
|
use app\common\controller\BaseController;
|
||||||
use app\common\traits\crud\CrudControllerTrait;
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
use app\common\service\SkuAttributeService;
|
use app\common\service\SkuAttributeService;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
class SkuAttributeController extends BaseController
|
class SkuAttributeController extends BaseController
|
||||||
{
|
{
|
||||||
@@ -16,18 +17,63 @@ class SkuAttributeController extends BaseController
|
|||||||
$this->service = new SkuAttributeService();
|
$this->service = new SkuAttributeService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类树
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function preset(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$params = $request->all();
|
||||||
|
$result = $this->service->preset($params);
|
||||||
|
foreach ($result as $k => $r){
|
||||||
|
unset($r['created_at']);
|
||||||
|
unset($r['updated_at']);
|
||||||
|
$result[$k] = $this->indexFormat($r);
|
||||||
|
}
|
||||||
|
return $this->success($result, '获取分类下拉');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表页数据格式化
|
* 列表页数据格式化
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
// protected function indexFormat($data)
|
protected function indexFormat($data)
|
||||||
// {
|
{
|
||||||
// if (isset($data['created_at']))
|
if (isset($data['created_at']))
|
||||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
// if (isset($data['updated_at']))
|
if (isset($data['updated_at']))
|
||||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
// return $data;
|
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];
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建
|
||||||
|
*
|
||||||
|
* @param Request $request 请求对象
|
||||||
|
* @return mixed 返回创建成功的数据或信息
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'store');
|
||||||
|
$res = $this->service->serviceStore($request, $data);
|
||||||
|
return $this->success($res, '创建成功');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
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;
|
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
|
* 获取系统list
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace app\common\service;
|
namespace app\common\service;
|
||||||
|
|
||||||
|
use app\common\logic\PostCategoryLogic;
|
||||||
|
use app\common\logic\SkuAttributeLogic;
|
||||||
use app\common\validate\SkuAttributeValidate;
|
use app\common\validate\SkuAttributeValidate;
|
||||||
use app\common\traits\crud\CrudServiceTrait;
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
use app\common\model\SkuAttribute;
|
use app\common\model\SkuAttribute;
|
||||||
@@ -12,6 +14,7 @@ class SkuAttributeService
|
|||||||
|
|
||||||
use CrudServiceTrait;
|
use CrudServiceTrait;
|
||||||
|
|
||||||
|
protected $logic;
|
||||||
/**
|
/**
|
||||||
* 指定当前要操作的模型
|
* 指定当前要操作的模型
|
||||||
*/
|
*/
|
||||||
@@ -22,6 +25,11 @@ class SkuAttributeService
|
|||||||
*/
|
*/
|
||||||
protected $validator = SkuAttributeValidate::class;
|
protected $validator = SkuAttributeValidate::class;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->logic = (new SkuAttributeLogic());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取验证器
|
* 获取验证器
|
||||||
*/
|
*/
|
||||||
@@ -58,4 +66,43 @@ class SkuAttributeService
|
|||||||
|
|
||||||
return $config;
|
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' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ class IndexController
|
|||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'controller' => [
|
'controller' => [
|
||||||
'module' => 'common',
|
'module' => 'admin',
|
||||||
'name' => 'barrage'
|
'name' => 'barrage'
|
||||||
],
|
],
|
||||||
'model' => [
|
'model' => [
|
||||||
|
|||||||
@@ -104,6 +104,12 @@ Route::group('/common', function () {
|
|||||||
Route::group('/sku', function () {
|
Route::group('/sku', function () {
|
||||||
Route::any('/list', [app\common\controller\SkuController::class, 'index']);
|
Route::any('/list', [app\common\controller\SkuController::class, 'index']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 弹幕
|
||||||
|
Route::group('/barrage', function () {
|
||||||
|
Route::any('/list', [app\common\controller\BarrageController::class, 'index']);
|
||||||
|
Route::any('/store', [app\common\controller\BarrageController::class, 'store']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -170,6 +176,7 @@ Route::group('/admin', function () {
|
|||||||
// 帖子分类
|
// 帖子分类
|
||||||
Route::group('/category', function () {
|
Route::group('/category', function () {
|
||||||
Route::any('/list', [app\admin\controller\PostCategoryController::class, 'index']);
|
Route::any('/list', [app\admin\controller\PostCategoryController::class, 'index']);
|
||||||
|
Route::any('/preset', [app\admin\controller\PostCategoryController::class, 'preset']);
|
||||||
Route::any('/tree', [app\admin\controller\PostCategoryController::class, 'tree']);
|
Route::any('/tree', [app\admin\controller\PostCategoryController::class, 'tree']);
|
||||||
Route::any('/show', [app\admin\controller\PostCategoryController::class, 'show']);
|
Route::any('/show', [app\admin\controller\PostCategoryController::class, 'show']);
|
||||||
Route::any('/store', [app\admin\controller\PostCategoryController::class, 'store']);
|
Route::any('/store', [app\admin\controller\PostCategoryController::class, 'store']);
|
||||||
@@ -191,6 +198,7 @@ Route::group('/admin', function () {
|
|||||||
// sku属性
|
// sku属性
|
||||||
Route::group('/sku/attribute', function () {
|
Route::group('/sku/attribute', function () {
|
||||||
Route::any('/list', [app\admin\controller\SkuAttributeController::class, 'index']);
|
Route::any('/list', [app\admin\controller\SkuAttributeController::class, 'index']);
|
||||||
|
Route::any('/preset', [app\admin\controller\SkuAttributeController::class, 'preset']);
|
||||||
Route::any('/show', [app\admin\controller\SkuAttributeController::class, 'show']);
|
Route::any('/show', [app\admin\controller\SkuAttributeController::class, 'show']);
|
||||||
Route::any('/store', [app\admin\controller\SkuAttributeController::class, 'store']);
|
Route::any('/store', [app\admin\controller\SkuAttributeController::class, 'store']);
|
||||||
Route::any('/update', [app\admin\controller\SkuAttributeController::class, 'update']);
|
Route::any('/update', [app\admin\controller\SkuAttributeController::class, 'update']);
|
||||||
@@ -233,6 +241,15 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/update', [app\admin\controller\AgreementController::class, 'update']);
|
Route::any('/update', [app\admin\controller\AgreementController::class, 'update']);
|
||||||
Route::any('/destroy', [app\admin\controller\AgreementController::class, 'destroy']);
|
Route::any('/destroy', [app\admin\controller\AgreementController::class, 'destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 弹幕
|
||||||
|
Route::group('/barrage', function () {
|
||||||
|
Route::any('/list', [app\admin\controller\BarrageController::class, 'index']);
|
||||||
|
Route::any('/show', [app\admin\controller\BarrageController::class, 'show']);
|
||||||
|
Route::any('/store', [app\admin\controller\BarrageController::class, 'store']);
|
||||||
|
Route::any('/update', [app\admin\controller\BarrageController::class, 'update']);
|
||||||
|
Route::any('/destroy', [app\admin\controller\BarrageController::class, 'destroy']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user