feat: 优化消息互动中心与首页Banner呈现,同步全量业务数据与高清图标
这个提交包含在:
@@ -222,6 +222,14 @@ class Home extends V1
|
||||
};
|
||||
$applyArea($query);
|
||||
|
||||
// 付费发帖拦截:未付清款项的帖子(微信支付待付款)严禁向外展示
|
||||
$applyPaid = function ($q) {
|
||||
$q->where(function ($w) {
|
||||
$w->where('amount', 'null')->whereOr('amount', '<=', 0)->whereOr('is_paid', 1);
|
||||
});
|
||||
};
|
||||
$applyPaid($query);
|
||||
|
||||
$counter = Db::name('fc_post')
|
||||
->where('audit_status', 1)
|
||||
->where('status', 1)
|
||||
@@ -233,6 +241,7 @@ class Home extends V1
|
||||
$counter->where('title', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
$applyArea($counter);
|
||||
$applyPaid($counter);
|
||||
$total = $counter->count();
|
||||
|
||||
// 「附近」:距离在 PHP 内用 Haversine 计算后排序(不用 SQL 距离函数,避免 MySQL 兼容问题);
|
||||
|
||||
@@ -68,11 +68,40 @@ class Member extends V1
|
||||
? array_values($cfg['benefits'])
|
||||
: $default['benefits'];
|
||||
|
||||
$freeViewQuota = isset($cfg['freeView']) ? max(0, (int)$cfg['freeView']) : $default['freeView'];
|
||||
$postDiscount = isset($cfg['postDiscount']) ? (string)$cfg['postDiscount'] : $default['postDiscount'];
|
||||
|
||||
// 真实查询当前用户的会员权益消耗与剩余额度
|
||||
$me = $this->user();
|
||||
$isMember = false;
|
||||
$freeViewUsed = 0;
|
||||
$freeViewLeft = 0;
|
||||
$postQuotaLeft = 0;
|
||||
$memberExpireAt = null;
|
||||
|
||||
if ($me) {
|
||||
$now = time();
|
||||
$ext = $this->ext($me['id']);
|
||||
$isMember = (int)$ext['is_member'] === 1
|
||||
&& (empty($ext['member_expiretime']) || (int)$ext['member_expiretime'] > $now);
|
||||
$today = date('Y-m-d');
|
||||
$freeViewUsed = ((string)$ext['free_view_date'] === $today) ? (int)$ext['free_view_used'] : 0;
|
||||
$freeViewLeft = $isMember ? max(0, $freeViewQuota - $freeViewUsed) : 0;
|
||||
$postQuotaLeft = $this->quotaLeft($ext);
|
||||
$memberExpireAt = !empty($ext['member_expiretime']) ? $this->iso($ext['member_expiretime']) : null;
|
||||
}
|
||||
|
||||
$this->ok([
|
||||
'freeView' => isset($cfg['freeView']) ? (int)$cfg['freeView'] : $default['freeView'],
|
||||
'postDiscount' => isset($cfg['postDiscount']) ? (string)$cfg['postDiscount'] : $default['postDiscount'],
|
||||
'distRate' => isset($cfg['distRate']) ? (string)$cfg['distRate'] : $default['distRate'],
|
||||
'benefits' => $benefits,
|
||||
'freeView' => $freeViewQuota,
|
||||
'postDiscount' => $postDiscount,
|
||||
'distRate' => isset($cfg['distRate']) ? (string)$cfg['distRate'] : $default['distRate'],
|
||||
'benefits' => $benefits,
|
||||
'isMember' => $isMember,
|
||||
'freeViewQuota' => $freeViewQuota,
|
||||
'freeViewUsed' => $freeViewUsed,
|
||||
'freeViewLeft' => $freeViewLeft,
|
||||
'postQuotaLeft' => $postQuotaLeft,
|
||||
'memberExpireAt' => $memberExpireAt,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,16 @@ use think\Db;
|
||||
/**
|
||||
* 用户端 · 消息中心(Module-MESSAGE)
|
||||
* 路由:
|
||||
* GET /api/v1/message/list M1 消息列表
|
||||
* POST /api/v1/message/:id/read M2 标记已读
|
||||
* GET /api/v1/message/unread-count M3 未读消息数(首页角标)
|
||||
* GET /api/v1/message/list M1 消息列表(支持个人消息与系统广播)
|
||||
* POST /api/v1/message/:id/read M2 标记单条已读
|
||||
* GET /api/v1/message/unread-count M3 未读消息数(首页角标统计)
|
||||
* POST /api/v1/message/read-all M4 一键已读(批量标记)
|
||||
* POST /api/v1/message/clear M5 一键清理(批量软删除/屏蔽)
|
||||
* POST /api/v1/message/:id/delete M6 删除单条消息(软删除/屏蔽)
|
||||
*
|
||||
* 说明:user_id=0 表示全体广播消息,用户可见。
|
||||
* 说明:
|
||||
* - user_id > 0 为用户专属通知,支持物理或软删除(deletetime)。
|
||||
* - user_id = 0 为全站系统广播,利用 read_uids 和 deleted_uids 支持多用户独立已读与独立清理,互不影响。
|
||||
*/
|
||||
class Message extends V1
|
||||
{
|
||||
@@ -19,6 +24,8 @@ class Message extends V1
|
||||
* M1 消息列表
|
||||
* GET /api/v1/message/list 入参 {type?,page,size}
|
||||
* → 分页 {list:[{id,type,title,content,read,createdAt}],page,size,total,hasMore}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
@@ -28,8 +35,17 @@ class Message extends V1
|
||||
|
||||
// 闭包重建查询:TP5.0 的 count() 会清空 Query::options,不能复用同一对象
|
||||
list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($uid, $type) {
|
||||
$q = Db::name('fc_message')->where('user_id', 'in', [$uid, 0]);
|
||||
if ($type !== '' && $type !== null) {
|
||||
$q = Db::name('fc_message')
|
||||
->whereNull('deletetime')
|
||||
->where(function ($sub) use ($uid) {
|
||||
$sub->where('user_id', $uid)
|
||||
->whereOr(function ($sub2) use ($uid) {
|
||||
$sub2->where('user_id', 0)
|
||||
->whereRaw("NOT FIND_IN_SET('{$uid}', IFNULL(deleted_uids, ''))");
|
||||
});
|
||||
});
|
||||
|
||||
if ($type !== '' && $type !== null && $type !== 'all') {
|
||||
$q->where('type', $type);
|
||||
}
|
||||
if ($forCount) {
|
||||
@@ -40,12 +56,21 @@ class Message extends V1
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
// 计算当前用户下的已读状态(广播消息匹配 read_uids 集合)
|
||||
$isRead = false;
|
||||
if ((int)$row['user_id'] === $uid) {
|
||||
$isRead = (bool)(int)$row['isread'];
|
||||
} else {
|
||||
$readUids = array_filter(explode(',', (string)$row['read_uids']));
|
||||
$isRead = (bool)(int)$row['isread'] || in_array((string)$uid, $readUids);
|
||||
}
|
||||
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'type' => (string)$row['type'],
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'read' => (bool)(int)$row['isread'],
|
||||
'read' => $isRead,
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
];
|
||||
}
|
||||
@@ -54,8 +79,10 @@ class Message extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* M2 标记已读
|
||||
* M2 标记单条已读
|
||||
* POST /api/v1/message/:id/read → {read:true}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
@@ -63,9 +90,31 @@ class Message extends V1
|
||||
$uid = (int)$user['id'];
|
||||
$id = (int)$this->request->param('id', 0);
|
||||
|
||||
Db::name('fc_message')->where('id', $id)
|
||||
->where('user_id', 'in', [$uid, 0])
|
||||
->update(['isread' => 1, 'readtime' => time()]);
|
||||
$msg = Db::name('fc_message')->where('id', $id)->whereNull('deletetime')->find();
|
||||
if (!$msg) {
|
||||
$this->fail(404, '消息不存在或已删除');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
if ((int)$msg['user_id'] === $uid) {
|
||||
Db::name('fc_message')->where('id', $id)->update([
|
||||
'isread' => 1,
|
||||
'readtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
} elseif ((int)$msg['user_id'] === 0) {
|
||||
// 系统广播:维护用户级已读集合 read_uids
|
||||
$readUids = array_filter(explode(',', (string)$msg['read_uids']));
|
||||
if (!in_array((string)$uid, $readUids)) {
|
||||
$readUids[] = (string)$uid;
|
||||
Db::name('fc_message')->where('id', $id)->update([
|
||||
'read_uids' => implode(',', array_unique($readUids)),
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$this->fail(403, '无权操作此消息');
|
||||
}
|
||||
|
||||
$this->ok(['read' => true]);
|
||||
}
|
||||
@@ -73,19 +122,184 @@ class Message extends V1
|
||||
/**
|
||||
* M3 未读消息数(首页消息角标)
|
||||
* GET /api/v1/message/unread-count → {count}
|
||||
* 规则:统计当前用户可见(user_id = 本人 或 0 广播)且 isread=0 的消息条数,
|
||||
* 替代前端原先写死的角标数字。
|
||||
* 规则:统计个人专属未读数 + 全体广播中未被当前用户读取的有效条数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unreadCount()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$uid = (int)$user['id'];
|
||||
|
||||
$count = (int)Db::name('fc_message')
|
||||
->where('user_id', 'in', [$uid, 0])
|
||||
// 1. 专属个人消息未读数
|
||||
$userCount = (int)Db::name('fc_message')
|
||||
->where('user_id', $uid)
|
||||
->where('isread', 0)
|
||||
->whereNull('deletetime')
|
||||
->count();
|
||||
|
||||
$this->ok(['count' => $count]);
|
||||
// 2. 系统广播未读数
|
||||
$broadcastMsgs = Db::name('fc_message')
|
||||
->where('user_id', 0)
|
||||
->whereNull('deletetime')
|
||||
->select();
|
||||
|
||||
$broadcastCount = 0;
|
||||
foreach ($broadcastMsgs as $b) {
|
||||
$deletedUids = array_filter(explode(',', (string)$b['deleted_uids']));
|
||||
if (in_array((string)$uid, $deletedUids)) {
|
||||
continue; // 用户已删除该广播
|
||||
}
|
||||
if ((int)$b['isread'] === 1) {
|
||||
continue; // 广播全局标记已读
|
||||
}
|
||||
$readUids = array_filter(explode(',', (string)$b['read_uids']));
|
||||
if (!in_array((string)$uid, $readUids)) {
|
||||
$broadcastCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->ok(['count' => $userCount + $broadcastCount]);
|
||||
}
|
||||
|
||||
/**
|
||||
* M4 一键已读
|
||||
* POST /api/v1/message/read-all 入参 {type?}
|
||||
* 规则:将当前分类下的专属未读消息及有效广播全部标记为已读
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function readAll()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$uid = (int)$user['id'];
|
||||
$type = $this->input('type', '');
|
||||
$now = time();
|
||||
|
||||
// 1. 批量标记专属个人消息
|
||||
$q = Db::name('fc_message')
|
||||
->where('user_id', $uid)
|
||||
->where('isread', 0)
|
||||
->whereNull('deletetime');
|
||||
|
||||
if ($type !== '' && $type !== null && $type !== 'all') {
|
||||
$q->where('type', $type);
|
||||
}
|
||||
$affected = $q->update([
|
||||
'isread' => 1,
|
||||
'readtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
// 2. 批量将有效系统广播加入当前用户已读
|
||||
$broadQ = Db::name('fc_message')->where('user_id', 0)->whereNull('deletetime');
|
||||
if ($type !== '' && $type !== null && $type !== 'all') {
|
||||
$broadQ->where('type', $type);
|
||||
}
|
||||
$broadcasts = $broadQ->select();
|
||||
foreach ($broadcasts as $b) {
|
||||
$delUids = array_filter(explode(',', (string)$b['deleted_uids']));
|
||||
if (in_array((string)$uid, $delUids)) {
|
||||
continue;
|
||||
}
|
||||
$readUids = array_filter(explode(',', (string)$b['read_uids']));
|
||||
if (!in_array((string)$uid, $readUids)) {
|
||||
$readUids[] = (string)$uid;
|
||||
Db::name('fc_message')->where('id', $b['id'])->update([
|
||||
'read_uids' => implode(',', array_unique($readUids)),
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$affected++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->ok(['success' => true, 'affected' => (int)$affected]);
|
||||
}
|
||||
|
||||
/**
|
||||
* M5 一键清理
|
||||
* POST /api/v1/message/clear 入参 {type?}
|
||||
* 规则:对专属通知执行软删除(deletetime);对广播消息记录当前用户已删除集合(deleted_uids)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$uid = (int)$user['id'];
|
||||
$type = $this->input('type', '');
|
||||
$now = time();
|
||||
|
||||
// 1. 专属消息软删除
|
||||
$q = Db::name('fc_message')->where('user_id', $uid)->whereNull('deletetime');
|
||||
if ($type !== '' && $type !== null && $type !== 'all') {
|
||||
$q->where('type', $type);
|
||||
}
|
||||
$affected = $q->update([
|
||||
'deletetime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
// 2. 广播消息:将 uid 追加到 deleted_uids
|
||||
$broadQ = Db::name('fc_message')->where('user_id', 0)->whereNull('deletetime');
|
||||
if ($type !== '' && $type !== null && $type !== 'all') {
|
||||
$broadQ->where('type', $type);
|
||||
}
|
||||
$broadcasts = $broadQ->select();
|
||||
foreach ($broadcasts as $b) {
|
||||
$delUids = array_filter(explode(',', (string)$b['deleted_uids']));
|
||||
if (!in_array((string)$uid, $delUids)) {
|
||||
$delUids[] = (string)$uid;
|
||||
Db::name('fc_message')->where('id', $b['id'])->update([
|
||||
'deleted_uids' => implode(',', array_unique($delUids)),
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$affected++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->ok(['success' => true, 'affected' => (int)$affected]);
|
||||
}
|
||||
|
||||
/**
|
||||
* M6 删除单条消息
|
||||
* POST /api/v1/message/:id/delete
|
||||
* 规则:对专属消息软删除(deletetime);对广播消息加入 deleted_uids
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$uid = (int)$user['id'];
|
||||
$id = (int)$this->request->param('id', 0);
|
||||
$now = time();
|
||||
|
||||
$msg = Db::name('fc_message')->where('id', $id)->whereNull('deletetime')->find();
|
||||
if (!$msg) {
|
||||
$this->fail(404, '消息不存在或已删除');
|
||||
}
|
||||
|
||||
if ((int)$msg['user_id'] === $uid) {
|
||||
// 专属个人消息执行软删除
|
||||
Db::name('fc_message')->where('id', $id)->update([
|
||||
'deletetime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
} elseif ((int)$msg['user_id'] === 0) {
|
||||
// 广播消息:记录已删除该消息的用户 UID
|
||||
$delUids = array_filter(explode(',', (string)$msg['deleted_uids']));
|
||||
if (!in_array((string)$uid, $delUids)) {
|
||||
$delUids[] = (string)$uid;
|
||||
Db::name('fc_message')->where('id', $id)->update([
|
||||
'deleted_uids' => implode(',', array_unique($delUids)),
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$this->fail(403, '无权操作此消息');
|
||||
}
|
||||
|
||||
$this->ok(['success' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ class Post extends V1
|
||||
// LBS 坐标(gcj02;未定位/为 0 时存 NULL,首页「附近」不参与距离排序)
|
||||
'lat' => $this->coord('lat', 90),
|
||||
'lng' => $this->coord('lng', 180),
|
||||
'is_paid' => $paid ? 1 : 0,
|
||||
'is_paid' => ($paid && $paidNow) ? 1 : 0, // 微信支付发帖未付款前为 0,防止未支付信息外泄
|
||||
'amount' => $paid ? $amount : 0,
|
||||
'pay_type' => $paid ? $payType : '',
|
||||
'audit_status' => 0,
|
||||
@@ -823,38 +823,77 @@ class Post extends V1
|
||||
* @param array $post fc_post 行
|
||||
* @return array
|
||||
*/
|
||||
/**
|
||||
* 详情页联系方式与内容访问控制(严格执行会员权益与付费拦截)
|
||||
*
|
||||
* 可见规则:
|
||||
* ① 本人发布的信息或已付费解锁记录(fc_pay_view)→ unlocked=true,返回真实联系方式明文
|
||||
* ② 会员享有每日免费查看额度,未点击解锁时不泄露真实号码,下发真实剩余额度与会员标识
|
||||
* ③ 未解锁状态下,对标题与详细正文中的手机号执行掩码遮蔽,封堵正文直接贴电话的白嫖漏洞
|
||||
*
|
||||
* @param array $data buildPost() 结果
|
||||
* @param array $post fc_post 行
|
||||
* @return array 增强后的 Post 详情结构
|
||||
*/
|
||||
protected function contactAccess($data, $post)
|
||||
{
|
||||
$data['unlocked'] = false;
|
||||
$data['wechat'] = '';
|
||||
|
||||
$me = $this->user();
|
||||
if (!$me) {
|
||||
return $data;
|
||||
$now = time();
|
||||
$isMember = false;
|
||||
$quota = $this->memberFreeViewQuota();
|
||||
$used = 0;
|
||||
$freeViewLeft = 0;
|
||||
$payViewPrice = round((float)$this->cfg('fee.payView', 2), 2);
|
||||
|
||||
$isOwner = false;
|
||||
$paid = false;
|
||||
|
||||
if ($me) {
|
||||
$ext = $this->ext($me['id']);
|
||||
$isMember = (int)$ext['is_member'] === 1
|
||||
&& (empty($ext['member_expiretime']) || (int)$ext['member_expiretime'] > $now);
|
||||
$isOwner = (int)$post['user_id'] === (int)$me['id'];
|
||||
$paid = (bool)Db::name('fc_pay_view')
|
||||
->where('user_id', $me['id'])
|
||||
->where('post_id', $post['id'])
|
||||
->find();
|
||||
|
||||
$today = date('Y-m-d');
|
||||
$used = ((string)$ext['free_view_date'] === $today) ? (int)$ext['free_view_used'] : 0;
|
||||
$freeViewLeft = $isMember ? max(0, $quota - $used) : 0;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$ext = $this->ext($me['id']);
|
||||
$isMember = (int)$ext['is_member'] === 1
|
||||
&& (empty($ext['member_expiretime']) || (int)$ext['member_expiretime'] > $now);
|
||||
$isOwner = (int)$post['user_id'] === (int)$me['id'];
|
||||
$paid = (bool)Db::name('fc_pay_view')
|
||||
->where('user_id', $me['id'])
|
||||
->where('post_id', $post['id'])
|
||||
->find();
|
||||
$data['isMember'] = $isMember;
|
||||
$data['freeViewQuota'] = $quota;
|
||||
$data['freeViewUsed'] = $used;
|
||||
$data['freeViewLeft'] = $freeViewLeft;
|
||||
$data['payViewPrice'] = $payViewPrice;
|
||||
|
||||
// 会员每日免费查看剩余次数(只做展示;解锁统一走 payView,按额度/付费计费)
|
||||
$quota = $this->memberFreeViewQuota();
|
||||
$today = date('Y-m-d');
|
||||
$used = ((string)$ext['free_view_date'] === $today) ? (int)$ext['free_view_used'] : 0;
|
||||
$data['freeViewLeft'] = $isMember ? max(0, $quota - $used) : 0;
|
||||
|
||||
if ($isOwner || $paid || $isMember) {
|
||||
$data['unlocked'] = true;
|
||||
$data['phone'] = (string)$post['phone'];
|
||||
$data['contact'] = (string)$post['phone'];
|
||||
// 真实解锁态判定:仅本人发布或已生成有效解锁记录
|
||||
if ($isOwner || $paid) {
|
||||
$data['unlocked'] = true;
|
||||
$data['phone'] = (string)$post['phone'];
|
||||
$data['contact'] = (string)$post['phone'];
|
||||
$data['contactName'] = (string)(isset($post['contact']) ? $post['contact'] : '');
|
||||
$data['wechat'] = $post['wechat'] !== '' ? (string)$post['wechat'] : ('tongcheng_' . $post['id']);
|
||||
$data['wechat'] = $post['wechat'] !== '' ? (string)$post['wechat'] : ('tongcheng_' . $post['id']);
|
||||
// 若发帖人有关联商家门店,在解锁态下一并展现真实门店电话
|
||||
if (!empty($data['merchant']) && is_array($data['merchant']) && !empty($data['merchant']['id'])) {
|
||||
$rawShopContact = Db::name('fc_merchant')->where('id', $data['merchant']['id'])->value('contact');
|
||||
if ($rawShopContact) {
|
||||
$data['merchant']['contact'] = (string)$rawShopContact;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 未解锁态:标题与详细描述中的任何手机号执行动态安全遮蔽,杜绝正文绕过
|
||||
if (!empty($data['content'])) {
|
||||
$data['content'] = $this->maskTextPhones($data['content']);
|
||||
}
|
||||
if (!empty($data['title'])) {
|
||||
$data['title'] = $this->maskTextPhones($data['title']);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -923,7 +962,10 @@ class Post extends V1
|
||||
$id = $this->routeId();
|
||||
|
||||
$payType = (string)$this->input('payType', '');
|
||||
if (!in_array($payType, ['wxpay', 'balance'], true)) {
|
||||
if ($payType === '') {
|
||||
$payType = 'free';
|
||||
}
|
||||
if (!in_array($payType, ['wxpay', 'balance', 'free'], true)) {
|
||||
$this->fail('支付方式不支持');
|
||||
}
|
||||
|
||||
@@ -965,6 +1007,9 @@ class Post extends V1
|
||||
if ($usedFree) {
|
||||
$amount = 0;
|
||||
$payType = 'free';
|
||||
} elseif ($payType === 'free') {
|
||||
// 用户希望使用会员免费特权,但额度已耗尽或非会员
|
||||
throw new \RuntimeException($isMember ? '今日会员免费查看额度已用完,请选择支付方式付费查看' : '该内容需付费查看,请选择支付方式');
|
||||
} elseif ($payType === 'balance') {
|
||||
// 条件扣款:并发下不会扣成负数
|
||||
$affected = Db::name('user')
|
||||
@@ -972,7 +1017,7 @@ class Post extends V1
|
||||
->where('money', '>=', $amount)
|
||||
->setDec('money', $amount);
|
||||
if (!$affected) {
|
||||
throw new \RuntimeException('余额不足');
|
||||
throw new \RuntimeException('余额不足,请充值或使用微信支付');
|
||||
}
|
||||
$balance = (float)Db::name('user')->where('id', (int)$user['id'])->value('money');
|
||||
$this->flow('expense', '付费查看', $amount, $balance, $id);
|
||||
@@ -1019,7 +1064,16 @@ class Post extends V1
|
||||
$this->ok(['order' => $pending]);
|
||||
}
|
||||
|
||||
$this->ok(['unlocked' => true, 'contact' => $contact]);
|
||||
$today = date('Y-m-d');
|
||||
$extNow = $this->ext($user['id']);
|
||||
$usedNow = ((string)$extNow['free_view_date'] === $today) ? (int)$extNow['free_view_used'] : 0;
|
||||
|
||||
$this->ok([
|
||||
'unlocked' => true,
|
||||
'contact' => $contact,
|
||||
'freeViewLeft' => $isMember ? max(0, $quota - $usedNow) : 0,
|
||||
'usedFree' => isset($usedFree) ? $usedFree : false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1442,7 +1496,7 @@ class Post extends V1
|
||||
'address' => (string)(isset($m['address']) ? $m['address'] : ''),
|
||||
'lat' => (isset($m['lat']) && $m['lat'] !== null && $m['lat'] !== '') ? (float)$m['lat'] : null,
|
||||
'lng' => (isset($m['lng']) && $m['lng'] !== null && $m['lng'] !== '') ? (float)$m['lng'] : null,
|
||||
'contact' => (string)(isset($m['contact']) ? $m['contact'] : ''),
|
||||
'contact' => $this->maskPhone(isset($m['contact']) ? $m['contact'] : ''), // 默认脱敏,未解锁绝不泄露
|
||||
'category' => (string)(isset($m['category']) ? $m['category'] : ''),
|
||||
'notice' => (string)(isset($m['notice']) ? $m['notice'] : ''),
|
||||
'auditStatus' => (int)$m['audit_status'],
|
||||
|
||||
@@ -457,11 +457,68 @@ class V1 extends Api
|
||||
return date('c', (int)$timestamp);
|
||||
}
|
||||
|
||||
/** 手机号脱敏 */
|
||||
/**
|
||||
* 手机号与电话号码多格式安全脱敏
|
||||
* 兼容标准11位手机号、带+86/0086国际前缀、带空格/中划线及带区号固定电话,防止未付费信息绕过泄露
|
||||
*
|
||||
* @param string $phone 原始号码
|
||||
* @return string 脱敏后的号码字符串
|
||||
*/
|
||||
protected function maskPhone($phone)
|
||||
{
|
||||
$phone = (string)$phone;
|
||||
return strlen($phone) === 11 ? substr($phone, 0, 3) . '****' . substr($phone, 7) : $phone;
|
||||
$raw = trim((string)$phone);
|
||||
if ($raw === "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 统一提取数字部分进行标准化识别
|
||||
$clean = preg_replace("/[^\d]/", "", $raw);
|
||||
|
||||
// 去除大陆前缀 86 或 0086
|
||||
if (strpos($clean, "86") === 0 && strlen($clean) === 13) {
|
||||
$clean = substr($clean, 2);
|
||||
}
|
||||
|
||||
// 11位大陆标准手机号
|
||||
if (preg_match("/^1[3-9]\d{9}$/", $clean)) {
|
||||
return substr($clean, 0, 3) . "****" . substr($clean, 7);
|
||||
}
|
||||
|
||||
// 10~12位座机固话(如 085188888888、01088888888)
|
||||
if (preg_match("/^0\d{9,11}$/", $clean)) {
|
||||
$prefixLen = (strpos($clean, "01") === 0 || strpos($clean, "02") === 0) ? 3 : 4;
|
||||
return substr($clean, 0, $prefixLen) . "****" . substr($clean, -3);
|
||||
}
|
||||
|
||||
// 其它>=7位的任意连续数字号码,统一对中段进行掩码
|
||||
$len = strlen($clean);
|
||||
if ($len >= 7) {
|
||||
$start = max(1, (int)floor(($len - 4) / 2));
|
||||
return substr($clean, 0, $start) . "****" . substr($clean, $start + 4);
|
||||
}
|
||||
|
||||
return $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本内容中的手机号与电话动态遮蔽
|
||||
* 用于未付费解锁状态下对标题、详细描述中的手机号执行掩码保护,杜绝发帖人在正文直接贴电话白嫖
|
||||
*
|
||||
* @param string $content 原始富文本或正文内容
|
||||
* @return string 动态掩码后的文本
|
||||
*/
|
||||
protected function maskTextPhones($content)
|
||||
{
|
||||
$text = (string)$content;
|
||||
if ($text === "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 匹配各类11位大陆手机号码,含可能夹带的空格或横杠(如 138 0000 0000 或 138-0000-0000)
|
||||
$pattern = '/(?:(?:\+|00)86[\s-]?)?(1[3-9]\d)[\s-]?(\d{4})[\s-]?(\d{4})/u';
|
||||
return preg_replace_callback($pattern, function ($matches) {
|
||||
return $matches[1] . '****' . $matches[3];
|
||||
}, $text);
|
||||
}
|
||||
|
||||
/** 生成业务单号(前缀 + 时间 + 8 位随机十六进制,避免同秒并发碰撞) */
|
||||
|
||||
在新工单中引用
屏蔽一个用户