feat: 新增发布额度权益与订单管理功能,优化多端交互细节

这个提交包含在:
2026-10-23 15:42:55 +08:00
父节点 3a2fcf7142
当前提交 691747726b
共有 208 个文件被更改,包括 11880 次插入 和 2262 次删除

查看文件

@@ -19,6 +19,7 @@ use app\common\library\CouponService;
* GET /api/v1/post/:id P5 信息详情
* POST /api/v1/post/:id/pay-view P6 付费查看联系方式
* POST /api/v1/post/:id/comment P7 发表评价
* POST /api/v1/post/comment/:id/reply P11 发布者回复评价
* GET /api/v1/post/:id/comments P10 评价列表(详情页「用户评价」)
*
* 计费口径(后台「发布与费用配置」维护,真源=fc_config);
@@ -247,12 +248,25 @@ class Post extends V1
$order = null;
$balanceAfter = 0;
$identityTypeInput = (string)$this->input('identityType', 'person');
$identityType = ($identityTypeInput === 'merchant' || $identityTypeInput === '2') ? 2 : 1;
if ($identityType === 2) {
$userExt = Db::name('fc_user_ext')->where('user_id', $user['id'])->find();
if (!$userExt || (int)$userExt['user_type'] !== 2) {
$identityType = 1;
}
}
$price = max(0, round((float)$this->input('price', 0), 2));
$priceUnit = mb_substr(trim((string)$this->input('priceUnit', '')), 0, 16);
$wechat = mb_substr(trim((string)$this->input('wechat', '')), 0, 64);
$address = mb_substr(trim((string)$this->input('address', '')), 0, 128);
try {
// 发布落库 + 扣款 + 订单 + 额度扣减 同一事务:任一步失败整体回滚
Db::transaction(function () use (
&$postId, &$order, &$balanceAfter, &$quotaLeft,
$paid, $user, $amount, $originAmount, $couponAmount, $userCouponId, $payType,
$now, $categoryId, $title, $content, $phone, $useQuota, $region, $cover
$now, $categoryId, $identityType, $title, $content, $phone, $wechat, $price, $priceUnit, $address, $useQuota, $region, $cover
) {
$paidNow = $paid && $payType === 'balance';
// 订单号提前生成:优惠券锁定需要绑定订单号
@@ -277,18 +291,19 @@ class Post extends V1
$postId = Db::name('fc_post')->insertGetId([
'user_id' => $user['id'],
'category_id' => $categoryId,
'identity_type' => $identityType,
'title' => $title,
'content' => $content,
'cover' => $cover,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'price' => round((float)$this->input('price', 0), 2),
'price_unit' => (string)$this->input('priceUnit', ''),
'price' => $price,
'price_unit' => $priceUnit,
'area' => $region['area'],
'district_id' => $region['district_id'],
'address' => (string)$this->input('address', ''),
'address' => $address,
'contact' => (string)$this->input('contact', ''),
'phone' => $phone,
'wechat' => '',
'wechat' => $wechat,
'tags' => $this->tagsString(),
// LBS 坐标(gcj02;未定位/为 0 时存 NULL,首页「附近」不参与距离排序)
'lat' => $this->coord('lat', 90),
@@ -628,18 +643,29 @@ class Post extends V1
$list = [];
foreach ($rows as $row) {
$media = json_decode((string)$row['media'], true);
$tags = [];
if (!empty($row['tags'])) {
$tags = array_values(array_filter(array_map('trim', explode(',', (string)$row['tags']))));
}
$list[] = [
'draftId' => (int)$row['id'],
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'categoryId' => (int)$row['category_id'],
'media' => is_array($media) ? $media : [],
'contact' => (string)$row['contact'],
'phone' => (string)$row['phone'],
'address' => (string)$row['address'],
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'savedAt' => $this->iso($row['savedat']),
'draftId' => (int)$row['id'],
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'categoryId' => (int)$row['category_id'],
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
'media' => is_array($media) ? $media : [],
'price' => (float)(isset($row['price']) ? $row['price'] : 0),
'priceUnit' => (string)(isset($row['price_unit']) ? $row['price_unit'] : ''),
'contact' => (string)$row['contact'],
'phone' => (string)$row['phone'],
'wechat' => (string)(isset($row['wechat']) ? $row['wechat'] : ''),
'tags' => $tags,
'address' => (string)$row['address'],
'lat' => isset($row['lat']) && $row['lat'] !== null ? (float)$row['lat'] : null,
'lng' => isset($row['lng']) && $row['lng'] !== null ? (float)$row['lng'] : null,
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'savedAt' => $this->iso($row['savedat']),
];
}
$this->ok($list);
@@ -679,19 +705,29 @@ class Post extends V1
$content = (string)$this->input('content', '');
$now = time();
$identityTypeInput = (string)$this->input('identityType', 'person');
$identityType = ($identityTypeInput === 'merchant' || $identityTypeInput === '2') ? 2 : 1;
$data = [
'user_id' => $user['id'],
'category_id' => $categoryId,
'title' => $title,
'content' => $content,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'contact' => (string)$this->input('contact', ''),
'phone' => (string)$this->input('phone', ''),
'address' => (string)$this->input('address', ''),
'area' => (string)$this->input('area', ''),
'district_id' => (int)$this->input('areaId', (int)$this->input('districtId', 0)),
'savedat' => $now,
'updatetime' => $now,
'user_id' => $user['id'],
'category_id' => $categoryId,
'identity_type' => $identityType,
'title' => $title,
'content' => $content,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'price' => max(0, round((float)$this->input('price', 0), 2)),
'price_unit' => mb_substr(trim((string)$this->input('priceUnit', '')), 0, 16),
'contact' => (string)$this->input('contact', ''),
'phone' => (string)$this->input('phone', ''),
'wechat' => mb_substr(trim((string)$this->input('wechat', '')), 0, 64),
'tags' => $this->tagsString(),
'address' => mb_substr(trim((string)$this->input('address', '')), 0, 128),
'lat' => $this->coord('lat', 90),
'lng' => $this->coord('lng', 180),
'area' => (string)$this->input('area', ''),
'district_id' => (int)$this->input('areaId', (int)$this->input('districtId', 0)),
'savedat' => $now,
'updatetime' => $now,
];
if ($draftId > 0) {
@@ -813,9 +849,11 @@ class Post extends V1
$used = ((string)$ext['free_view_date'] === $today) ? (int)$ext['free_view_used'] : 0;
$data['freeViewLeft'] = $isMember ? max(0, $quota - $used) : 0;
if ($isOwner || $paid) {
if ($isOwner || $paid || $isMember) {
$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']);
}
@@ -1009,6 +1047,11 @@ class Post extends V1
$this->fail('信息不存在', 404);
}
// 禁止发布者对自己的信息发表评价
if ((int)$post['user_id'] === (int)$user['id']) {
$this->fail('不能评价自己发布的信息');
}
$now = time();
$commentId = Db::name('fc_comment')->insertGetId([
'post_id' => $id,
@@ -1035,6 +1078,68 @@ class Post extends V1
$this->ok(['commentId' => $commentId]);
}
/**
* P11 发布者回复评价
* POST /api/v1/post/comment/:id/reply {reply} → {id, reply, replytime}
* 规则:仅本信息的发布者可对该信息下的评价进行回复
*
* @return void
*/
public function replyComment()
{
$user = $this->auth();
$commentId = (int)$this->request->param('id', 0);
if (!$commentId) {
$commentId = (int)$this->input('commentId', 0);
}
if ($commentId <= 0) {
$this->fail('评价不存在', 404);
}
$reply = trim((string)$this->input('reply', ''));
if ($reply === '') {
$this->fail('回复内容不能为空');
}
if (mb_strlen($reply, 'UTF-8') > 200) {
$this->fail('回复内容不能超过 200 个字');
}
$comment = Db::name('fc_comment')->where('id', $commentId)->find();
if (!$comment) {
$this->fail('评价不存在', 404);
}
$post = Db::name('fc_post')->where('id', $comment['post_id'])->whereNull('deletetime')->find();
if (!$post) {
$this->fail('对应信息不存在', 404);
}
// 仅限信息发布者(楼主/商家)回复
if ((int)$post['user_id'] !== (int)$user['id']) {
$this->fail('只有发布者本人可以回复评价', 403);
}
$now = time();
Db::name('fc_comment')->where('id', $commentId)->update([
'reply' => $reply,
'replytime' => $now,
'updatetime' => $now,
]);
$this->notify(
$comment['user_id'],
'interact',
'评价收到回复',
'发布者回复了您对「' . (string)$post['title'] . '」的评价:' . $reply
);
$this->ok([
'id' => $commentId,
'reply' => $reply,
'replytime' => $now,
]);
}
/**
* P10 评价列表(详情页「用户评价」)
* GET /api/v1/post/:id/comments → [{id,user,score,content,reply,createdAt}]
@@ -1052,7 +1157,7 @@ class Post extends V1
->join('user u', 'u.id = co.user_id', 'LEFT')
->where('co.post_id', $id)
->where('co.status', 1)
->field('co.id, co.score, co.content, co.reply, co.top, co.createtime, u.nickname AS nickname')
->field('co.id, co.user_id, co.score, co.content, co.reply, co.replytime, co.top, co.createtime, u.nickname AS nickname')
->order('co.top desc, co.id desc')
->select();
@@ -1060,10 +1165,12 @@ class Post extends V1
foreach ($rows as $row) {
$list[] = [
'id' => (int)$row['id'],
'userId' => (int)$row['user_id'],
'user' => (string)$row['nickname'],
'score' => (int)$row['score'],
'content' => (string)$row['content'],
'reply' => (string)$row['reply'],
'replytime' => !empty($row['replytime']) ? $this->iso($row['replytime']) : '',
'createdAt' => $this->iso($row['createtime']),
];
}
@@ -1286,9 +1393,10 @@ class Post extends V1
{
$tags = $this->input('tags', []);
if (is_array($tags)) {
$tags = array_values(array_filter(array_map('trim', $tags)));
$tags = implode(',', $tags);
}
return (string)$tags;
return mb_substr(trim((string)$tags), 0, 128);
}
/**
@@ -1370,6 +1478,7 @@ class Post extends V1
'id' => $postId,
'categoryId' => (int)$row['category_id'],
'categoryName' => $categoryName,
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'cover' => (string)$row['cover'],
@@ -1380,6 +1489,9 @@ class Post extends V1
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'contact' => $this->maskPhone($row['phone']),
'phone' => $this->maskPhone($row['phone']),
'contactName' => (string)(isset($row['contact']) ? $row['contact'] : ''),
'isTop' => isset($row['is_top']) && (int)$row['is_top'] === 1,
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'isPaid' => (int)$row['is_paid'] === 1,