This commit is contained in:
2025-12-23 17:01:44 +08:00
parent 53eb52d641
commit 2a0ab5f361
7 changed files with 248 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\NoticeService;
class NoticeController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new NoticeService();
}
/**
* 列表页数据格式化
*
* @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,33 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\NoticeService;
class NoticeController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new NoticeService();
}
/**
* 列表页数据格式化
*
* @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;
// }
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\Notice;
class NoticeLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Notice::class;
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class Notice extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'notice';
/**
* 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 = [];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace app\common\service;
use app\common\validate\NoticeValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\Notice;
use support\Request;
class NoticeService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Notice::class;
/**
* 验证器
*/
protected $validator = NoticeValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
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['where']['status'] = 1;
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
break;
case 'index':
// $config['where']['status'] = 1;
if (isset($p['status']) && !empty($p['status'])) {
$config['where']['status'] = $p['status'];
}
$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;
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\common\validate;
use think\Validate;
class NoticeValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+15
View File
@@ -106,6 +106,12 @@ Route::group('/common', function () {
Route::any('/list', [app\common\controller\SkuController::class, 'index']);
Route::any('/preset', [app\common\controller\SkuController::class, 'preset']);
});
// 公告
Route::group('/notice', function () {
Route::any('/list', [app\admin\controller\NoticeController::class, 'index']);
Route::any('/show', [app\admin\controller\NoticeController::class, 'show']);
});
});
@@ -227,6 +233,15 @@ Route::group('/admin', function () {
Route::any('/update', [app\admin\controller\SkuController::class, 'update']);
Route::any('/destroy', [app\admin\controller\SkuController::class, 'destroy']);
});
// 公告
Route::group('/notice', function () {
Route::any('/list', [app\admin\controller\NoticeController::class, 'index']);
Route::any('/show', [app\admin\controller\NoticeController::class, 'show']);
Route::any('/store', [app\admin\controller\NoticeController::class, 'store']);
Route::any('/update', [app\admin\controller\NoticeController::class, 'update']);
Route::any('/destroy', [app\admin\controller\NoticeController::class, 'destroy']);
});
});