feat: 完善分销中心与团队明细接口,增强商户与帖子交互细节

这个提交包含在:
2026-10-24 15:43:24 +08:00
父节点 f179b90fb4
当前提交 6b86177b5f
共有 20 个文件被更改,包括 2205 次插入 和 757 次删除

查看文件

@@ -41,7 +41,7 @@ class AdminMember extends V1
$list = [];
foreach ($rows as $row) {
$isMember = (int)$row['is_member'] === 1
&& (!$row['member_expiretime'] || (int)$row['member_expiretime'] > $now);
&& !empty($row['member_expiretime']) && (int)$row['member_expiretime'] > $now;
$list[] = [
'id' => (int)$row['id'],
'nickname' => (string)$row['nickname'],

查看文件

@@ -9,14 +9,19 @@ use think\Db;
* 路由:
* GET /api/v1/distribution/overview D1 分销概览
* GET /api/v1/distribution/team D2 我的团队
* POST /api/v1/distribution/withdraw D3 申请提现
* GET /api/v1/distribution/withdraw-records D4 提现记录
* GET /api/v1/distribution/commissions D3 分销收益明细
* GET /api/v1/distribution/poster D4 推广海报要素
* POST /api/v1/distribution/withdraw D5 申请提现
* GET /api/v1/distribution/withdraw-records D6 提现记录
*/
class Distribution extends V1
{
/**
* D1 分销概览
* GET /api/v1/distribution/overview → {totalCommission,settled,withdrawable,todayCommission,teamCount,l1Count,l2Count,inviteCode,posterUrl,minWithdraw}
* GET /api/v1/distribution/overview
* 获取用户分销核心资产数据、团队人数与分销基础配置
*
* @return void 输出包含累计佣金、已结算、待结算、可提现、今日收益、邀请码及分销规则配置的JSON响应
*/
public function overview()
{
@@ -38,35 +43,45 @@ class Distribution extends V1
$l2 = (int)Db::name('fc_dist_relation')->where('parent_id', $uid)->where('level', 2)->count();
$ext = $this->ext($uid);
$code = (string)$ext['invite_code'];
$shareUrl = 'https://fenleixinxi.gzyakj.com.cn/#/pages/index/index?ic=' . urlencode($code);
// 商家转账确认收款页需要的商户号与小程序 AppID(非敏感,可下发)
$epay = (array)get_addon_config('epay');
$wx = isset($epay['wechat']) && is_array($epay['wechat']) ? $epay['wechat'] : [];
$this->ok([
'totalCommission' => round($total, 2),
'settled' => round($settled, 2),
'totalCommission' => round($total, 2),
'settled' => round($settled, 2),
'pendingCommission' => round($pending, 2),
'withdrawable' => round(max(0, $withdrawable), 2),
'todayCommission' => round($todayCommission, 2),
'teamCount' => $l1 + $l2,
'l1Count' => $l1,
'l2Count' => $l2,
'inviteCode' => (string)$ext['invite_code'],
'posterUrl' => '',
// 最低提现金额(后台「分销设置」下发,替代前端写死的 50)
'minWithdraw' => (float)$this->cfg('dist.minWithdraw', 50),
'withdrawable' => round(max(0, $withdrawable), 2),
'todayCommission' => round($todayCommission, 2),
'teamCount' => $l1 + $l2,
'l1Count' => $l1,
'l2Count' => $l2,
'inviteCode' => $code,
'shareUrl' => $shareUrl,
'posterUrl' => '',
// 最低提现金额(后台「分销设置」下发,默认 50)
'minWithdraw' => (float)$this->cfg('dist.minWithdraw', 50),
// 分销比例与配置规则
'level1Rate' => (float)$this->cfg('dist.level1Rate', 20),
'level2Rate' => (float)$this->cfg('dist.level2Rate', 10),
'settleCycle' => (string)$this->cfg('dist.settleCycle', 'T+7'),
'enabled' => (int)$this->cfg('dist.enabled', 1),
// 提现收款人实名(未填写时前端需先采集)
'realname' => isset($ext['realname']) ? (string)$ext['realname'] : '',
'transferMchId' => isset($wx['mch_id']) ? (string)$wx['mch_id'] : '',
'transferAppId' => isset($wx['miniapp_id']) ? (string)$wx['miniapp_id'] : '',
'realname' => isset($ext['realname']) ? (string)$ext['realname'] : '',
'transferMchId' => isset($wx['mch_id']) ? (string)$wx['mch_id'] : '',
'transferAppId' => isset($wx['miniapp_id']) ? (string)$wx['miniapp_id'] : '',
]);
}
/**
* D2 我的团队
* GET /api/v1/distribution/team 入参 {level?,page,size}
* → 分页 {list:[{id,nickname,level,joinedAt,performance,commission}],page,size,total,hasMore}
* 分页查询直推(1级)和间推(2级)下线团队成员
*
* @return void 输出团队成员分页列表JSON
*/
public function team()
{
@@ -85,19 +100,31 @@ class Distribution extends V1
if ($forCount) {
return $q;
}
return $q->field('r.id,r.user_id,r.level,r.createtime,u.nickname')
return $q->field('r.id,r.user_id,r.level,r.createtime,u.nickname,u.avatar,u.mobile')
->order('r.createtime desc');
});
$list = [];
foreach ($rows as $row) {
$childId = (int)$row['user_id'];
$commission = (float)Db::name('fc_commission')->where('from_user_id', $childId)->sum('amount');
$orderAmount = (float)Db::name('fc_order')->where('user_id', $childId)->where('status', 'paid')->sum('amount');
$commission = (float)Db::name('fc_commission')
->where('user_id', $uid)
->where('from_user_id', $childId)
->sum('amount');
$orderAmount = (float)Db::name('fc_order')
->where('user_id', $childId)
->where('status', 'paid')
->sum('amount');
$performance = $orderAmount > 0 ? $orderAmount : $commission * 5;
$mobile = (string)(isset($row['mobile']) ? $row['mobile'] : '');
$maskedMobile = (strlen($mobile) === 11) ? substr($mobile, 0, 3) . '****' . substr($mobile, -4) : '';
$list[] = [
'id' => $childId,
'nickname' => (string)$row['nickname'],
'avatar' => (string)(isset($row['avatar']) ? $row['avatar'] : ''),
'mobile' => $maskedMobile,
'level' => (int)$row['level'],
'joinedAt' => $this->iso($row['createtime']),
'performance' => round($performance, 2),
@@ -109,9 +136,121 @@ class Distribution extends V1
}
/**
* D3 申请提现
* D3 分销收益明细(佣金流水账单)
* GET /api/v1/distribution/commissions 入参 {status?,level?,page,size}
* 分页查询下线消费产生的佣金记录明细及结算状态
*
* @return void 输出佣金明细列表与汇总统计JSON
*/
public function commissions()
{
$user = $this->auth();
$uid = (int)$user['id'];
$status = $this->input('status', '');
$level = $this->input('level', '');
list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($uid, $status, $level) {
$q = Db::name('fc_commission')->alias('c')
->join('user u', 'u.id = c.from_user_id', 'LEFT')
->join('fc_order o', 'o.order_no = c.order_no', 'LEFT')
->where('c.user_id', $uid);
if ($status !== '' && $status !== null) {
$q->where('c.status', (int)$status);
}
if ($level !== '' && $level !== null) {
$q->where('c.level', (int)$level);
}
if ($forCount) {
return $q;
}
return $q->field('c.*,u.nickname as from_nickname,u.avatar as from_avatar,o.title as order_title,o.amount as order_amount')
->order('c.createtime desc');
});
$typeMap = [
'post' => '信息发布/置顶',
'member' => 'VIP会员购买',
'payview' => '付费查看信息',
'refresh' => '信息一键刷新',
'merchant' => '商家认证入驻',
];
$statusMap = [
0 => '待结算',
1 => '已结算',
2 => '已失效',
];
$list = [];
foreach ($rows as $row) {
$orderType = (string)(isset($row['order_type']) ? $row['order_type'] : 'post');
$st = (int)$row['status'];
$list[] = [
'id' => (int)$row['id'],
'orderNo' => (string)$row['order_no'],
'orderType' => $orderType,
'orderTypeName' => isset($typeMap[$orderType]) ? $typeMap[$orderType] : (isset($row['order_title']) && $row['order_title'] ? $row['order_title'] : '同城消费'),
'orderAmount' => round((float)(isset($row['order_amount']) ? $row['order_amount'] : 0), 2),
'amount' => round((float)$row['amount'], 2),
'rate' => (float)$row['rate'],
'level' => (int)$row['level'],
'status' => $st,
'statusText' => isset($statusMap[$st]) ? $statusMap[$st] : '处理中',
'settleDue' => !empty($row['settle_due']) ? $this->iso($row['settle_due']) : '',
'settletime' => !empty($row['settletime']) ? $this->iso($row['settletime']) : '',
'createdAt' => $this->iso($row['createtime']),
'fromUser' => [
'id' => (int)$row['from_user_id'],
'nickname' => (string)(isset($row['from_nickname']) && $row['from_nickname'] !== '' ? $row['from_nickname'] : '同城好友'),
'avatar' => (string)(isset($row['from_avatar']) ? $row['from_avatar'] : ''),
],
];
}
$res = $this->paginate($list, $total, $page, $size);
$res['summary'] = [
'totalCommission' => round((float)Db::name('fc_commission')->where('user_id', $uid)->where('status', '<>', 2)->sum('amount'), 2),
'settledCommission' => round((float)Db::name('fc_commission')->where('user_id', $uid)->where('status', 1)->sum('amount'), 2),
'pendingCommission' => round((float)Db::name('fc_commission')->where('user_id', $uid)->where('status', 0)->sum('amount'), 2),
];
$this->ok($res);
}
/**
* D4 分销海报生成要素
* GET /api/v1/distribution/poster
* 获取用于前端合成或分享专属推广海报的元数据
*
* @return void 输出海报配置与素材信息的JSON
*/
public function poster()
{
$user = $this->auth();
$uid = (int)$user['id'];
$ext = $this->ext($uid);
$siteName = (string)$this->cfg('app.name', '同城分类信息');
$slogan = (string)$this->cfg('dist.slogan', '同城便民生活 · 随时随地发布与求助');
$code = (string)$ext['invite_code'];
$this->ok([
'inviteCode' => $code,
'siteName' => $siteName,
'slogan' => $slogan,
'nickname' => (string)(isset($user['nickname']) && $user['nickname'] !== '' ? $user['nickname'] : '同城合伙人'),
'avatar' => (string)(isset($user['avatar']) ? $user['avatar'] : ''),
'path' => 'pages/index/index?ic=' . $code,
]);
}
/**
* D5 申请提现
* POST /api/v1/distribution/withdraw 入参 {amount,channel?} → {withdrawNo,status:'auditing'}
* 规则 BR-09:金额必填且 >0、且不超过可提现余额
*
* @return void 输出提现单号与状态JSON
*/
public function withdraw()
{
@@ -172,8 +311,11 @@ class Distribution extends V1
}
/**
* D4 提现记录
* D6 提现记录
* GET /api/v1/distribution/withdraw-records → [{id,withdrawNo,amount,status,createdAt}]
* 获取当前用户的历史提现记录与商家转账确认参数
*
* @return void 输出提现历史记录列表JSON
*/
public function withdrawRecords()
{
@@ -199,7 +341,11 @@ class Distribution extends V1
}
/**
* 计算当前用户可提现余额
* 可提现余额 = Σ已结算佣金(status=1) - Σ(申请中/已打款)提现
*
* @param int $uid 用户ID
* @return float 可提现余额数值
*/
protected function withdrawable($uid)
{
@@ -208,4 +354,4 @@ class Distribution extends V1
->where('status', 'in', ['auditing', 'paying', 'paid'])->sum('amount');
return $settled - $applied;
}
}
}

