邮箱列表

This commit is contained in:
2025-05-26 11:19:29 +08:00
parent ff07c5bcd9
commit 80de64ad43
5 changed files with 215 additions and 0 deletions
@@ -0,0 +1,81 @@
<?php
namespace app\console\controller;
use support\Request;
use support\Response;
use app\console\model\SubscribeModel;
use app\console\service\SubscribeService;
use app\console\validate\SubscribeValidator;
use app\mzl\common\controller\BaseController;
class SubscribeController extends BaseController
{
/**
* 不需要验证token的接口
* @var array
*/
protected $noNeedJwt = [];
/**
* 验证器
*/
protected mixed $validator = SubscribeValidator::class;
/**
* 返回业务 Service 实例
*/
protected function getService()
{
return new SubscribeService(new SubscribeModel());
}
/**
* 额外字段处理 (根据场景处理)
* @param array $item
* @param string $scene
* @return array
*/
protected function postProcessItem(array $item, string $scene): array
{
if ($scene === 'default') {
}
return $item;
}
/**
* 参数预处理 (根据场景处理)
* @param Request $request
* @param string $scene
* @return array
*/
protected function prepareParams(Request $request, string $scene): array
{
$params = parent::prepareParams($request, $scene);
if ($scene === 'default') {
}
return $params;
}
/**
* 分页
*
* @param Request $request 请求对象
* @return Response 响应对象
*/
public function index(Request $request, string $scene = 'default'): Response
{
try {
return parent::index($request, $scene);
} catch (\Throwable $th) {
return $this->errorResponse($th->getMessage());
}
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace app\console\model;
use support\Model;
/**
* SubscribeModel
*/
class SubscribeModel extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'hs_subscribe';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
/**
* 模型的数据字段的保存格式。
*
* @var string
*/
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'email', 'ip', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace app\console\service;
use app\console\model\SubscribeModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class SubscribeService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return SubscribeModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
$keyword = $params['keyword'] ?? '';
return [
'filters' => [
// ['field' => '***', 'operator' => '=', 'value' => '***']
],
'fields' => ['id', 'email', 'ip', 'created_at', 'updated_at'],
'relations' => [],
'sorts' => [
['field' => 'created_at', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
}
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace app\console\validate;
use think\Validate;
class SubscribeValidator extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+2
View File
@@ -181,6 +181,8 @@ Route::group('/console', function() {
Route::any('/location/{id}/delete', [\app\console\controller\LocationController::class, 'destroy']);
Route::any('/location/{id}/detail', [\app\console\controller\LocationController::class, 'show']);
Route::any('/location/preset', [\app\console\controller\LocationController::class, 'presets']);
// 邮箱列表
Route::any('/email/subscribe', [\app\console\controller\SubscribeController::class, 'index']);
});
// ====== ====== ====== 后台管理 ====== ====== ======