feat: 新增电话拨打功能及相关配置,完善农产品分类与地区数据
- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录 - 新增平台免责声明内容及协议接口,完善用户服务协议相关配置 - 新增农产品分类图标与上市角标展示,优化分类管理界面样式 - 新增全国行政区划工具类与城市选择组件,重构地区数据结构 - 新增SSH自检与部署脚本,完善项目部署流程
这个提交包含在:
@@ -3,16 +3,17 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
use app\common\library\NationalArea;
|
||||
|
||||
/**
|
||||
* 用户端 · 首页与展示(Module-HOME)
|
||||
* 路由:
|
||||
* GET /api/v1/home/banners H1 轮播广告位
|
||||
* GET /api/v1/home/categories H2 分类导航
|
||||
* GET /api/v1/home/categories H2 分类导航(含二级分类树与实拍图)
|
||||
* GET /api/v1/home/search/hot H3 热门搜索
|
||||
* GET /api/v1/home/feed H4 信息流(支持 lat/lng + sort=nearby 距离排序)
|
||||
* GET /api/v1/home/areas H5 服务区域列表(平铺省/市/区县,区县为服务区域)
|
||||
* GET /api/v1/home/locate H6 按定位坐标匹配服务区域
|
||||
* GET /api/v1/home/feed H4 信息流(支持全国省/市/区县筛选 + 一二级分类筛选 + 距离排序)
|
||||
* GET /api/v1/home/areas H5 全国服务区域列表(平铺省/市/区县)
|
||||
* GET /api/v1/home/locate H6 按定位坐标匹配全国当前区县
|
||||
*/
|
||||
class Home extends V1
|
||||
{
|
||||
@@ -48,41 +49,82 @@ class Home extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* H2 分类导航
|
||||
* GET /api/v1/home/categories → [{id,name,iconKey,icon,color,count}]
|
||||
* 规则:仅 enabled=1,按 sort asc;icon 为固定 /static/icons/ 文件名(按 id 映射)
|
||||
* H2 分类导航(一级分类 + 二级分类树,附带农产品实拍图)
|
||||
* GET /api/v1/home/categories → [{id,pid,name,iconKey,icon,image,color,count,children:[...]}]
|
||||
* 规则:仅 enabled=1,按 sort asc;一级分类下挂 children 二级分类列表
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function categories()
|
||||
{
|
||||
$rows = Db::name('fc_category')
|
||||
->where('enabled', 1)
|
||||
->order('sort asc')
|
||||
->order('pid asc, sort asc, id asc')
|
||||
->select();
|
||||
|
||||
$list = [];
|
||||
$parents = [];
|
||||
$childrenMap = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$id = (int)$row['id'];
|
||||
$pid = isset($row['pid']) ? (int)$row['pid'] : 0;
|
||||
$iconKey = (string)$row['icon_key'];
|
||||
$list[] = [
|
||||
$rawImage = isset($row['image']) ? (string)$row['image'] : '';
|
||||
$iconPath = $this->resolveCategoryIconPath($id, $iconKey, $rawImage);
|
||||
$imagePath = $rawImage !== '' ? $rawImage : $iconPath;
|
||||
|
||||
$item = [
|
||||
'id' => $id,
|
||||
'pid' => $pid,
|
||||
'name' => (string)$row['name'],
|
||||
'iconKey' => $iconKey,
|
||||
'icon' => $this->resolveCategoryIconPath($id, $iconKey),
|
||||
'icon' => $iconPath,
|
||||
'image' => $imagePath,
|
||||
'color' => (string)$row['color'],
|
||||
'kind' => isset($row['kind']) && $row['kind'] === 'farm' ? 'farm' : 'general',
|
||||
'count' => (int)$row['post_count'],
|
||||
];
|
||||
|
||||
if ($pid === 0) {
|
||||
$item['children'] = [];
|
||||
$parents[$id] = $item;
|
||||
} else {
|
||||
if (!isset($childrenMap[$pid])) {
|
||||
$childrenMap[$pid] = [];
|
||||
}
|
||||
$childrenMap[$pid][] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$list = [];
|
||||
foreach ($parents as $pid => $parent) {
|
||||
$parent['children'] = isset($childrenMap[$pid]) ? $childrenMap[$pid] : [];
|
||||
$list[] = $parent;
|
||||
}
|
||||
|
||||
// 兜底:若数据库中仅有未挂载父级的孤立分类,直接返回
|
||||
if (empty($list) && !empty($childrenMap)) {
|
||||
foreach ($childrenMap as $group) {
|
||||
foreach ($group as $c) {
|
||||
$c['children'] = [];
|
||||
$list[] = $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->ok($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* H3 热门搜索
|
||||
* GET /api/v1/home/search/hot → [string]
|
||||
* 规则:读配置 home.hotKeywords,未配置则返回默认
|
||||
* 规则:读配置 home.hotKeywords,未配置则返回农产品热门搜索词
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function hotKeywords()
|
||||
{
|
||||
$default = ['租房 一室一厅', '二手电动车', '急招快递员', '钢琴家教', '空调维修'];
|
||||
$default = ['有机花菜', '高山大白菜', '红富士苹果', '大棚草莓', '修文猕猴桃'];
|
||||
$keywords = $this->cfg('home.hotKeywords', $default);
|
||||
if (!is_array($keywords) || !$keywords) {
|
||||
$keywords = $default;
|
||||
@@ -91,37 +133,24 @@ class Home extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* H5 服务区域列表(平铺:每条记录自带省 / 市 / 区县)
|
||||
* H5 全国服务区域列表(平铺:每条记录自带省 / 市 / 区县)
|
||||
* GET /api/v1/home/areas → [{id,province,city,district,lat,lng}]
|
||||
* 规则:仅 enabled=1;按省、市、sort、id 排序。
|
||||
* 区县为最终服务区域;省 / 市由前端按 distinct 值生成级联列。
|
||||
* 规则:默认开放全国所有省市区县,供小程序端省/市/区三级联动选择。
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function areas()
|
||||
{
|
||||
$rows = Db::name('fc_area')
|
||||
->where('enabled', 1)
|
||||
->order('province asc, city asc, sort asc, id asc')
|
||||
->select();
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'province' => (string)$row['province'],
|
||||
'city' => (string)$row['city'],
|
||||
'district' => (string)$row['district'],
|
||||
'lat' => $row['lat'] !== null ? (float)$row['lat'] : null,
|
||||
'lng' => $row['lng'] !== null ? (float)$row['lng'] : null,
|
||||
];
|
||||
}
|
||||
|
||||
$list = NationalArea::all();
|
||||
$this->ok($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* H6 按定位坐标匹配服务区域(区县)
|
||||
* H6 按定位坐标匹配全国当前服务区域(省/市/区县)
|
||||
* GET /api/v1/home/locate?lat=&lng= → {areaId,province,city,district,distance}
|
||||
* 规则:在启用的服务区域中心点中取最近的一个(Haversine),超出 300km 视为不在服务范围,返回 null。
|
||||
* 规则:在全国区县字典中匹配距离当前坐标最近的区县。
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function locate()
|
||||
{
|
||||
@@ -136,107 +165,132 @@ class Home extends V1
|
||||
$this->ok(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) {
|
||||
$this->ok(null);
|
||||
}
|
||||
|
||||
$area = $best['row'];
|
||||
$this->ok([
|
||||
'areaId' => (int)$area['id'],
|
||||
'province' => (string)$area['province'],
|
||||
'city' => (string)$area['city'],
|
||||
'district' => (string)$area['district'],
|
||||
'distance' => $best['distance'],
|
||||
]);
|
||||
$matched = NationalArea::locate($lat, $lng);
|
||||
$this->ok($matched);
|
||||
}
|
||||
|
||||
/**
|
||||
* H4 信息流
|
||||
* GET /api/v1/home/feed {categoryId?,keyword?,areaId?,area?,sort?,lat?,lng?,page,size}
|
||||
* GET /api/v1/home/feed {categoryId?,subCategoryId?,keyword?,province?,city?,areaId?,area?,sort?,lat?,lng?,page,size}
|
||||
* → {list,page,size,total,hasMore}
|
||||
* 规则:仅 audit_status=1 AND status=1 AND deletetime IS NULL
|
||||
* - sort=nearby 时按距离升序(无坐标的信息排最后;请求未带 lat/lng 则回落发布时间倒序);
|
||||
* - 列表项 distance 为 km(一位小数),请求未带坐标 / 信息未定位时为 null。
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function feed()
|
||||
{
|
||||
list($page, $size) = $this->pager();
|
||||
|
||||
$categoryId = (int)$this->input('categoryId', 0);
|
||||
$subCategoryId = (int)$this->input('subCategoryId', 0);
|
||||
$keyword = trim((string)$this->input('keyword', ''));
|
||||
$province = trim((string)$this->input('province', ''));
|
||||
$city = trim((string)$this->input('city', ''));
|
||||
$area = trim((string)$this->input('area', ''));
|
||||
// 服务区域 ID(兼容上一版的 districtId 参数)
|
||||
$areaId = (int)$this->input('areaId', 0);
|
||||
if (!$areaId) {
|
||||
$areaId = (int)$this->input('districtId', 0);
|
||||
}
|
||||
$sort = (string)$this->input('sort', '');
|
||||
// 容错处理:过滤前端小程序可能序列化出的 undefined 与 null 字符串
|
||||
if ($area === 'undefined' || $area === 'null') {
|
||||
|
||||
foreach (['province', 'city', 'area', 'keyword', 'sort'] as $strVar) {
|
||||
if ($$strVar === 'undefined' || $$strVar === 'null') {
|
||||
$$strVar = '';
|
||||
}
|
||||
}
|
||||
if (in_array($province, ['全部', '全国', '不限'], true)) {
|
||||
$province = '';
|
||||
}
|
||||
if (in_array($city, ['全部', '全市', '全州', '不限'], true)) {
|
||||
$city = '';
|
||||
}
|
||||
if (in_array($area, ['全部', '全区', '全城', '全国', '不限'], true)) {
|
||||
$area = '';
|
||||
}
|
||||
if ($keyword === 'undefined' || $keyword === 'null') {
|
||||
$keyword = '';
|
||||
}
|
||||
if ($sort === 'undefined' || $sort === 'null') {
|
||||
$sort = '';
|
||||
}
|
||||
|
||||
$query = Db::name('fc_post')
|
||||
->where('audit_status', 1)
|
||||
->where('status', 1)
|
||||
->whereNull('deletetime');
|
||||
if ($categoryId > 0) {
|
||||
$query->where('category_id', $categoryId);
|
||||
}
|
||||
if ($keyword !== '') {
|
||||
$query->where('title', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
$applyArea = function ($q) use ($area, $areaId) {
|
||||
// 服务区域 = 区县:areaId 优先,兼容旧的 area=区县名称
|
||||
if ($areaId > 0) {
|
||||
$row = Db::name('fc_area')->where('id', $areaId)->find();
|
||||
if ($row) {
|
||||
$q->where(function ($w) use ($row) {
|
||||
$w->where('district_id', (int)$row['id'])->whereOr('area', (string)$row['district']);
|
||||
// 若传入的 categoryId 本身是二级分类(pid > 0),自动作为二级分类匹配
|
||||
$catRow = $categoryId > 0 ? Db::name('fc_category')->where('id', $categoryId)->find() : null;
|
||||
$isSubCatId = $catRow && !empty($catRow['pid']) && (int)$catRow['pid'] > 0;
|
||||
|
||||
$applyCategory = function ($q) use ($categoryId, $subCategoryId, $isSubCatId) {
|
||||
if ($subCategoryId > 0) {
|
||||
$q->where(function ($w) use ($subCategoryId) {
|
||||
$w->where('sub_category_id', $subCategoryId)->whereOr('category_id', $subCategoryId);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if ($categoryId > 0) {
|
||||
if ($isSubCatId) {
|
||||
$q->where(function ($w) use ($categoryId) {
|
||||
$w->where('sub_category_id', $categoryId)->whereOr('category_id', $categoryId);
|
||||
});
|
||||
} else {
|
||||
$q->where('category_id', $categoryId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$applyArea = function ($q) use ($province, $city, $area, $areaId) {
|
||||
if ($areaId > 0) {
|
||||
$natRow = NationalArea::findById($areaId);
|
||||
if (!$natRow) {
|
||||
$natRow = Db::name('fc_area')->where('id', $areaId)->find();
|
||||
}
|
||||
if ($natRow) {
|
||||
$q->where(function ($w) use ($natRow) {
|
||||
$w->where('district_id', (int)$natRow['id'])->whereOr('area', (string)$natRow['district']);
|
||||
});
|
||||
} else {
|
||||
$q->where('district_id', $areaId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ($area !== '') {
|
||||
$q->where('area', $area);
|
||||
return;
|
||||
}
|
||||
if ($city !== '') {
|
||||
$cityDistricts = [];
|
||||
foreach (NationalArea::all() as $item) {
|
||||
if ($item['city'] === $city || rtrim($item['city'], '市') === rtrim($city, '市')) {
|
||||
$cityDistricts[] = $item['district'];
|
||||
}
|
||||
}
|
||||
$q->where(function ($w) use ($city, $cityDistricts) {
|
||||
$w->where('city', $city);
|
||||
if (!empty($cityDistricts)) {
|
||||
$w->whereOr('area', 'in', array_slice(array_unique($cityDistricts), 0, 100));
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if ($province !== '') {
|
||||
$q->where('province', $province);
|
||||
}
|
||||
};
|
||||
$applyArea($query);
|
||||
|
||||
// 付费发帖拦截:未付清款项的帖子(微信支付待付款)严禁向外展示
|
||||
$applyPaid = function ($q) {
|
||||
$q->where(function ($w) {
|
||||
$w->where('amount', 'null')->whereOr('amount', '<=', 0)->whereOr('is_paid', 1);
|
||||
});
|
||||
};
|
||||
|
||||
$query = Db::name('fc_post')
|
||||
->where('audit_status', 1)
|
||||
->where('status', 1)
|
||||
->whereNull('deletetime');
|
||||
$applyCategory($query);
|
||||
if ($keyword !== '') {
|
||||
$query->where('title', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
$applyArea($query);
|
||||
$applyPaid($query);
|
||||
|
||||
$counter = Db::name('fc_post')
|
||||
->where('audit_status', 1)
|
||||
->where('status', 1)
|
||||
->whereNull('deletetime');
|
||||
if ($categoryId > 0) {
|
||||
$counter->where('category_id', $categoryId);
|
||||
}
|
||||
$applyCategory($counter);
|
||||
if ($keyword !== '') {
|
||||
$counter->where('title', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
@@ -244,8 +298,6 @@ class Home extends V1
|
||||
$applyPaid($counter);
|
||||
$total = $counter->count();
|
||||
|
||||
// 「附近」:距离在 PHP 内用 Haversine 计算后排序(不用 SQL 距离函数,避免 MySQL 兼容问题);
|
||||
// 因排序依赖计算结果,这里取全量匹配行排序后再做**内存分页**,保证 page/size/total 一致。
|
||||
if ($sort === 'nearby') {
|
||||
$rows = $query->order('createtime desc')->select();
|
||||
$items = [];
|
||||
@@ -260,12 +312,12 @@ class Home extends V1
|
||||
$na = $a['distance'] === null;
|
||||
$nb = $b['distance'] === null;
|
||||
if ($na !== $nb) {
|
||||
return $na ? 1 : -1; // 无坐标的排最后
|
||||
return $na ? 1 : -1;
|
||||
}
|
||||
if (!$na && $a['distance'] != $b['distance']) {
|
||||
return $a['distance'] < $b['distance'] ? -1 : 1;
|
||||
}
|
||||
return $b['ct'] - $a['ct']; // 距离相同(或都无坐标):新的在前
|
||||
return $b['ct'] - $a['ct'];
|
||||
});
|
||||
$list = [];
|
||||
foreach ($items as $it) {
|
||||
@@ -274,12 +326,13 @@ class Home extends V1
|
||||
$this->ok($this->paginateArray($list, $page, $size));
|
||||
}
|
||||
|
||||
if ($sort === 'price') {
|
||||
if ($sort === 'price_desc') {
|
||||
$query->order('is_top desc, price desc');
|
||||
} elseif ($sort === 'price' || $sort === 'price_asc') {
|
||||
$query->order('is_top desc, price asc');
|
||||
} elseif ($sort === 'hot') {
|
||||
$query->order('is_top desc, views desc');
|
||||
} else {
|
||||
// 后台「置顶」优先展示,其余按发布时间倒序
|
||||
$query->order('is_top desc, createtime desc');
|
||||
}
|
||||
|
||||
@@ -294,7 +347,7 @@ class Home extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* Haversine 距离(km,一位小数)—— 与 Post 控制器同一算法
|
||||
* Haversine 距离(km,一位小数)
|
||||
* @return float
|
||||
*/
|
||||
protected function haversine($lat1, $lng1, $lat2, $lng2)
|
||||
@@ -335,7 +388,7 @@ class Home extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装 Post 结构(与前端 mock 数据字段严格对齐)
|
||||
* 组装 Post 结构(含二级分类与农产品属性)
|
||||
* @param array $row fc_post 行
|
||||
* @return array
|
||||
*/
|
||||
@@ -349,6 +402,15 @@ class Home 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];
|
||||
if (!empty($row['user_id'])) {
|
||||
$pub = Db::name('user')->where('id', $row['user_id'])->find();
|
||||
@@ -376,82 +438,76 @@ class Home extends V1
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int)$row['id'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'categoryName' => $categoryName,
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'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'],
|
||||
'contact' => $this->maskPhone($row['phone']),
|
||||
'views' => (int)$row['views'],
|
||||
'likes' => (int)$row['likes'],
|
||||
'isPaid' => (int)$row['is_paid'] === 1,
|
||||
'isTop' => (int)$row['is_top'] === 1,
|
||||
'auditStatus' => (int)$row['audit_status'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
'tags' => $tags,
|
||||
'publisher' => $publisher,
|
||||
'commentCount' => (int)$row['comment_count'],
|
||||
'distance' => $this->postDistance($row),
|
||||
'id' => (int)$row['id'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'categoryName' => $categoryName,
|
||||
'subCategoryId' => $subCategoryId,
|
||||
'subCategoryName' => $subCategoryName,
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'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'] : '',
|
||||
'contact' => $this->maskPhone($row['phone']),
|
||||
'views' => (int)$row['views'],
|
||||
'likes' => (int)$row['likes'],
|
||||
'isPaid' => (int)$row['is_paid'] === 1,
|
||||
'isTop' => (int)$row['is_top'] === 1,
|
||||
'auditStatus' => (int)$row['audit_status'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
'tags' => $tags,
|
||||
'publisher' => $publisher,
|
||||
'commentCount' => (int)$row['comment_count'],
|
||||
'distance' => $this->postDistance($row),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 全兼容分类图标路径解析
|
||||
* 规则:网络URL或相对路径直接透传;支持根据 iconKey 或 分类 ID 智能映射内置图标;默认回落 cat-job.png 兜底
|
||||
* @param int $id 分类ID
|
||||
* 全兼容分类图标/实拍图路径解析
|
||||
* @param int $id 分类ID
|
||||
* @param string $iconKey 分类图标键名或图片路径
|
||||
* @param string $image 分类实拍图路径
|
||||
* @return string
|
||||
*/
|
||||
protected function resolveCategoryIconPath($id, $iconKey = '')
|
||||
protected function resolveCategoryIconPath($id, $iconKey = '', $image = '')
|
||||
{
|
||||
if ($image !== '' && preg_match('/^https?:\/\/|^\/uploads\/|^\/static\//i', $image)) {
|
||||
return $image;
|
||||
}
|
||||
if ($iconKey !== '') {
|
||||
if (preg_match('/^https?:\/\/|^\/uploads\/|^\/static\//i', $iconKey)) {
|
||||
return $iconKey;
|
||||
}
|
||||
$iconFileName = (strpos($iconKey, '.') !== false) ? $iconKey : $iconKey . '.png';
|
||||
if (file_exists(ROOT_PATH . 'public/static/categories/' . $iconFileName)) {
|
||||
return '/static/categories/' . $iconFileName;
|
||||
}
|
||||
if (file_exists(ROOT_PATH . 'public/static/icons/' . $iconFileName)) {
|
||||
return '/static/icons/' . $iconFileName;
|
||||
}
|
||||
$keyMap = [
|
||||
'cat-job' => 'cat-job.png',
|
||||
'cat-house' => 'cat-house.png',
|
||||
'cat-goods' => 'cat-goods.png',
|
||||
'cat-car' => 'cat-car.png',
|
||||
'cat-service' => 'cat-service.png',
|
||||
'cat-education' => 'cat-education.png',
|
||||
'cat-clean' => 'cat-clean.png',
|
||||
'cat-friend' => 'cat-friend.png',
|
||||
];
|
||||
if (isset($keyMap[$iconKey])) {
|
||||
return '/static/icons/' . $keyMap[$iconKey];
|
||||
}
|
||||
}
|
||||
return '/static/icons/' . $this->iconFile($id);
|
||||
return '/static/categories/' . $this->iconFile($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类 id → 固定图标文件名(向下兼容)
|
||||
* 分类 id → 默认图标文件名
|
||||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
protected function iconFile($id)
|
||||
{
|
||||
$map = [
|
||||
1 => 'cat-job.png',
|
||||
2 => 'cat-house.png',
|
||||
3 => 'cat-goods.png',
|
||||
4 => 'cat-car.png',
|
||||
5 => 'cat-service.png',
|
||||
6 => 'cat-education.png',
|
||||
7 => 'cat-clean.png',
|
||||
8 => 'cat-friend.png',
|
||||
1 => 'cat-veg.png',
|
||||
2 => 'cat-fruit.png',
|
||||
];
|
||||
return isset($map[$id]) ? $map[$id] : 'cat-job.png';
|
||||
return isset($map[$id]) ? $map[$id] : 'cat-veg.png';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class Setting extends V1
|
||||
|
||||
/**
|
||||
* 获取协议与隐私政策内容(游客可用)
|
||||
* GET /api/v1/setting/agreement?type=service|privacy
|
||||
* GET /api/v1/setting/agreement?type=service|privacy|disclaimer
|
||||
* 出参:{ title, content, updateTime }
|
||||
*/
|
||||
public function agreement()
|
||||
@@ -63,6 +63,10 @@ class Setting extends V1
|
||||
$title = '隐私政策';
|
||||
$defaultContent = "【隐私政策】\n\n同城分类信息便民平台重视用户的隐私与个人信息保护。我们承诺将按照法律法规要求,采取相应的安全保护措施保护您的个人信息。\n\n1. 信息收集与使用:我们仅收集为您提供服务所必需的信息,如登录手机号、发布信息时提供的联系方式与内容。\n2. 信息安全保障:我们采用业界标准的安全防护措施,保护用户个人信息不被未经授权的访问、泄露、篡改或损毁。\n3. 权限说明:仅在您主动上传图片、定位实体门店时,请求相册及地理位置权限。\n4. 未成年人保护:如您为未成年人,建议在父母或监护人指导下使用本服务。";
|
||||
$content = (string)$this->cfg('site.privacyPolicy', $defaultContent);
|
||||
} elseif ($type === 'disclaimer') {
|
||||
$title = '平台免责声明';
|
||||
$defaultContent = "【平台免责声明】\n\n1. 信息媒介属性:本平台仅为农产品及本地生活信息展示与联络媒介,不参与任何线下交易,不对信息真实性、合法性作出担保。\n2. 交易风险自担:请自行鉴别信息真伪,在未核实清楚前不要提前给对方转账,谨防诈骗。因私下交易产生的纠纷与损失,由交易双方依法依规自行处理。\n3. 联系方式保护:为保护用户隐私,平台对联系电话进行脱敏展示,拨打记录仅用于限制每日恶意拨打行为。\n4. 举报与处置:如发现虚假、违法违规信息,请及时通过页面「举报」入口反馈,平台将核实后采取下架、封禁等措施。";
|
||||
$content = (string)$this->cfg('site.disclaimer', $defaultContent);
|
||||
} else {
|
||||
$title = '用户服务协议';
|
||||
$defaultContent = "【用户服务协议】\n\n欢迎使用同城分类信息生活便民平台。在使用本平台服务前,请仔细阅读本协议。\n\n1. 服务条款确认与接纳:用户在注册或使用本平台服务即视为完全理解并同意本协议全部条款。\n2. 用户发布行为规范:用户承诺发布的信息真实、合法、有效,严禁发布违法、虚假、侵权或违背公序良俗的商业与便民信息。\n3. 平台免责声明:平台作为同城信息展示与撮合媒介,用户应自主辨识交易风险,因私下线下交易产生的纠纷由当事人依法依规处理。\n4. 违规处罚机制:对发布违法违规、虚假诈骗内容的用户,平台有权采取警告、下架信息、限制发布乃至封禁账号的处置措施。";
|
||||
|
||||
在新工单中引用
屏蔽一个用户