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:
223
pro_v3.5.1_副本/vendor/open-smf/connection-pool/README.md
vendored
Normal file
223
pro_v3.5.1_副本/vendor/open-smf/connection-pool/README.md
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
# Connection pool
|
||||
A common connection pool based on Swoole is usually used as the database connection pool.
|
||||
|
||||
[](https://github.com/open-smf/connection-pool/releases)
|
||||
[](https://secure.php.net)
|
||||
[](https://packagist.org/packages/open-smf/connection-pool)
|
||||
[](LICENSE)
|
||||
|
||||
## Requirements
|
||||
|
||||
| Dependency | Requirement |
|
||||
| -------- | -------- |
|
||||
| [PHP](https://secure.php.net/manual/en/install.php) | `>=7.0.0` |
|
||||
| [Swoole](https://github.com/swoole/swoole-src) | `>=4.2.9` `Recommend 4.2.13+` |
|
||||
|
||||
## Install
|
||||
> Install package via [Composer](https://getcomposer.org/).
|
||||
|
||||
```shell
|
||||
composer require "open-smf/connection-pool:~1.0"
|
||||
```
|
||||
|
||||
## Usage
|
||||
> See more [examples](examples).
|
||||
|
||||
- Available connectors
|
||||
|
||||
| Connector | Connection description |
|
||||
| -------- | -------- |
|
||||
| CoroutineMySQLConnector | Instance of `Swoole\Coroutine\MySQL` |
|
||||
| CoroutinePostgreSQLConnector | Instance of `Swoole\Coroutine\PostgreSQL`, require configuring `Swoole` with `--enable-coroutine-postgresql`|
|
||||
| CoroutineRedisConnector | Instance of `Swoole\Coroutine\Redis` |
|
||||
| PhpRedisConnector | Instance of `Redis`, require [redis](https://pecl.php.net/package/redis) |
|
||||
| PDOConnector | Instance of `PDO`, require [PDO](https://www.php.net/manual/en/book.pdo.php) |
|
||||
| YourConnector | `YourConnector` must implement interface `ConnectorInterface`, any object can be used as a connection instance |
|
||||
|
||||
- Basic usage
|
||||
|
||||
```php
|
||||
use Smf\ConnectionPool\ConnectionPool;
|
||||
use Smf\ConnectionPool\Connectors\CoroutineMySQLConnector;
|
||||
use Swoole\Coroutine\MySQL;
|
||||
|
||||
go(function () {
|
||||
// All MySQL connections: [10, 30]
|
||||
$pool = new ConnectionPool(
|
||||
[
|
||||
'minActive' => 10,
|
||||
'maxActive' => 30,
|
||||
'maxWaitTime' => 5,
|
||||
'maxIdleTime' => 20,
|
||||
'idleCheckInterval' => 10,
|
||||
],
|
||||
new CoroutineMySQLConnector,
|
||||
[
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'user' => 'root',
|
||||
'password' => 'xy123456',
|
||||
'database' => 'mysql',
|
||||
'timeout' => 10,
|
||||
'charset' => 'utf8mb4',
|
||||
'strict_type' => true,
|
||||
'fetch_mode' => true,
|
||||
]
|
||||
);
|
||||
echo "Initializing connection pool\n";
|
||||
$pool->init();
|
||||
defer(function () use ($pool) {
|
||||
echo "Closing connection pool\n";
|
||||
$pool->close();
|
||||
});
|
||||
|
||||
echo "Borrowing the connection from pool\n";
|
||||
/**@var MySQL $connection */
|
||||
$connection = $pool->borrow();
|
||||
|
||||
$status = $connection->query('SHOW STATUS LIKE "Threads_connected"');
|
||||
|
||||
echo "Return the connection to pool as soon as possible\n";
|
||||
$pool->return($connection);
|
||||
|
||||
var_dump($status);
|
||||
});
|
||||
```
|
||||
|
||||
- Usage in Swoole Server
|
||||
|
||||
```php
|
||||
use Smf\ConnectionPool\ConnectionPool;
|
||||
use Smf\ConnectionPool\ConnectionPoolTrait;
|
||||
use Smf\ConnectionPool\Connectors\CoroutineMySQLConnector;
|
||||
use Smf\ConnectionPool\Connectors\PhpRedisConnector;
|
||||
use Swoole\Coroutine\MySQL;
|
||||
use Swoole\Http\Request;
|
||||
use Swoole\Http\Response;
|
||||
use Swoole\Http\Server;
|
||||
|
||||
class HttpServer
|
||||
{
|
||||
use ConnectionPoolTrait;
|
||||
|
||||
protected $swoole;
|
||||
|
||||
public function __construct(string $host, int $port)
|
||||
{
|
||||
$this->swoole = new Server($host, $port);
|
||||
|
||||
$this->setDefault();
|
||||
$this->bindWorkerEvents();
|
||||
$this->bindHttpEvent();
|
||||
}
|
||||
|
||||
protected function setDefault()
|
||||
{
|
||||
$this->swoole->set([
|
||||
'daemonize' => false,
|
||||
'dispatch_mode' => 1,
|
||||
'max_request' => 8000,
|
||||
'open_tcp_nodelay' => true,
|
||||
'reload_async' => true,
|
||||
'max_wait_time' => 60,
|
||||
'enable_reuse_port' => true,
|
||||
'enable_coroutine' => true,
|
||||
'http_compression' => false,
|
||||
'enable_static_handler' => false,
|
||||
'buffer_output_size' => 4 * 1024 * 1024,
|
||||
'worker_num' => 4, // Each worker holds a connection pool
|
||||
]);
|
||||
}
|
||||
|
||||
protected function bindHttpEvent()
|
||||
{
|
||||
$this->swoole->on('Request', function (Request $request, Response $response) {
|
||||
$pool1 = $this->getConnectionPool('mysql');
|
||||
/**@var MySQL $mysql */
|
||||
$mysql = $pool1->borrow();
|
||||
$status = $mysql->query('SHOW STATUS LIKE "Threads_connected"');
|
||||
// Return the connection to pool as soon as possible
|
||||
$pool1->return($mysql);
|
||||
|
||||
|
||||
$pool2 = $this->getConnectionPool('redis');
|
||||
/**@var \Redis $redis */
|
||||
$redis = $pool2->borrow();
|
||||
$clients = $redis->info('Clients');
|
||||
// Return the connection to pool as soon as possible
|
||||
$pool2->return($redis);
|
||||
|
||||
$json = [
|
||||
'status' => $status,
|
||||
'clients' => $clients,
|
||||
];
|
||||
// Other logic
|
||||
// ...
|
||||
$response->header('Content-Type', 'application/json');
|
||||
$response->end(json_encode($json));
|
||||
});
|
||||
}
|
||||
|
||||
protected function bindWorkerEvents()
|
||||
{
|
||||
$createPools = function () {
|
||||
// All MySQL connections: [4 workers * 2 = 8, 4 workers * 10 = 40]
|
||||
$pool1 = new ConnectionPool(
|
||||
[
|
||||
'minActive' => 2,
|
||||
'maxActive' => 10,
|
||||
],
|
||||
new CoroutineMySQLConnector,
|
||||
[
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'user' => 'root',
|
||||
'password' => 'xy123456',
|
||||
'database' => 'mysql',
|
||||
'timeout' => 10,
|
||||
'charset' => 'utf8mb4',
|
||||
'strict_type' => true,
|
||||
'fetch_mode' => true,
|
||||
]);
|
||||
$pool1->init();
|
||||
$this->addConnectionPool('mysql', $pool1);
|
||||
|
||||
// All Redis connections: [4 workers * 5 = 20, 4 workers * 20 = 80]
|
||||
$pool2 = new ConnectionPool(
|
||||
[
|
||||
'minActive' => 5,
|
||||
'maxActive' => 20,
|
||||
],
|
||||
new PhpRedisConnector,
|
||||
[
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '6379',
|
||||
'database' => 0,
|
||||
'password' => null,
|
||||
]);
|
||||
$pool2->init();
|
||||
$this->addConnectionPool('redis', $pool2);
|
||||
};
|
||||
$closePools = function () {
|
||||
$this->closeConnectionPools();
|
||||
};
|
||||
$this->swoole->on('WorkerStart', $createPools);
|
||||
$this->swoole->on('WorkerStop', $closePools);
|
||||
$this->swoole->on('WorkerError', $closePools);
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->swoole->start();
|
||||
}
|
||||
}
|
||||
|
||||
// Enable coroutine for PhpRedis
|
||||
Swoole\Runtime::enableCoroutine();
|
||||
$server = new HttpServer('0.0.0.0', 5200);
|
||||
$server->start();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
Reference in New Issue
Block a user