feat: 新增地址选择插件及订阅消息等多项功能优化
- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
这个提交包含在:
@@ -87,7 +87,12 @@ class V1 extends Api
|
||||
$this->resolved = true;
|
||||
|
||||
$token = $this->bearerToken();
|
||||
if (!$token && !($token = $this->request->request('token'))) {
|
||||
// 不再接受 ?token= 传参(避免令牌进入访问日志/Referer),仅认 Authorization: Bearer
|
||||
if (!$token) {
|
||||
return $this->user = null;
|
||||
}
|
||||
// 刷新令牌(rf_ 前缀)不能作为访问令牌使用
|
||||
if (strpos($token, 'rf_') === 0) {
|
||||
return $this->user = null;
|
||||
}
|
||||
|
||||
@@ -115,6 +120,35 @@ class V1 extends Api
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台管理接口鉴权(/api/v1/admin/** 专用)
|
||||
*
|
||||
* 背景:V1 基类对所有动作关闭了 FastAdmin 的 URI 权限校验($noNeedLogin = ['*']),
|
||||
* 因此管理端接口必须显式校验调用者身份,否则任何人可读写后台数据。
|
||||
*
|
||||
* 放行规则(满足其一即可):
|
||||
* 1. 用户 ID 在 fc_config 的 admin.userIds 白名单内(逗号分隔);
|
||||
* 2. 用户手机号在 fc_config 的 admin.mobiles 白名单内(逗号分隔)。
|
||||
*
|
||||
* @return \app\common\model\User
|
||||
*/
|
||||
protected function adminOnly()
|
||||
{
|
||||
$user = $this->auth();
|
||||
|
||||
$ids = array_filter(array_map('intval', preg_split('/[,,\s]+/', (string)$this->cfg('admin.userIds', ''))));
|
||||
if ($ids && in_array((int)$user['id'], $ids, true)) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
$mobiles = array_filter(array_map('trim', preg_split('/[,,\s]+/', (string)$this->cfg('admin.mobiles', ''))));
|
||||
if ($mobiles && in_array((string)$user['mobile'], $mobiles, true)) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
$this->fail('无权访问管理接口', 403, 403);
|
||||
}
|
||||
|
||||
/** 当前用户 ID */
|
||||
protected function userId()
|
||||
{
|
||||
@@ -124,7 +158,7 @@ class V1 extends Api
|
||||
/** 签发 token 并写入 fa_user_token */
|
||||
protected function issueToken($userId, $days = 30)
|
||||
{
|
||||
$token = md5(mt_rand() . $userId . microtime(true) . uniqid('', true));
|
||||
$token = bin2hex(random_bytes(20));
|
||||
Db::name('user_token')->insert([
|
||||
'token' => $token,
|
||||
'user_id' => $userId,
|
||||
@@ -134,6 +168,48 @@ class V1 extends Api
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 签发刷新令牌(rf_ 前缀,40 天)
|
||||
* 与访问令牌同表存储,但鉴权时会被拒绝(见 user()),只能用于 /auth/refresh 换新令牌
|
||||
*
|
||||
* 长度约束:fa_user_token.token 为 varchar(50),故取 20 字节随机(40 hex)+ 3 位前缀 = 43
|
||||
*/
|
||||
protected function issueRefreshToken($userId, $days = 40)
|
||||
{
|
||||
$refresh = 'rf_' . bin2hex(random_bytes(20));
|
||||
Db::name('user_token')->insert([
|
||||
'token' => $refresh,
|
||||
'user_id' => $userId,
|
||||
'createtime' => time(),
|
||||
'expiretime' => time() + $days * 86400,
|
||||
]);
|
||||
return $refresh;
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单频率限制(文件缓存计数)
|
||||
*
|
||||
* @param string $key 维度键(如 login:手机号、withdraw:用户ID)
|
||||
* @param int $max 窗口内最大次数
|
||||
* @param int $window 窗口秒数
|
||||
* @return void
|
||||
*/
|
||||
protected function rateLimit($key, $max, $window)
|
||||
{
|
||||
$cacheKey = 'rl:' . md5($key);
|
||||
$now = time();
|
||||
$data = cache($cacheKey);
|
||||
if (!is_array($data) || empty($data['reset']) || $data['reset'] <= $now) {
|
||||
$data = ['count' => 0, 'reset' => $now + $window];
|
||||
}
|
||||
$data['count']++;
|
||||
cache($cacheKey, $data, $window);
|
||||
|
||||
if ($data['count'] > $max) {
|
||||
$this->fail('操作过于频繁,请稍后再试', 429, 429);
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================== 入参 ==================== */
|
||||
|
||||
/**
|
||||
@@ -283,7 +359,11 @@ class V1 extends Api
|
||||
]);
|
||||
}
|
||||
if (self::$cfgCache === null) {
|
||||
// 首次写入时先载入全量配置,避免后续读取其他 key 时命中空缓存而返回默认值
|
||||
self::$cfgCache = [];
|
||||
foreach (Db::name('fc_config')->select() as $row) {
|
||||
self::$cfgCache[$row['key']] = $row['value'];
|
||||
}
|
||||
}
|
||||
self::$cfgCache[$key] = $val;
|
||||
return true;
|
||||
@@ -310,10 +390,10 @@ class V1 extends Api
|
||||
return strlen($phone) === 11 ? substr($phone, 0, 3) . '****' . substr($phone, 7) : $phone;
|
||||
}
|
||||
|
||||
/** 生成业务单号 */
|
||||
/** 生成业务单号(前缀 + 时间 + 8 位随机十六进制,避免同秒并发碰撞) */
|
||||
protected function orderNo($prefix)
|
||||
{
|
||||
return $prefix . date('YmdHis') . mt_rand(1000, 9999);
|
||||
return $prefix . date('YmdHis') . bin2hex(random_bytes(4));
|
||||
}
|
||||
|
||||
/* ==================== 业务公共 ==================== */
|
||||
@@ -364,6 +444,7 @@ class V1 extends Api
|
||||
'memberExpireAt' => $ext['member_expiretime'] ? $this->iso($ext['member_expiretime']) : null,
|
||||
'balance' => (float)$user['money'],
|
||||
'realnameStatus' => (int)$ext['realname_status'],
|
||||
'realname' => isset($ext['realname']) ? (string)$ext['realname'] : '',
|
||||
'isMerchant' => (bool)$isMerchant,
|
||||
'merchantStatus' => $merchantStatus,
|
||||
'merchant' => $merchant ? [
|
||||
@@ -400,7 +481,7 @@ class V1 extends Api
|
||||
static $seq = 0;
|
||||
$seq++;
|
||||
Db::name('fc_finance_flow')->insert([
|
||||
'flow_no' => 'F' . date('YmdHis') . mt_rand(100, 999) . $seq,
|
||||
'flow_no' => 'F' . date('YmdHis') . bin2hex(random_bytes(4)) . $seq,
|
||||
'type' => $type,
|
||||
'scene' => $scene,
|
||||
'amount' => $amount,
|
||||
|
||||
在新工单中引用
屏蔽一个用户