查看文件

@@ -83,7 +83,7 @@ class Member extends V1
$now = time();
$ext = $this->ext($me['id']);
$isMember = (int)$ext['is_member'] === 1
&& (empty($ext['member_expiretime']) || (int)$ext['member_expiretime'] > $now);
&& !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;
@@ -123,7 +123,10 @@ class Member extends V1
$this->fail('请选择会员套餐');
}
$payType = (string)$this->input('payType', '');
$payType = (string)$this->input('payType', 'wxpay');
if ($payType === '') {
$payType = 'wxpay';
}
if (!in_array($payType, ['wxpay', 'balance'], true)) {
$this->fail('支付方式不支持');
}

查看文件

@@ -62,6 +62,35 @@ class Merchant extends V1
// 首屏拉取前 6 条该商家的有效发帖
$posts = $this->fetchMerchantPosts($m['user_id'], 1, 6);
// 严格保护商家联系电话:未付费解锁或非会员状态下脱敏,杜绝从信息详情页跳转商家主页白嫖绕过
$rawContact = (string)(isset($m['contact']) ? $m['contact'] : '');
$unlocked = false;
$me = $this->user();
if ($me) {
$now = time();
$ext = $this->ext($me['id']);
$isMember = (int)$ext['is_member'] === 1
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
$isOwner = (int)$m['user_id'] === (int)$me['id'];
if ($isOwner || $isMember) {
$unlocked = true;
} else {
// 检查是否从已解锁的关联信息跳转而来
$postId = (int)$this->input('postId', 0);
if ($postId > 0) {
$paidView = Db::name('fc_pay_view')
->where('user_id', $me['id'])
->where('post_id', $postId)
->find();
if ($paidView) {
$unlocked = true;
}
}
}
}
$displayContact = $unlocked ? $rawContact : $this->maskPhone($rawContact);
$data = [
'id' => (int)$m['id'],
'userId' => (int)$m['user_id'],
@@ -71,7 +100,8 @@ class Merchant 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' => $displayContact,
'unlocked' => $unlocked,
'category' => (string)(isset($m['category']) ? $m['category'] : ''),
'notice' => (string)(isset($m['notice']) ? $m['notice'] : ''),
'auditStatus' => (int)$m['audit_status'],

查看文件

@@ -186,7 +186,10 @@ class Post extends V1
if ($plan === 'single') {
// 单条付费 = 付费发布标准(免费发布条数用完后即按此计费);会员按折扣率计价
$amount = $unitPrice;
$payType = trim((string)$this->input('payType', ''));
$payType = trim((string)$this->input('payType', 'wxpay'));
if ($payType === '') {
$payType = 'wxpay';
}
if ($amount > 0 && !in_array($payType, ['wxpay', 'balance'], true)) {
$this->fail('支付方式不支持');
}
@@ -505,7 +508,7 @@ class Post extends V1
'freeQuotaLeft' => $free['unlimited'] ? -1 : $free['left'],
'freeUnlimited' => $free['unlimited'],
'quotaExpireAt' => $quotaExpire > 0 ? $this->iso($quotaExpire) : '',
'isMember' => (int)$ext['is_member'] === 1 && ($memberExpire === 0 || $memberExpire > $now),
'isMember' => (int)$ext['is_member'] === 1 && !empty($memberExpire) && $memberExpire > $now,
'memberExpireAt' => $memberExpire > 0 ? $this->iso($memberExpire) : '',
]);
}
@@ -854,7 +857,7 @@ class Post extends V1
if ($me) {
$ext = $this->ext($me['id']);
$isMember = (int)$ext['is_member'] === 1
&& (empty($ext['member_expiretime']) || (int)$ext['member_expiretime'] > $now);
&& !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'])
@@ -974,18 +977,33 @@ class Post extends V1
$this->fail('信息不存在', 404);
}
$phone = (string)$post['phone'];
$wechat = $post['wechat'] !== '' ? (string)$post['wechat'] : ('tongcheng_' . $id);
$contactName = (string)(isset($post['contact']) ? $post['contact'] : '');
$contact = [
'phone' => (string)$post['phone'],
'wechat' => $post['wechat'] !== '' ? (string)$post['wechat'] : ('tongcheng_' . $id),
'name' => $contactName,
'phone' => $phone,
'wechat' => $wechat,
];
// 已解锁直接返回
// 已解锁直接返回(严格返回纯净扁平字段,杜绝 JSON 嵌套导致前端格式错乱)
$exist = Db::name('fc_pay_view')
->where('user_id', $user['id'])
->where('post_id', $id)
->find();
if ($exist) {
$this->ok(['unlocked' => true, 'contact' => $contact]);
$today = date('Y-m-d');
$usedToday = ((string)$ext['free_view_date'] === $today) ? (int)$ext['free_view_used'] : 0;
$this->ok([
'unlocked' => true,
'phone' => $phone,
'contact' => $phone,
'contactName' => $contactName,
'wechat' => $wechat,
'contactInfo' => $contact,
'freeViewLeft' => $isMember ? max(0, $quota - $usedToday) : 0,
]);
}
$amount = round((float)$this->cfg('fee.payView', 2), 2);
@@ -993,7 +1011,7 @@ class Post extends V1
$ext = $this->ext($user['id']);
$isMember = (int)$ext['is_member'] === 1
&& (!$ext['member_expiretime'] || $ext['member_expiretime'] > $now);
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
$quota = $this->memberFreeViewQuota();
$orderId = 0;
@@ -1070,7 +1088,11 @@ class Post extends V1
$this->ok([
'unlocked' => true,
'contact' => $contact,
'phone' => $phone,
'contact' => $phone,
'contactName' => $contactName,
'wechat' => $wechat,
'contactInfo' => $contact,
'freeViewLeft' => $isMember ? max(0, $quota - $usedNow) : 0,
'usedFree' => isset($usedFree) ? $usedFree : false,
]);
@@ -1362,7 +1384,7 @@ class Post extends V1
{
$now = time();
$isMember = (int)$ext['is_member'] === 1
&& (empty($ext['member_expiretime']) || (int)$ext['member_expiretime'] > $now);
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
if (!$isMember) {
return 1.0;
}

查看文件

@@ -558,7 +558,7 @@ class V1 extends Api
$user = $user ?: $this->auth();
$ext = $this->ext($user['id']);
$isMember = (int)$ext['is_member'] === 1
&& (!$ext['member_expiretime'] || $ext['member_expiretime'] > time());
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > time();
// 查询商家认证状态与商铺资料
$merchant = Db::name('fc_merchant')->where('user_id', $user['id'])->find();
$isMerchant = $merchant && (int)$merchant['audit_status'] === 1 && $merchant['shop_status'] === 'normal';