feat: 新增电话拨打功能及相关配置,完善农产品分类与地区数据
- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录 - 新增平台免责声明内容及协议接口,完善用户服务协议相关配置 - 新增农产品分类图标与上市角标展示,优化分类管理界面样式 - 新增全国行政区划工具类与城市选择组件,重构地区数据结构 - 新增SSH自检与部署脚本,完善项目部署流程
这个提交包含在:
@@ -7,15 +7,16 @@ use think\Db;
|
||||
/**
|
||||
* 用户端 · 商家门店与主页(Module-MERCHANT)
|
||||
* 路由:
|
||||
* GET /api/v1/merchant/:id M1 商家公开主页/门店详情
|
||||
* GET /api/v1/merchant/:id/posts M2 商家名下发布的信息流(分页)
|
||||
* GET /api/v1/merchant/:id M1 商家公开主页/门店详情(手机号隐藏脱敏)
|
||||
* POST /api/v1/merchant/:id/dial M1-B 商家门店申请拨打电话(校验每日拨打次数上限)
|
||||
* GET /api/v1/merchant/:id/posts M2 商家名下发布的信息流(分页)
|
||||
*/
|
||||
class Merchant extends V1
|
||||
{
|
||||
/**
|
||||
* M1 获取商家门店详情及公开档案
|
||||
* GET /api/v1/merchant/:id
|
||||
* 规则:允许游客;支持通过 merchant.id 或 user_id 查询;若提供客户端坐标则计算到店距离
|
||||
* 规则:允许游客;支持通过 merchant.id 或 user_id 查询;界面隐藏明文手机号,仅保留拨打按钮与免责弹窗
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -62,9 +63,10 @@ class Merchant extends V1
|
||||
// 首屏拉取前 6 条该商家的有效发帖
|
||||
$posts = $this->fetchMerchantPosts($m['user_id'], 1, 6);
|
||||
|
||||
// 严格保护商家联系电话:未付费解锁或非会员状态下脱敏,杜绝从信息详情页跳转商家主页白嫖绕过
|
||||
$rawContact = (string)(isset($m['contact']) ? $m['contact'] : '');
|
||||
$unlocked = false;
|
||||
// 商家详情页统一隐藏明文手机号(仅返回脱敏号码),通过 POST /merchant/:id/dial 校验每日拨打次数上限
|
||||
$rawContact = trim((string)(isset($m['contact']) ? $m['contact'] : ''));
|
||||
$isMember = false;
|
||||
$isOwner = false;
|
||||
$me = $this->user();
|
||||
if ($me) {
|
||||
$now = time();
|
||||
@@ -72,24 +74,11 @@ class Merchant extends V1
|
||||
$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);
|
||||
$callState = $this->callQuotaState($me ? (int)$me['id'] : 0, $isMember);
|
||||
$maskedContact = $this->maskPhone($rawContact);
|
||||
$dialDisplay = $this->buildDialDisplay($userNickname ?: (string)$m['name'], $rawContact);
|
||||
|
||||
$data = [
|
||||
'id' => (int)$m['id'],
|
||||
@@ -100,8 +89,14 @@ 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' => $displayContact,
|
||||
'unlocked' => $unlocked,
|
||||
'contact' => $maskedContact,
|
||||
'hasPhone' => $rawContact !== '',
|
||||
'dialDisplay' => $dialDisplay,
|
||||
'callQuotaTotal' => $callState['total'],
|
||||
'callQuotaUsed' => $callState['used'],
|
||||
'callQuotaLeft' => $callState['left'],
|
||||
'canDial' => $isOwner || $callState['unlimited'] || $callState['left'] > 0,
|
||||
'unlocked' => false,
|
||||
'category' => (string)(isset($m['category']) ? $m['category'] : ''),
|
||||
'notice' => (string)(isset($m['notice']) ? $m['notice'] : ''),
|
||||
'auditStatus' => (int)$m['audit_status'],
|
||||
@@ -119,6 +114,125 @@ class Merchant extends V1
|
||||
$this->ok($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* M1-B 商家详情页申请拨打电话(校验每日拨打次数上限并记录拨打日志)
|
||||
* POST /api/v1/merchant/:id/dial
|
||||
* → {phoneNumber, dialDisplay, callQuotaTotal, callQuotaUsed, callQuotaLeft}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dial()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$id = (int)$this->routeId();
|
||||
if ($id <= 0) {
|
||||
$id = (int)$this->input('id', 0) ?: (int)$this->input('userId', 0);
|
||||
}
|
||||
if ($id <= 0) {
|
||||
$this->fail('缺少商家参数', 400);
|
||||
}
|
||||
|
||||
$m = Db::name('fc_merchant')->where('id', $id)->find();
|
||||
if (!$m) {
|
||||
$m = Db::name('fc_merchant')->where('user_id', $id)->find();
|
||||
}
|
||||
if (!$m) {
|
||||
$this->fail('商家门店不存在', 404);
|
||||
}
|
||||
|
||||
$phone = trim((string)(isset($m['contact']) ? $m['contact'] : ''));
|
||||
if ($phone === '') {
|
||||
$this->fail('该商家暂未预留联系电话');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$ext = $this->ext($user['id']);
|
||||
$isMember = (int)$ext['is_member'] === 1
|
||||
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
|
||||
$isOwner = (int)$m['user_id'] === (int)$user['id'];
|
||||
|
||||
$state = $this->callQuotaState((int)$user['id'], $isMember);
|
||||
|
||||
if (!$isOwner && !$state['unlimited'] && $state['left'] <= 0) {
|
||||
$msg = $isMember
|
||||
? ('您今日的 VIP 拨打次数已达上限(' . $state['total'] . '次/日)')
|
||||
: ('您今日的免费拨打次数已达上限(' . $state['total'] . '次/日),开通 VIP 会员可享每日更多拨打次数');
|
||||
$this->fail($msg, 403);
|
||||
}
|
||||
|
||||
$today = date('Y-m-d');
|
||||
Db::name('fc_call_log')->insert([
|
||||
'user_id' => (int)$user['id'],
|
||||
'target_type' => 'merchant',
|
||||
'target_id' => (int)$m['id'],
|
||||
'phone' => $phone,
|
||||
'call_date' => $today,
|
||||
'createtime' => $now,
|
||||
]);
|
||||
|
||||
$newUsed = $state['used'] + 1;
|
||||
$newLeft = $state['unlimited'] ? 999 : max(0, $state['total'] - $newUsed);
|
||||
$pubUser = Db::name('user')->where('id', $m['user_id'])->find();
|
||||
$contactLabel = $pubUser && !empty($pubUser['nickname']) ? (string)$pubUser['nickname'] : (string)$m['name'];
|
||||
|
||||
$this->ok([
|
||||
'phoneNumber' => $phone,
|
||||
'dialDisplay' => $this->buildDialDisplay($contactLabel, $phone),
|
||||
'callQuotaTotal' => $state['total'],
|
||||
'callQuotaUsed' => $newUsed,
|
||||
'callQuotaLeft' => $newLeft,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造免责声明拨打弹窗展示文案(如:王138****8000)
|
||||
*
|
||||
* @param string $name 联系人或门店名称
|
||||
* @param string $phone 手机号
|
||||
* @return string
|
||||
*/
|
||||
protected function buildDialDisplay($name, $phone)
|
||||
{
|
||||
$masked = $this->maskPhone($phone);
|
||||
$clean = trim((string)$name);
|
||||
if ($clean === '') {
|
||||
return $masked;
|
||||
}
|
||||
$surname = mb_substr($clean, 0, 1, 'UTF-8');
|
||||
return $surname . $masked;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算指定用户今日的电话拨打额度状态
|
||||
*
|
||||
* @param int $userId 用户ID(0表示游客)
|
||||
* @param bool $isMember 是否为有效期内VIP会员
|
||||
* @return array{total:int,used:int,left:int,unlimited:bool}
|
||||
*/
|
||||
protected function callQuotaState($userId, $isMember)
|
||||
{
|
||||
$normalQuota = max(0, (int)$this->cfg('call.normalDailyQuota', 5));
|
||||
$vipQuota = max(0, (int)$this->cfg('call.vipDailyQuota', 30));
|
||||
$total = $isMember ? $vipQuota : $normalQuota;
|
||||
$unlimited = ($total === 0);
|
||||
|
||||
$used = 0;
|
||||
if ($userId > 0) {
|
||||
$today = date('Y-m-d');
|
||||
$used = (int)Db::name('fc_call_log')
|
||||
->where('user_id', $userId)
|
||||
->where('call_date', $today)
|
||||
->count();
|
||||
}
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
'used' => $used,
|
||||
'left' => $unlimited ? 999 : max(0, $total - $used),
|
||||
'unlimited' => $unlimited,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* M2 获取商家名下的信息列表(支持分页)
|
||||
* GET /api/v1/merchant/:id/posts
|
||||
@@ -179,6 +293,12 @@ class Merchant extends V1
|
||||
$cat = Db::name('fc_category')->where('id', $r['category_id'])->value('name');
|
||||
$catName = $cat ? (string)$cat : '';
|
||||
}
|
||||
$subCatId = isset($r['sub_category_id']) ? (int)$r['sub_category_id'] : 0;
|
||||
$subCatName = '';
|
||||
if ($subCatId > 0) {
|
||||
$subCat = Db::name('fc_category')->where('id', $subCatId)->value('name');
|
||||
$subCatName = $subCat ? (string)$subCat : '';
|
||||
}
|
||||
|
||||
$cover = (string)$r['cover'];
|
||||
$mediaArr = $this->jsonArr($r['media']);
|
||||
@@ -197,22 +317,29 @@ class Merchant extends V1
|
||||
}
|
||||
|
||||
$list[] = [
|
||||
'id' => (int)$r['id'],
|
||||
'title' => (string)$r['title'],
|
||||
'content' => (string)$r['content'],
|
||||
'price' => (float)$r['price'],
|
||||
'priceUnit' => (string)$r['price_unit'],
|
||||
'cover' => $cover,
|
||||
'media' => $mediaArr,
|
||||
'area' => (string)$r['area'],
|
||||
'address' => (string)$r['address'],
|
||||
'categoryId' => (int)$r['category_id'],
|
||||
'categoryName' => $catName,
|
||||
'isTop' => (int)$r['is_top'] === 1,
|
||||
'views' => (int)$r['views'],
|
||||
'commentCount' => (int)$r['comment_count'],
|
||||
'createdAt' => $this->iso($r['createtime']),
|
||||
'tags' => $tags,
|
||||
'id' => (int)$r['id'],
|
||||
'title' => (string)$r['title'],
|
||||
'content' => (string)$r['content'],
|
||||
'price' => (float)$r['price'],
|
||||
'priceUnit' => (string)$r['price_unit'],
|
||||
'cover' => $cover,
|
||||
'media' => $mediaArr,
|
||||
'province' => isset($r['province']) ? (string)$r['province'] : '',
|
||||
'city' => isset($r['city']) ? (string)$r['city'] : '',
|
||||
'area' => (string)$r['area'],
|
||||
'address' => (string)$r['address'],
|
||||
'plantArea' => isset($r['plant_area']) ? (string)$r['plant_area'] : '',
|
||||
'harvestTime' => isset($r['harvest_time']) ? (string)$r['harvest_time'] : '',
|
||||
'outputRange' => isset($r['output_range']) ? (string)$r['output_range'] : '',
|
||||
'categoryId' => (int)$r['category_id'],
|
||||
'categoryName' => $catName,
|
||||
'subCategoryId' => $subCatId,
|
||||
'subCategoryName' => $subCatName,
|
||||
'isTop' => (int)$r['is_top'] === 1,
|
||||
'views' => (int)$r['views'],
|
||||
'commentCount' => (int)$r['comment_count'],
|
||||
'createdAt' => $this->iso($r['createtime']),
|
||||
'tags' => $tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户