feat(fsgx): 完成全部24项开发任务 Phase1-7
Phase1 后端核心:
- 新增 fsgx_v1.sql 迁移脚本(is_queue_goods/frozen_points/available_points/no_assess)
- SystemConfigServices 返佣设置扩展(周期人数/分档比例/范围/时机)
- StoreOrderCreateServices 周期循环佣金计算
- StoreOrderTakeServices 佣金发放后同步冻结积分
- StoreProductServices/StoreProduct 保存 is_queue_goods
Phase2 后端接口:
- GET /api/hjf/brokerage/progress 佣金周期进度
- GET /api/hjf/assets/overview 资产总览
- HjfPointsServices 每日 frozen_points 0.4‰ 释放定时任务
- PUT /adminapi/hjf/member/{uid}/no_assess 不考核接口
- GET /adminapi/hjf/points/release_log 积分日志接口
Phase3 前端清理:
- hjfCustom.js 路由精简(仅保留 points/log)
- hjfQueue.js/hjfMember.js API 清理/重定向至 CRMEB 原生接口
- pages.json 公排→推荐佣金/佣金记录/佣金规则
Phase4-5 前端改造:
- queue/status.vue 推荐佣金进度页整体重写
- 商品详情/订单确认/支付结果页文案与逻辑改造
- 个人中心/资产页/引导页/规则页文案改造
- HjfQueueProgress/HjfRefundNotice/HjfAssetCard 组件改造
- 推广中心嵌入佣金进度摘要
- hjfMockData.js 全量更新(公排字段→佣金字段)
Phase6 Admin 增强:
- 用户列表新增 frozen_points/available_points 列及不考核操作按钮
- hjfPoints.js USE_MOCK=false 对接真实积分日志接口
Phase7 配置文档:
- docs/fsgx-phase7-config-checklist.md 后台配置与全链路验收清单
Made-with: Cursor
This commit is contained in:
87
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/Base.php
vendored
Normal file
87
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/Base.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class Base extends TestCase {
|
||||
static $ROOT_PATH = __DIR__ . "/../vendor/topthink/think";
|
||||
static $RUNTIME_PATH = __DIR__ . "/../runtime/";
|
||||
|
||||
protected $app;
|
||||
protected $throttle_config = [];
|
||||
protected $middleware_file = __DIR__ . "/config/global-middleware.php";
|
||||
protected $middleware_type = 'global';
|
||||
|
||||
/**
|
||||
* thinkphp 一般运行在 php-fpm 模式下,每次处理请求都要重新加载配置文件
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
function get_response(\think\Request $request): \think\Response {
|
||||
// 创建 \think\App 对象,设置配置
|
||||
$app = new GCApp(static::$ROOT_PATH);
|
||||
$app->setRuntimePath(static::$RUNTIME_PATH);
|
||||
|
||||
// 加载中间件
|
||||
$app->middleware->import(include $this->middleware_file, $this->middleware_type);
|
||||
// 设置 throttle 配置
|
||||
$app->config->set($this->throttle_config, 'throttle');
|
||||
|
||||
$response = $app->http->run($request);
|
||||
$app->refClear();
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
// 每次测试完毕都需要清理 runtime cache 目录,避免影响其他单元测试
|
||||
$cache_dir = static::$RUNTIME_PATH . "cache";
|
||||
$dirs = glob($cache_dir . '/*', GLOB_ONLYDIR);
|
||||
foreach ($dirs as $dir) {
|
||||
$files = glob($dir . '/*.php');
|
||||
foreach ($files as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
// 删除 cache 下的空目录
|
||||
foreach ($dirs as $dir) {
|
||||
rmdir($dir);
|
||||
}
|
||||
unset($cache_dir);
|
||||
unset($dirs);
|
||||
gc_collect_cycles(); // 进行垃圾回收
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认的 throttle 基础配置信息
|
||||
* @return array
|
||||
*/
|
||||
function get_default_throttle_config(): array {
|
||||
static $config = []; // 默认配置从文件中读取,可以设置为静态变量
|
||||
if (!$config) {
|
||||
$config = include dirname(__DIR__) . "/src/config.php";
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置中间件配置文件
|
||||
* @param string $file 文件的路径 eg: $this->app->getBasePath() . 'middleware.php'
|
||||
* @param string $type 类型:global 全局;route 路由;controller 控制器
|
||||
*/
|
||||
function set_middleware(string $file, string $type = 'global') {
|
||||
$this->middleware_file = $file;
|
||||
$this->middleware_type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 throttle 配置
|
||||
* @param array $config
|
||||
*/
|
||||
function set_throttle_config(array $config) {
|
||||
$this->throttle_config = $config;
|
||||
}
|
||||
|
||||
}
|
||||
97
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/CustomCacheTest.php
vendored
Normal file
97
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/CustomCacheTest.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 自定义 cache 类
|
||||
*/
|
||||
namespace tests;
|
||||
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use think\middleware\Throttle;
|
||||
|
||||
class CustomCache implements CacheInterface {
|
||||
protected $data = [];
|
||||
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return isset($this->data[$key]) ? $this->data[$key] : $default;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete(string $key): bool { return true; }
|
||||
public function clear(): bool { return true; }
|
||||
public function getMultiple(iterable $keys, mixed $default = null): iterable { return [];}
|
||||
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; }
|
||||
public function deleteMultiple(iterable $keys): bool { return true; }
|
||||
public function has(string $key): bool { return true; }
|
||||
}
|
||||
|
||||
class DummyCache implements CacheInterface {
|
||||
public function get($key, $default = null): mixed
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool { return true; }
|
||||
public function delete(string $key): bool { return true; }
|
||||
public function clear(): bool { return true; }
|
||||
public function getMultiple(iterable $keys, mixed $default = null): iterable { return [];}
|
||||
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; }
|
||||
public function deleteMultiple(iterable $keys): bool { return true; }
|
||||
public function has(string $key): bool { return true; }
|
||||
}
|
||||
|
||||
|
||||
class CustomCacheTest extends Base {
|
||||
|
||||
function visit(int $count): int
|
||||
{
|
||||
$allowCount = 0;
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$request = new \think\Request();
|
||||
$request->setMethod('GET');
|
||||
$request->setUrl('/');
|
||||
|
||||
$response = $this->get_response($request);
|
||||
if ($response->getCode() == 200) {
|
||||
$allowCount++;
|
||||
}
|
||||
}
|
||||
return $allowCount;
|
||||
}
|
||||
|
||||
function test_custom_cache()
|
||||
{
|
||||
$cache = new CustomCache();
|
||||
$config = $this->get_default_throttle_config();
|
||||
$config['visit_rate'] = '10/m';
|
||||
$config['key'] = function(Throttle $throttle, \think\Request $request) use ($cache) {
|
||||
$throttle->setCache($cache);
|
||||
return true;
|
||||
};
|
||||
|
||||
$this->set_throttle_config($config);
|
||||
|
||||
$this->assertEquals(10, $this->visit(200));
|
||||
}
|
||||
|
||||
function test_dummy_cache()
|
||||
{
|
||||
$cache = new DummyCache();
|
||||
$config = $this->get_default_throttle_config();
|
||||
$config['visit_rate'] = '10/m';
|
||||
$config['key'] = function(Throttle $throttle, \think\Request $request) use ($cache) {
|
||||
$throttle->setCache($cache);
|
||||
return true;
|
||||
};
|
||||
|
||||
$this->set_throttle_config($config);
|
||||
$this->assertEquals(200, $this->visit(200));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
75
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/GCApp.php
vendored
Normal file
75
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/GCApp.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 默认的 \think\App 的实例初始化后会在一些地方创建对它的引用,
|
||||
* 多数是在静态变量里,这就导致它不能被自动垃圾回收。
|
||||
* 因此创建 GCApp 作为其子类,添加清理这些引用的处理的方法。
|
||||
*/
|
||||
|
||||
namespace tests;
|
||||
|
||||
use think\App;
|
||||
use think\initializer\BootService;
|
||||
use think\initializer\Error;
|
||||
use think\initializer\RegisterService;
|
||||
use think\Model;
|
||||
use think\Validate;
|
||||
|
||||
|
||||
class GCError extends Error {
|
||||
/**
|
||||
* 从 parent::init() 中移除 register_shutdown_function
|
||||
* @param App $app
|
||||
*/
|
||||
public function init(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
error_reporting(E_ALL);
|
||||
set_error_handler([$this, 'appError']);
|
||||
set_exception_handler([$this, 'appException']);
|
||||
// register_shutdown_function([$this, 'appShutdown']); // 移除
|
||||
}
|
||||
}
|
||||
|
||||
class GCValidate extends Validate {
|
||||
public static function cleanMaker() { static::$maker = []; }
|
||||
}
|
||||
|
||||
class GCModel extends Model {
|
||||
public static function cleanMaker() { static::$maker = []; }
|
||||
}
|
||||
|
||||
/**
|
||||
* 可被自动 gc 的,但需要手动调用 refClear 函数
|
||||
* Class GCApp
|
||||
* @package tests
|
||||
*/
|
||||
class GCApp extends App {
|
||||
protected $initializers = [ // 覆盖父类
|
||||
GCError::class, // 去掉 register_shutdown_function
|
||||
RegisterService::class, // 原来就有的
|
||||
BootService::class, // 原来就有的
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加清理函数
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function refClear()
|
||||
{
|
||||
$this->route->clear(); // 清理路由规则
|
||||
// 清理绑定在 App 的实例
|
||||
$names = [];
|
||||
foreach ($this->getIterator() as $name=>$_v) {
|
||||
$names[] = $name;
|
||||
}
|
||||
foreach ($names as $name) {
|
||||
$this->delete($name);
|
||||
}
|
||||
// 清理异常 handler
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
GCValidate::cleanMaker();
|
||||
GCModel::cleanMaker();
|
||||
}
|
||||
}
|
||||
51
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/ResidentMemoryTest.php
vendored
Normal file
51
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/ResidentMemoryTest.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
|
||||
/**
|
||||
* 常驻内存型的单元测试,当 TP 运行在常驻内存型的时候。
|
||||
* 一个 App 实例,处理多次请求
|
||||
* Class ResidentMemoryTest
|
||||
* @package tests
|
||||
*/
|
||||
class ResidentMemoryTest extends Base
|
||||
{
|
||||
public function test_resident_memory()
|
||||
{
|
||||
$app = new GCApp(static::$ROOT_PATH);
|
||||
$app->setRuntimePath(static::$RUNTIME_PATH);
|
||||
$app->middleware->import(include $this->middleware_file, $this->middleware_type);
|
||||
$app->config->set($this->get_default_throttle_config(), 'throttle');
|
||||
|
||||
// 处理多个请求
|
||||
$allowCount1 = 0;
|
||||
$allowCount2 = 0;
|
||||
|
||||
for ($i = 0; $i < 200; $i++) {
|
||||
// 受访问频率限制
|
||||
$request = new \think\Request();
|
||||
$request->setMethod('GET');
|
||||
$request->setUrl('/');
|
||||
$response = $app->http->run($request);
|
||||
if ($response->getCode() == 200) {
|
||||
$allowCount1++;
|
||||
}
|
||||
|
||||
// 不受访问频率限制
|
||||
$request = new \think\Request();
|
||||
$request->setMethod('POST');
|
||||
$request->setUrl('/');
|
||||
|
||||
$response = $app->http->run($request);
|
||||
if ($response->getCode() == 200) {
|
||||
$allowCount2++;
|
||||
}
|
||||
}
|
||||
|
||||
$app->refClear();
|
||||
$this->assertEquals(100, $allowCount1);
|
||||
$this->assertEquals(200, $allowCount2);
|
||||
}
|
||||
}
|
||||
53
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/ThrottleDefaultConfigTest.php
vendored
Normal file
53
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/ThrottleDefaultConfigTest.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
/**
|
||||
* 默认配置的单元测试
|
||||
* Class ThrottleDefaultConfig
|
||||
* @package tests
|
||||
*/
|
||||
class ThrottleDefaultConfigTest extends Base
|
||||
{
|
||||
function __construct($name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
$this->set_throttle_config($this->get_default_throttle_config());
|
||||
}
|
||||
|
||||
function test_visit_rate()
|
||||
{
|
||||
// 默认的访问频率为 '100/m'
|
||||
$allowCount = 0;
|
||||
for ($i = 0; $i < 200; $i++) {
|
||||
$request = new \think\Request();
|
||||
$request->setMethod('GET');
|
||||
$request->setUrl('/');
|
||||
|
||||
$response = $this->get_response($request);
|
||||
if ($response->getCode() == 200) {
|
||||
$allowCount++;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(100, $allowCount);
|
||||
}
|
||||
|
||||
function test_unlimited_request_method()
|
||||
{
|
||||
// 默认只限制了 ['GET', 'HEAD'] ,对 POST 不做限制
|
||||
$allowCount = 0;
|
||||
for ($i = 0; $i < 200; $i++) {
|
||||
$request = new \think\Request();
|
||||
$request->setMethod('POST');
|
||||
$request->setUrl('/');
|
||||
|
||||
$response = $this->get_response($request);
|
||||
if ($response->getCode() == 200) {
|
||||
$allowCount++;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(200, $allowCount);
|
||||
}
|
||||
|
||||
}
|
||||
82
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/VisitRateTest.php
vendored
Normal file
82
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/VisitRateTest.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 访问频率的单元测试
|
||||
*/
|
||||
|
||||
namespace tests;
|
||||
|
||||
use think\middleware\Throttle;
|
||||
|
||||
class VisitRateTest extends Base
|
||||
{
|
||||
function is_visit_allow(string $uri): bool
|
||||
{
|
||||
$request = new \think\Request();
|
||||
$request->setUrl($uri);
|
||||
$response = $this->get_response($request);
|
||||
return $response->getCode() == 200;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据请求的 url 设置不同的访问频率
|
||||
*/
|
||||
function test_custom_visit_rate() {
|
||||
$config = $this->get_default_throttle_config();
|
||||
$config['key'] = function(Throttle $throttle, \think\Request $request) {
|
||||
$path = $request->url();
|
||||
if ($path === '/path1') {
|
||||
$throttle->setRate('10/m');
|
||||
} else if ($path === '/path2') {
|
||||
$throttle->setRate('20/m');
|
||||
} else if ($path === '/path3') {
|
||||
$throttle->setRate('30/m');
|
||||
}
|
||||
return $path;
|
||||
};
|
||||
$this->set_throttle_config($config);
|
||||
|
||||
$allowCount0 = 0;
|
||||
$allowCount1 = 0;
|
||||
$allowCount2 = 0;
|
||||
$allowCount3 = 0;
|
||||
for ($i = 0; $i < 200; $i++) {
|
||||
if ($this->is_visit_allow('/')) {
|
||||
$allowCount0++;
|
||||
}
|
||||
if ($this->is_visit_allow('/path1')) {
|
||||
$allowCount1++;
|
||||
}
|
||||
if ($this->is_visit_allow('/path2')) {
|
||||
$allowCount2++;
|
||||
}
|
||||
if ($this->is_visit_allow('/path3')) {
|
||||
$allowCount3++;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(100, $allowCount0);
|
||||
$this->assertEquals(10, $allowCount1);
|
||||
$this->assertEquals(20, $allowCount2);
|
||||
$this->assertEquals(30, $allowCount3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问 2 个周期,成功次数 2 * count
|
||||
*/
|
||||
function test_visit_rate_more_period() {
|
||||
$config = $this->get_default_throttle_config();
|
||||
$config['visit_rate'] = '10/s';
|
||||
$this->set_throttle_config($config);
|
||||
|
||||
$allowCount = 0;
|
||||
$micro_start = microtime(true);
|
||||
// 由于缓存过期时间只精确到秒,因此周期差需要延后约 1 秒,这里取 0.9 秒
|
||||
while (microtime(true) - $micro_start < 2 + 0.9) {
|
||||
if ($this->is_visit_allow('/')) {
|
||||
$allowCount++;
|
||||
}
|
||||
usleep(10); // 请求均匀分布
|
||||
}
|
||||
$this->assertEquals(20, $allowCount);
|
||||
}
|
||||
}
|
||||
7
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/config/global-middleware.php
vendored
Normal file
7
pro_v3.5.1_副本/vendor/topthink/think-throttle/tests/config/global-middleware.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
// 全局中间件定义文件
|
||||
return [
|
||||
\think\middleware\Throttle::class,
|
||||
// Session初始化
|
||||
\think\middleware\SessionInit::class
|
||||
];
|
||||
Reference in New Issue
Block a user