feat: 优化消息互动中心与首页Banner呈现,同步全量业务数据与高清图标

这个提交包含在:
2026-10-24 11:39:44 +08:00
父节点 0f84426c33
当前提交 d18b597010
共有 109 个文件被更改,包括 3385 次插入 和 526 次删除

查看文件

@@ -27,9 +27,9 @@ class FcInstall extends Command
* image 留空时小程序用「亮绿底 + 墨绿字 + 白色插画」内置配图渲染。
*/
const BANNERS = [
['同城好物节 · 二手直降', '/pages/post/list?categoryId=3', 'linear-gradient(105deg, #00e070 0%, #00c860 42%, #046b3b 100%)'],
['招聘旺季 · 免费发布', '/pages/post/create', 'linear-gradient(105deg, #00d96c 0%, #00b85c 40%, #023a21 100%)'],
['本地服务 · 上门更省心', '/pages/post/list?categoryId=5', 'linear-gradient(105deg, #00e878 0%, #049e52 45%, #045c34 100%)'],
['同城好物节 · 二手直降', '/pages/post/list?categoryId=3', 'linear-gradient(120deg, #10b981 0%, #34d399 50%, #a7f3d0 100%)'],
['招聘旺季 · 免费发布', '/pages/post/create', 'linear-gradient(120deg, #059669 0%, #10b981 50%, #6ee7b7 100%)'],
['本地服务 · 上门更省心', '/pages/post/list?categoryId=5', 'linear-gradient(120deg, #00d26a 0%, #34d399 50%, #bbf7d0 100%)'],
];
/**

查看文件

@@ -24,14 +24,14 @@ class FcSeedPosts extends Command
const USERS = [
1001 => ['同城小助手', '13800001111'],
1002 => ['小王同学', '15033443344'],
1003 => ['洁净到家', '13156785678'],
2001 => ['顺捷物流', '13988888888'],
2002 => ['安家房产', '13566666666'],
2003 => ['骑行爱好者', '13712341234'],
2004 => ['车行天下', '13800000000'],
2005 => ['洁净到家', '13156785678'],
2006 => ['小王同学', '15033443344'],
2007 => ['优选二手车', '13700000000'],
1003 => ['洁净到家·陈姐', '13156785678'],
2001 => ['顺捷物流·杨经理', '13988888888'],
2002 => ['安家房产·周主管', '13566666666'],
2003 => ['骑行爱好者·小周', '13712341234'],
2004 => ['车行天下·张总', '13800000000'],
2005 => ['洁净到家·王师傅', '13156785678'],
2006 => ['数码达人·阿豪', '15033443344'],
2007 => ['优选二手车·赵经理', '13700000000'],
];
/** 区域中心坐标(gcj02 近似值,用于首页「附近」排序演示) */
@@ -82,6 +82,7 @@ class FcSeedPosts extends Command
'id' => $id,
'user_id' => $uid,
'category_id' => $categoryId,
'identity_type' => in_array($uid, [1003, 2001, 2002, 2004, 2005, 2007, 2011], true) ? 2 : 1,
'title' => $row[1],
'content' => $row[2],
'cover' => $media[0],
@@ -460,5 +461,17 @@ class FcSeedPosts extends Command
->count();
Db::name('fc_category')->where('id', $categoryId)->update(['post_count' => $count]);
}
// 同步商家有效发帖数
$merchants = Db::name('fc_merchant')->field('id,user_id')->select();
foreach ($merchants as $m) {
$mCount = Db::name('fc_post')
->where('user_id', $m['user_id'])
->where('audit_status', 1)
->where('status', 1)
->whereNull('deletetime')
->count();
Db::name('fc_merchant')->where('id', $m['id'])->update(['post_count' => $mCount]);
}
}
}

查看文件

@@ -3,44 +3,45 @@
namespace app\admin\model;
use think\Model;
use traits\model\SoftDelete;
use app\common\library\FcRelation;
/**
* 消息模型 · 同城分类信息
*/
class FcMessage extends Model
{
use SoftDelete;
// 表名
protected $name = 'fc_message';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'user_name',
];
/**
* 获取接收用户名属性
*
* @param mixed $value 原值
* @param array $data 当前行数据
* @return string 用户昵称或标识
*/
public function getUserNameAttr($value, $data)
{
return FcRelation::userName(isset($data['user_id']) ? $data['user_id'] : 0);
$uid = isset($data['user_id']) ? (int)$data['user_id'] : 0;
if ($uid === 0) {
return '全体用户(广播)';
}
return FcRelation::userName($uid);
}
}

查看文件

@@ -6,15 +6,11 @@
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" >刷新</a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('fc/message/add')?'':'hide'}" title="{:__('Add')}" >添加</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('fc/message/edit')?'':'hide'}" title="{:__('Edit')}" >{:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('fc/message/del')?'':'hide'}" title="{:__('Delete')}" >{:__('Delete')}</a>
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> 刷新</a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('fc/message/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> 添加</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('fc/message/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('fc/message/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a class="btn btn-info btn-recyclebin btn-dialog {:$auth->check('fc/message/recyclebin')?'':'hide'}" href="fc/message/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> 回收站</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('fc/message/edit')}"

查看文件

@@ -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 位随机十六进制,避免同秒并发碰撞) */

查看文件

@@ -45,10 +45,34 @@ class OrderFulfill
self::unlockPayView($order);
}
// post 及其它类型:信息已落库,仅需结算分销
if ($type === 'post') {
self::fulfillPost($order);
}
// 其它消费类型统一结算分销
DistributionService::settleOrder($order);
}
/**
* 付费发帖支付成功后激活支付状态
* 将 fc_post 的 is_paid 置为 1,确保未付款信息不会流出展示
*
* @param array $order
* @return void
*/
protected static function fulfillPost(array $order)
{
$postId = (int)(isset($order['related_id']) ? $order['related_id'] : 0);
if ($postId <= 0) {
return;
}
Db::name('fc_post')->where('id', $postId)->update([
'is_paid' => 1,
'updatetime' => time(),
]);
}
/**
* 付费查看解锁(user_id + post_id 唯一索引保证幂等)
*

查看文件

@@ -101,7 +101,10 @@ return [
/* =============== 六、用户端 · 消息中心(Module-MESSAGE) =============== */
'api/v1/message/list' => 'api/Message/list',
'api/v1/message/unread-count' => 'api/Message/unreadCount',
'api/v1/message/:id/read' => 'api/Message/read',
'api/v1/message/read-all' => 'api/Message/readAll',
'api/v1/message/clear' => 'api/Message/clear',
'api/v1/message/:id/read' => 'api/Message/read',
'api/v1/message/:id/delete' => 'api/Message/delete',
/* =============== 六·B、用户端 · 交易与支付(充值 / 微信支付 / 优惠券) ===============
* · pay/notify 为微信支付异步通知:**公开路由,无需登录**,验签与订单置为 paid 由