feat: 新增电话拨打功能及相关配置,完善农产品分类与地区数据
- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录 - 新增平台免责声明内容及协议接口,完善用户服务协议相关配置 - 新增农产品分类图标与上市角标展示,优化分类管理界面样式 - 新增全国行政区划工具类与城市选择组件,重构地区数据结构 - 新增SSH自检与部署脚本,完善项目部署流程
这个提交包含在:
@@ -5,6 +5,7 @@ namespace app\api\controller;
|
||||
use think\Db;
|
||||
use app\common\library\DistributionService;
|
||||
use app\common\library\CouponService;
|
||||
use app\common\library\NationalArea;
|
||||
|
||||
/**
|
||||
* 用户端 · 信息发布与详情(Module-POST)
|
||||
@@ -57,12 +58,13 @@ class Post extends V1
|
||||
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
|
||||
|
||||
// 扩展名白名单:[媒体类型, 体积上限(字节), 允许的真实 MIME]
|
||||
// 图片限制 ≤ 5MB,保障顶部轮播加载速度与清晰度
|
||||
$allow = [
|
||||
'jpg' => ['image', 10 * 1024 * 1024, ['image/jpeg']],
|
||||
'jpeg' => ['image', 10 * 1024 * 1024, ['image/jpeg']],
|
||||
'png' => ['image', 10 * 1024 * 1024, ['image/png']],
|
||||
'gif' => ['image', 10 * 1024 * 1024, ['image/gif']],
|
||||
'webp' => ['image', 10 * 1024 * 1024, ['image/webp']],
|
||||
'jpg' => ['image', 5 * 1024 * 1024, ['image/jpeg']],
|
||||
'jpeg' => ['image', 5 * 1024 * 1024, ['image/jpeg']],
|
||||
'png' => ['image', 5 * 1024 * 1024, ['image/png']],
|
||||
'gif' => ['image', 5 * 1024 * 1024, ['image/gif']],
|
||||
'webp' => ['image', 5 * 1024 * 1024, ['image/webp']],
|
||||
'mp4' => ['video', 50 * 1024 * 1024, ['video/mp4']],
|
||||
'mov' => ['video', 50 * 1024 * 1024, ['video/quicktime']],
|
||||
];
|
||||
@@ -80,7 +82,7 @@ class Post extends V1
|
||||
$this->fail('文件大小超出限制');
|
||||
}
|
||||
if ($size > $maxSize) {
|
||||
$this->fail('文件大小超出限制');
|
||||
$this->fail($type === 'image' ? '单张图片大小不能超过 5MB' : '文件大小超出限制');
|
||||
}
|
||||
|
||||
// 真实 MIME 双重校验(读临时文件头,图片/视频都必须命中白名单);
|
||||
@@ -96,6 +98,23 @@ class Post extends V1
|
||||
}
|
||||
}
|
||||
|
||||
// 轮播图片宽高比校验(0.75 ~ 2.2,即 3:4 至 16:9 之间,避免极端长条图破坏详情页轮播展示)
|
||||
$imgWidth = 0;
|
||||
$imgHeight = 0;
|
||||
if ($type === 'image' && function_exists('getimagesize')) {
|
||||
$imgInfo = @getimagesize($file->getPathname());
|
||||
if (is_array($imgInfo) && !empty($imgInfo[0]) && !empty($imgInfo[1])) {
|
||||
$imgWidth = (int)$imgInfo[0];
|
||||
$imgHeight = (int)$imgInfo[1];
|
||||
if ($imgWidth >= 50 && $imgHeight >= 50) {
|
||||
$ratio = $imgWidth / $imgHeight;
|
||||
if ($ratio < 0.75 || $ratio > 2.2) {
|
||||
$this->fail('为保障轮播展示效果,请上传宽高比在 3:4 ~ 16:9 之间的横图或方图');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$dirName = date('Ymd');
|
||||
$saveName = $file->hash('md5') . '.' . $ext; // md5 命名:同内容文件天然去重
|
||||
$destDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . $dirName . DS;
|
||||
@@ -105,10 +124,12 @@ class Post extends V1
|
||||
}
|
||||
|
||||
$this->ok([
|
||||
'url' => '/uploads/' . $dirName . '/' . $saveName,
|
||||
'type' => $type,
|
||||
'size' => $size,
|
||||
'name' => $name,
|
||||
'url' => '/uploads/' . $dirName . '/' . $saveName,
|
||||
'type' => $type,
|
||||
'size' => $size,
|
||||
'name' => $name,
|
||||
'width' => $imgWidth,
|
||||
'height' => $imgHeight,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -131,12 +152,27 @@ class Post extends V1
|
||||
$user = $this->auth();
|
||||
|
||||
$categoryId = (int)$this->input('categoryId', 0);
|
||||
$subCategoryId = (int)$this->input('subCategoryId', 0);
|
||||
$title = trim((string)$this->input('title', ''));
|
||||
$content = trim((string)$this->input('content', ''));
|
||||
|
||||
if ($categoryId <= 0 && $subCategoryId > 0) {
|
||||
$categoryId = $subCategoryId;
|
||||
}
|
||||
if ($categoryId <= 0) {
|
||||
$this->fail('分类不能为空');
|
||||
}
|
||||
// 若传入的 categoryId 是二级分类(pid > 0),自动归属其一级大类与二级分类
|
||||
$catRow = Db::name('fc_category')->where('id', $categoryId)->find();
|
||||
if ($catRow && !empty($catRow['pid']) && (int)$catRow['pid'] > 0) {
|
||||
$subCategoryId = (int)$catRow['id'];
|
||||
$categoryId = (int)$catRow['pid'];
|
||||
} elseif ($subCategoryId > 0) {
|
||||
$subRow = Db::name('fc_category')->where('id', $subCategoryId)->find();
|
||||
if ($subRow && !empty($subRow['pid']) && (int)$subRow['pid'] > 0) {
|
||||
$categoryId = (int)$subRow['pid'];
|
||||
}
|
||||
}
|
||||
if ($title === '') {
|
||||
$this->fail('标题不能为空');
|
||||
}
|
||||
@@ -262,15 +298,33 @@ class Post extends V1
|
||||
}
|
||||
$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);
|
||||
if ($price > 0 && $priceUnit === '') {
|
||||
$priceUnit = '元/斤';
|
||||
}
|
||||
$wechat = ''; // 微信字段已移除
|
||||
$address = mb_substr(trim((string)$this->input('address', '')), 0, 128);
|
||||
$plantArea = mb_substr(trim((string)$this->input('plantArea', '')), 0, 64);
|
||||
$harvestTime = mb_substr(trim((string)$this->input('harvestTime', '')), 0, 64);
|
||||
$outputRange = mb_substr(trim((string)$this->input('outputRange', '')), 0, 64);
|
||||
|
||||
// 农产品分类(kind=farm)必须完善产地规格与价格;通用分类(招聘求职等)自动跳过这些校验
|
||||
$topCatRow = Db::name('fc_category')->where('id', $categoryId)->find();
|
||||
$isFarmCategory = $topCatRow && isset($topCatRow['kind']) && $topCatRow['kind'] === 'farm';
|
||||
if ($isFarmCategory) {
|
||||
if ($plantArea === '' || $harvestTime === '' || $outputRange === '') {
|
||||
$this->fail('请完善种植面积、采摘时间与预计量产');
|
||||
}
|
||||
if ($price <= 0) {
|
||||
$this->fail('请填写销售价格');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 发布落库 + 扣款 + 订单 + 额度扣减 同一事务:任一步失败整体回滚
|
||||
Db::transaction(function () use (
|
||||
&$postId, &$order, &$balanceAfter, &$quotaLeft,
|
||||
$paid, $user, $amount, $originAmount, $couponAmount, $userCouponId, $payType,
|
||||
$now, $categoryId, $identityType, $title, $content, $phone, $wechat, $price, $priceUnit, $address, $useQuota, $region, $cover
|
||||
$now, $categoryId, $subCategoryId, $identityType, $title, $content, $phone, $wechat, $price, $priceUnit, $address, $plantArea, $harvestTime, $outputRange, $useQuota, $region, $cover
|
||||
) {
|
||||
$paidNow = $paid && $payType === 'balance';
|
||||
// 订单号提前生成:优惠券锁定需要绑定订单号
|
||||
@@ -293,21 +347,27 @@ 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' => $price,
|
||||
'price_unit' => $priceUnit,
|
||||
'area' => $region['area'],
|
||||
'district_id' => $region['district_id'],
|
||||
'address' => $address,
|
||||
'contact' => (string)$this->input('contact', ''),
|
||||
'phone' => $phone,
|
||||
'wechat' => $wechat,
|
||||
'user_id' => $user['id'],
|
||||
'category_id' => $categoryId,
|
||||
'sub_category_id' => $subCategoryId,
|
||||
'identity_type' => $identityType,
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'cover' => $cover,
|
||||
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
|
||||
'price' => $price,
|
||||
'price_unit' => $priceUnit,
|
||||
'province' => $region['province'],
|
||||
'city' => $region['city'],
|
||||
'area' => $region['area'],
|
||||
'district_id' => $region['district_id'],
|
||||
'address' => $address,
|
||||
'plant_area' => $plantArea,
|
||||
'harvest_time' => $harvestTime,
|
||||
'output_range' => $outputRange,
|
||||
'contact' => (string)$this->input('contact', ''),
|
||||
'phone' => $phone,
|
||||
'wechat' => $wechat,
|
||||
'tags' => $this->tagsString(),
|
||||
// LBS 坐标(gcj02;未定位/为 0 时存 NULL,首页「附近」不参与距离排序)
|
||||
'lat' => $this->coord('lat', 90),
|
||||
@@ -434,28 +494,37 @@ class Post extends V1
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$cat = Db::name('fc_category')->where('id', $row['category_id'])->find();
|
||||
$subCatId = isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0;
|
||||
$subCat = $subCatId > 0 ? Db::name('fc_category')->where('id', $subCatId)->find() : null;
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'categoryName' => $cat ? (string)$cat['name'] : '',
|
||||
'cover' => (string)$row['cover'],
|
||||
'price' => (float)$row['price'],
|
||||
'priceUnit' => (string)$row['price_unit'],
|
||||
'area' => (string)$row['area'],
|
||||
'areaId' => (int)$row['district_id'],
|
||||
'address' => (string)$row['address'],
|
||||
'auditStatus' => (int)$row['audit_status'],
|
||||
'auditReason' => (string)$row['audit_reason'],
|
||||
'status' => (int)$row['status'],
|
||||
'isTop' => (int)$row['is_top'] === 1,
|
||||
'isPaid' => (int)$row['is_paid'] === 1,
|
||||
'amount' => (float)$row['amount'],
|
||||
'views' => (int)$row['views'],
|
||||
'likes' => (int)$row['likes'],
|
||||
'commentCount' => (int)$row['comment_count'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
'id' => (int)$row['id'],
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'categoryName' => $cat ? (string)$cat['name'] : '',
|
||||
'subCategoryId' => $subCatId,
|
||||
'subCategoryName' => $subCat ? (string)$subCat['name'] : '',
|
||||
'cover' => (string)$row['cover'],
|
||||
'price' => (float)$row['price'],
|
||||
'priceUnit' => (string)$row['price_unit'],
|
||||
'province' => isset($row['province']) ? (string)$row['province'] : '',
|
||||
'city' => isset($row['city']) ? (string)$row['city'] : '',
|
||||
'area' => (string)$row['area'],
|
||||
'areaId' => (int)$row['district_id'],
|
||||
'address' => (string)$row['address'],
|
||||
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
|
||||
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
|
||||
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
|
||||
'auditStatus' => (int)$row['audit_status'],
|
||||
'auditReason' => (string)$row['audit_reason'],
|
||||
'status' => (int)$row['status'],
|
||||
'isTop' => (int)$row['is_top'] === 1,
|
||||
'isPaid' => (int)$row['is_paid'] === 1,
|
||||
'amount' => (float)$row['amount'],
|
||||
'views' => (int)$row['views'],
|
||||
'likes' => (int)$row['likes'],
|
||||
'commentCount' => (int)$row['comment_count'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -680,24 +749,30 @@ class Post extends V1
|
||||
$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'],
|
||||
'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']),
|
||||
'draftId' => (int)$row['id'],
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'subCategoryId' => isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0,
|
||||
'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' => '',
|
||||
'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,
|
||||
'province' => isset($row['province']) ? (string)$row['province'] : '',
|
||||
'city' => isset($row['city']) ? (string)$row['city'] : '',
|
||||
'area' => (string)$row['area'],
|
||||
'areaId' => (int)$row['district_id'],
|
||||
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
|
||||
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
|
||||
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
|
||||
'savedAt' => $this->iso($row['savedat']),
|
||||
];
|
||||
}
|
||||
$this->ok($list);
|
||||
@@ -733,6 +808,7 @@ class Post extends V1
|
||||
|
||||
$draftId = (int)$this->input('draftId', 0);
|
||||
$categoryId = (int)$this->input('categoryId', 0);
|
||||
$subCategoryId = (int)$this->input('subCategoryId', 0);
|
||||
$title = (string)$this->input('title', '');
|
||||
$content = (string)$this->input('content', '');
|
||||
$now = time();
|
||||
@@ -741,25 +817,31 @@ class Post extends V1
|
||||
$identityType = ($identityTypeInput === 'merchant' || $identityTypeInput === '2') ? 2 : 1;
|
||||
|
||||
$data = [
|
||||
'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,
|
||||
'user_id' => $user['id'],
|
||||
'category_id' => $categoryId,
|
||||
'sub_category_id' => $subCategoryId,
|
||||
'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' => '',
|
||||
'tags' => $this->tagsString(),
|
||||
'address' => mb_substr(trim((string)$this->input('address', '')), 0, 128),
|
||||
'lat' => $this->coord('lat', 90),
|
||||
'lng' => $this->coord('lng', 180),
|
||||
'province' => mb_substr(trim((string)$this->input('province', '')), 0, 32),
|
||||
'city' => mb_substr(trim((string)$this->input('city', '')), 0, 32),
|
||||
'area' => (string)$this->input('area', ''),
|
||||
'district_id' => (int)$this->input('areaId', (int)$this->input('districtId', 0)),
|
||||
'plant_area' => mb_substr(trim((string)$this->input('plantArea', '')), 0, 64),
|
||||
'harvest_time' => mb_substr(trim((string)$this->input('harvestTime', '')), 0, 64),
|
||||
'output_range' => mb_substr(trim((string)$this->input('outputRange', '')), 0, 64),
|
||||
'savedat' => $now,
|
||||
'updatetime' => $now,
|
||||
];
|
||||
|
||||
if ($draftId > 0) {
|
||||
@@ -926,33 +1008,150 @@ class Post extends V1
|
||||
$data['freeViewLeft'] = $freeViewLeft;
|
||||
$data['payViewPrice'] = $isFreeView ? 0 : $payViewPrice;
|
||||
|
||||
// 真实解锁态判定:全站免费公开模式、本人发布、或已生成有效解锁记录
|
||||
if ($isFreeView || $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']);
|
||||
// 若发帖人有关联商家门店,在解锁态下一并展现真实门店电话
|
||||
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']);
|
||||
}
|
||||
// 每日电话拨打次数上限与剩余额度(详情预览页隐藏明文手机号,仅保留免责声明弹窗拨打)
|
||||
$callState = $this->callQuotaState($me ? (int)$me['id'] : 0, $isMember);
|
||||
$rawPhone = (string)$post['phone'];
|
||||
$contactName = (string)(isset($post['contact']) ? $post['contact'] : '');
|
||||
$maskedPhone = $this->maskPhone($rawPhone);
|
||||
|
||||
$data['hasPhone'] = $rawPhone !== '';
|
||||
$data['dialDisplay'] = $this->buildDialDisplay($contactName, $rawPhone);
|
||||
$data['callQuotaTotal'] = $callState['total'];
|
||||
$data['callQuotaUsed'] = $callState['used'];
|
||||
$data['callQuotaLeft'] = $callState['left'];
|
||||
$data['canDial'] = $isOwner || $paid || $callState['unlimited'] || $callState['left'] > 0;
|
||||
|
||||
// 界面上始终隐藏明文手机号(仅返回脱敏号码),通过 POST /post/:id/dial 校验额度并调起系统拨号
|
||||
$data['unlocked'] = ($isFreeView || $isOwner || $paid);
|
||||
$data['phone'] = $maskedPhone;
|
||||
$data['contact'] = $maskedPhone;
|
||||
$data['contactName'] = $contactName;
|
||||
$data['wechat'] = '';
|
||||
|
||||
// 标题与详细描述中的任何手机号执行动态安全遮蔽,防止正文直接贴电话
|
||||
if (!empty($data['content'])) {
|
||||
$data['content'] = $this->maskTextPhones($data['content']);
|
||||
}
|
||||
if (!empty($data['title'])) {
|
||||
$data['title'] = $this->maskTextPhones($data['title']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造免责声明拨打弹窗展示文案(如:夏178****8426)
|
||||
*
|
||||
* @param string $contactName 联系人姓名
|
||||
* @param string $phone 手机号
|
||||
* @return string
|
||||
*/
|
||||
protected function buildDialDisplay($contactName, $phone)
|
||||
{
|
||||
$masked = $this->maskPhone($phone);
|
||||
$name = trim((string)$contactName);
|
||||
if ($name === '') {
|
||||
return $masked;
|
||||
}
|
||||
$surname = mb_substr($name, 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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* P6-B 信息详情页申请拨打电话(校验每日拨打次数上限并记录拨打日志)
|
||||
* POST /api/v1/post/:id/dial
|
||||
* → {phoneNumber, dialDisplay, callQuotaTotal, callQuotaUsed, callQuotaLeft}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dial()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$id = $this->routeId();
|
||||
|
||||
$post = Db::name('fc_post')->where('id', $id)->whereNull('deletetime')->find();
|
||||
if (!$post) {
|
||||
$this->fail('信息不存在', 404);
|
||||
}
|
||||
|
||||
$phone = trim((string)$post['phone']);
|
||||
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)$post['user_id'] === (int)$user['id'];
|
||||
$paid = (bool)Db::name('fc_pay_view')
|
||||
->where('user_id', $user['id'])
|
||||
->where('post_id', $id)
|
||||
->find();
|
||||
|
||||
$state = $this->callQuotaState((int)$user['id'], $isMember);
|
||||
|
||||
// 非本人且未单条付费解锁时,校验每日拨打次数上限
|
||||
if (!$isOwner && !$paid && !$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' => 'post',
|
||||
'target_id' => (int)$id,
|
||||
'phone' => $phone,
|
||||
'call_date' => $today,
|
||||
'createtime' => $now,
|
||||
]);
|
||||
|
||||
$newUsed = $state['used'] + 1;
|
||||
$newLeft = $state['unlimited'] ? 999 : max(0, $state['total'] - $newUsed);
|
||||
|
||||
$this->ok([
|
||||
'phoneNumber' => $phone,
|
||||
'dialDisplay' => $this->buildDialDisplay(isset($post['contact']) ? $post['contact'] : '', $phone),
|
||||
'callQuotaTotal' => $state['total'],
|
||||
'callQuotaUsed' => $newUsed,
|
||||
'callQuotaLeft' => $newLeft,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员每日免费查看条数(从用户所属 fc_plan 套餐或默认套餐读取;0 代表会员无限次免费看)
|
||||
*
|
||||
@@ -1409,10 +1608,9 @@ class Post extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析发布信息的服务区域(区县)
|
||||
* 优先级:areaId(兼容 districtId)> area 名称 > 经纬度最近区域(300km 内)。
|
||||
* 未提供任何区域时返回空区域,保持与旧客户端兼容。
|
||||
* @return array{area:string,district_id:int}
|
||||
* 解析发布信息的全国服务区域(省/市/区县)
|
||||
* 优先级:areaId(兼容 districtId)> area 名称 > 经纬度最近区域。
|
||||
* @return array{province:string,city:string,area:string,district_id:int}
|
||||
*/
|
||||
protected function resolveRegion()
|
||||
{
|
||||
@@ -1420,49 +1618,58 @@ class Post extends V1
|
||||
if (!$areaId) {
|
||||
$areaId = (int)$this->input('districtId', 0);
|
||||
}
|
||||
$provinceInput = trim((string)$this->input('province', ''));
|
||||
$cityInput = trim((string)$this->input('city', ''));
|
||||
$areaName = trim((string)$this->input('area', ''));
|
||||
$area = null;
|
||||
|
||||
if ($areaId > 0) {
|
||||
$area = Db::name('fc_area')
|
||||
->where('id', $areaId)
|
||||
->where('enabled', 1)
|
||||
->find();
|
||||
$area = NationalArea::findById($areaId);
|
||||
if (!$area) {
|
||||
$area = Db::name('fc_area')
|
||||
->where('id', $areaId)
|
||||
->where('enabled', 1)
|
||||
->find();
|
||||
}
|
||||
if (!$area) {
|
||||
$this->fail('所选服务区域不可用,请重新选择');
|
||||
}
|
||||
} elseif ($areaName !== '') {
|
||||
$area = Db::name('fc_area')
|
||||
->where('district', $areaName)
|
||||
->where('enabled', 1)
|
||||
->find();
|
||||
$area = NationalArea::findByDistrict($areaName, $provinceInput, $cityInput);
|
||||
if (!$area) {
|
||||
$area = Db::name('fc_area')
|
||||
->where('district', $areaName)
|
||||
->where('enabled', 1)
|
||||
->find();
|
||||
}
|
||||
} else {
|
||||
$lat = $this->coord('lat', 90);
|
||||
$lng = $this->coord('lng', 180);
|
||||
if ($lat !== null && $lng !== null) {
|
||||
$rows = Db::name('fc_area')
|
||||
->where('enabled', 1)
|
||||
->whereNotNull('lat')
|
||||
->whereNotNull('lng')
|
||||
->select();
|
||||
$best = null;
|
||||
foreach ($rows as $row) {
|
||||
$distance = $this->haversine($lat, $lng, (float)$row['lat'], (float)$row['lng']);
|
||||
if ($best === null || $distance < $best['distance']) {
|
||||
$best = ['row' => $row, 'distance' => $distance];
|
||||
}
|
||||
}
|
||||
if ($best && $best['distance'] <= 300) {
|
||||
$area = $best['row'];
|
||||
$located = NationalArea::locate($lat, $lng);
|
||||
if ($located) {
|
||||
$area = [
|
||||
'id' => $located['areaId'],
|
||||
'province' => $located['province'],
|
||||
'city' => $located['city'],
|
||||
'district' => $located['district'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$area) {
|
||||
return ['area' => $areaName, 'district_id' => 0];
|
||||
return [
|
||||
'province' => $provinceInput,
|
||||
'city' => $cityInput,
|
||||
'area' => $areaName,
|
||||
'district_id' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'province' => isset($area['province']) ? (string)$area['province'] : $provinceInput,
|
||||
'city' => isset($area['city']) ? (string)$area['city'] : $cityInput,
|
||||
'area' => (string)$area['district'],
|
||||
'district_id' => (int)$area['id'],
|
||||
];
|
||||
@@ -1584,6 +1791,15 @@ class Post extends V1
|
||||
}
|
||||
}
|
||||
|
||||
$subCategoryId = isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0;
|
||||
$subCategoryName = '';
|
||||
if ($subCategoryId > 0) {
|
||||
$subCat = Db::name('fc_category')->where('id', $subCategoryId)->find();
|
||||
if ($subCat) {
|
||||
$subCategoryName = (string)$subCat['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$publisher = ['id' => 0, 'name' => '', 'avatar' => '', 'isMerchant' => false, 'verified' => false, 'isMember' => false, 'memberLevel' => ''];
|
||||
$merchant = null;
|
||||
if (!empty($row['user_id'])) {
|
||||
@@ -1666,39 +1882,46 @@ class Post extends V1
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $postId,
|
||||
'userId' => (int)$row['user_id'],
|
||||
'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'],
|
||||
'media' => $this->jsonArr(isset($row['media']) ? $row['media'] : ''),
|
||||
'price' => (float)$row['price'],
|
||||
'priceUnit' => (string)$row['price_unit'],
|
||||
'area' => (string)$row['area'],
|
||||
'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,
|
||||
'auditStatus' => (int)$row['audit_status'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
'tags' => $tags,
|
||||
'publisher' => $publisher,
|
||||
'merchant' => $merchant,
|
||||
'commentCount' => (int)$row['comment_count'],
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
'distance' => $this->postDistance($row),
|
||||
'faved' => $faved,
|
||||
'followed' => $followed,
|
||||
'favoriteCount' => $favoriteCount,
|
||||
'id' => $postId,
|
||||
'userId' => (int)$row['user_id'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'categoryName' => $categoryName,
|
||||
'subCategoryId' => $subCategoryId,
|
||||
'subCategoryName' => $subCategoryName,
|
||||
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'cover' => (string)$row['cover'],
|
||||
'media' => $this->jsonArr(isset($row['media']) ? $row['media'] : ''),
|
||||
'price' => (float)$row['price'],
|
||||
'priceUnit' => (string)$row['price_unit'],
|
||||
'province' => isset($row['province']) ? (string)$row['province'] : '',
|
||||
'city' => isset($row['city']) ? (string)$row['city'] : '',
|
||||
'area' => (string)$row['area'],
|
||||
'areaId' => (int)$row['district_id'],
|
||||
'address' => (string)$row['address'],
|
||||
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
|
||||
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
|
||||
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
|
||||
'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,
|
||||
'auditStatus' => (int)$row['audit_status'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
'tags' => $tags,
|
||||
'publisher' => $publisher,
|
||||
'merchant' => $merchant,
|
||||
'commentCount' => (int)$row['comment_count'],
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
'distance' => $this->postDistance($row),
|
||||
'faved' => $faved,
|
||||
'followed' => $followed,
|
||||
'favoriteCount' => $favoriteCount,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户