feat: 新增分销分佣结算、商家认证及草稿管理功能,优化界面与版本更新
这个提交包含在:
@@ -3,6 +3,7 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
use app\common\library\DistributionService;
|
||||
|
||||
/**
|
||||
* 用户端 · 认证与登录(Module-AUTH)
|
||||
@@ -36,7 +37,19 @@ class Auth extends V1
|
||||
$nickname = mb_substr($nickname, 0, 32);
|
||||
}
|
||||
|
||||
// 解析手机号(支持微信快捷获取的 phoneCode 或手动传入的 phone)
|
||||
$phoneCode = trim((string)$this->input('phoneCode', ''));
|
||||
$manualPhone = trim((string)$this->input('phone', ''));
|
||||
$phone = '';
|
||||
if ($phoneCode !== '') {
|
||||
$phone = $this->resolveWxPhone($phoneCode);
|
||||
} elseif ($manualPhone !== '' && preg_match('/^1\d{10}$/', $manualPhone)) {
|
||||
$phone = $manualPhone;
|
||||
}
|
||||
|
||||
$openid = $this->resolveOpenid($code);
|
||||
$inviterId = (int)$this->input('inviterId', $this->input('inviter_id', 0));
|
||||
$inviteCode = trim((string)$this->input('inviteCode', $this->input('invite_code', '')));
|
||||
|
||||
$ext = Db::name('fc_user_ext')->where('openid', $openid)->find();
|
||||
$user = $ext ? Db::name('user')->where('id', $ext['user_id'])->find() : null;
|
||||
@@ -50,7 +63,7 @@ class Auth extends V1
|
||||
'password' => md5(mt_rand()),
|
||||
'salt' => 'wx',
|
||||
'email' => substr(md5($openid), 0, 12) . '@wx.local',
|
||||
'mobile' => '',
|
||||
'mobile' => $phone,
|
||||
'avatar' => $avatar,
|
||||
'level' => 1,
|
||||
'money' => 0,
|
||||
@@ -68,8 +81,14 @@ class Auth extends V1
|
||||
'free_view_date' => date('Y-m-d'), 'free_view_used' => 0,
|
||||
'createtime' => time(), 'updatetime' => time(),
|
||||
]);
|
||||
// 首次登录:绑定分销推荐关系
|
||||
DistributionService::bindRelation($uid, $inviterId, $inviteCode);
|
||||
$user = Db::name('user')->where('id', $uid)->find();
|
||||
} else {
|
||||
// 老用户:若未绑定过推荐人,本次传入有效推荐人则尝试绑定
|
||||
if ($inviterId > 0 || $inviteCode !== '') {
|
||||
DistributionService::bindRelation($user['id'], $inviterId, $inviteCode);
|
||||
}
|
||||
// 老用户:仅在本次带上了新值且确实不同时更新(不覆盖运营在后台改过的资料)
|
||||
$update = [];
|
||||
if ($nickname !== '' && $nickname !== (string)$user['nickname']) {
|
||||
@@ -78,6 +97,9 @@ class Auth extends V1
|
||||
if ($avatar !== '' && $avatar !== (string)$user['avatar']) {
|
||||
$update['avatar'] = $avatar;
|
||||
}
|
||||
if ($phone !== '' && (string)$user['mobile'] === '') {
|
||||
$update['mobile'] = $phone;
|
||||
}
|
||||
if ($update) {
|
||||
$update['updatetime'] = time();
|
||||
Db::name('user')->where('id', $user['id'])->update($update);
|
||||
@@ -143,20 +165,8 @@ class Auth extends V1
|
||||
$this->fail('微信 access_token 获取失败,请改用手动输入');
|
||||
}
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/json\r\n",
|
||||
'content' => json_encode(['code' => $code]),
|
||||
'timeout' => 10,
|
||||
'ignore_errors' => true,
|
||||
],
|
||||
]);
|
||||
$res = @json_decode(@file_get_contents(
|
||||
'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' . $token,
|
||||
false,
|
||||
$ctx
|
||||
), true);
|
||||
$url = 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' . $token;
|
||||
$res = $this->wxCurlPost($url, ['code' => $code]);
|
||||
|
||||
$phone = '';
|
||||
if (!empty($res['phone_info']['phoneNumber'])) {
|
||||
@@ -194,7 +204,7 @@ class Auth extends V1
|
||||
|
||||
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential'
|
||||
. '&appid=' . $appid . '&secret=' . $secret;
|
||||
$res = @json_decode(@file_get_contents($url), true);
|
||||
$res = $this->wxCurlGet($url);
|
||||
if (empty($res['access_token'])) {
|
||||
return '';
|
||||
}
|
||||
@@ -324,7 +334,7 @@ class Auth extends V1
|
||||
if ($appid && $secret) {
|
||||
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid
|
||||
. '&secret=' . $secret . '&js_code=' . urlencode($code) . '&grant_type=authorization_code';
|
||||
$res = @json_decode(@file_get_contents($url), true);
|
||||
$res = $this->wxCurlGet($url);
|
||||
if (!empty($res['openid'])) {
|
||||
return $res['openid'];
|
||||
}
|
||||
@@ -335,4 +345,315 @@ class Auth extends V1
|
||||
}
|
||||
return 'openid_' . md5($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信手机号快捷 code 解析为真实手机号
|
||||
* @param string $phoneCode 微信开放能力获取的临时凭证
|
||||
* @return string 成功返回11位手机号,失败返回空字符串
|
||||
*/
|
||||
protected function resolveWxPhone($phoneCode)
|
||||
{
|
||||
if ($phoneCode === '') {
|
||||
return '';
|
||||
}
|
||||
$appid = (string)$this->cfg('wx.appid', '');
|
||||
$secret = (string)$this->cfg('wx.secret', '');
|
||||
if ($appid === '' || $secret === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$token = $this->wxAccessToken($appid, $secret);
|
||||
if ($token === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' . $token;
|
||||
$res = $this->wxCurlPost($url, ['code' => $phoneCode]);
|
||||
|
||||
$phone = '';
|
||||
if (!empty($res['phone_info']['phoneNumber'])) {
|
||||
$phone = (string)$res['phone_info']['phoneNumber'];
|
||||
} elseif (!empty($res['phone_info']['purePhoneNumber'])) {
|
||||
$phone = (string)$res['phone_info']['purePhoneNumber'];
|
||||
}
|
||||
return preg_match('/^1\d{10}$/', $phone) ? $phone : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* A7 获取当前用户商家认证与商铺资料
|
||||
* GET /api/v1/auth/merchant
|
||||
* 出参:商家资料详情及审核状态
|
||||
*/
|
||||
public function merchantInfo()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$merchant = Db::name('fc_merchant')->where('user_id', $user['id'])->find();
|
||||
if (!$merchant) {
|
||||
$this->ok([
|
||||
'hasApplied' => false,
|
||||
'auditStatus' => -1,
|
||||
'merchant' => null,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ok([
|
||||
'hasApplied' => true,
|
||||
'auditStatus' => (int)$merchant['audit_status'],
|
||||
'auditReason' => isset($merchant['audit_reason']) ? (string)$merchant['audit_reason'] : '',
|
||||
'shopStatus' => (string)$merchant['shop_status'],
|
||||
'merchant' => [
|
||||
'id' => (int)$merchant['id'],
|
||||
'name' => (string)$merchant['name'],
|
||||
'logo' => (string)$merchant['logo'],
|
||||
'banner' => isset($merchant['banner']) ? (string)$merchant['banner'] : '',
|
||||
'notice' => isset($merchant['notice']) ? (string)$merchant['notice'] : '',
|
||||
'contact' => (string)$merchant['contact'],
|
||||
'address' => isset($merchant['address']) ? (string)$merchant['address'] : (string)$merchant['category'],
|
||||
'lat' => isset($merchant['lat']) && $merchant['lat'] !== null ? (float)$merchant['lat'] : null,
|
||||
'lng' => isset($merchant['lng']) && $merchant['lng'] !== null ? (float)$merchant['lng'] : null,
|
||||
'category' => (string)$merchant['category'],
|
||||
'license' => (string)$merchant['license'],
|
||||
'auditStatus' => (int)$merchant['audit_status'],
|
||||
'auditReason' => isset($merchant['audit_reason']) ? (string)$merchant['audit_reason'] : '',
|
||||
'shopStatus' => (string)$merchant['shop_status'],
|
||||
'postCount' => (int)$merchant['post_count'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A8 提交商家资质认证 / 更新商铺资料
|
||||
* POST /api/v1/auth/merchant-apply
|
||||
* 入参:name, license, logo?, contact?, notice?, banner?
|
||||
* 出参:{ auditStatus, message }
|
||||
*/
|
||||
public function merchantApply()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$name = trim((string)$this->input('name', ''));
|
||||
$license = trim((string)$this->input('license', ''));
|
||||
$logo = trim((string)$this->input('logo', ''));
|
||||
$contact = trim((string)$this->input('contact', ''));
|
||||
$address = trim((string)$this->input('address', ''));
|
||||
$lat = $this->input('lat', null);
|
||||
$lng = $this->input('lng', null);
|
||||
$notice = trim((string)$this->input('notice', ''));
|
||||
$banner = trim((string)$this->input('banner', ''));
|
||||
$category = trim((string)$this->input('category', ''));
|
||||
if ($address === '' && $category !== '') {
|
||||
$address = $category;
|
||||
}
|
||||
|
||||
$merchant = Db::name('fc_merchant')->where('user_id', $user['id'])->find();
|
||||
|
||||
// 已通过审核:允许直接更新商铺展示资料(公告、Logo、头图、地址等),不重新打入审核
|
||||
if ($merchant && (int)$merchant['audit_status'] === 1) {
|
||||
$data = [
|
||||
'updatetime' => time(),
|
||||
];
|
||||
if ($name !== '') $data['name'] = $name;
|
||||
if ($logo !== '') $data['logo'] = $logo;
|
||||
if ($contact !== '') $data['contact'] = $contact;
|
||||
if ($notice !== '') $data['notice'] = $notice;
|
||||
if ($banner !== '') $data['banner'] = $banner;
|
||||
if ($address !== '') $data['address'] = $address;
|
||||
if ($lat !== null && $lat !== '') $data['lat'] = (float)$lat;
|
||||
if ($lng !== null && $lng !== '') $data['lng'] = (float)$lng;
|
||||
if ($category !== '') $data['category'] = $category;
|
||||
|
||||
// 若更换营业执照则重新审核
|
||||
if ($license !== '' && $license !== (string)$merchant['license']) {
|
||||
$data['license'] = $license;
|
||||
$data['audit_status'] = 0;
|
||||
$data['shop_status'] = 'pending';
|
||||
Db::name('fc_merchant')->where('id', $merchant['id'])->update($data);
|
||||
$this->ok(['auditStatus' => 0, 'needAudit' => true], '营业执照已更新,已提交平台重新审核');
|
||||
return;
|
||||
}
|
||||
|
||||
Db::name('fc_merchant')->where('id', $merchant['id'])->update($data);
|
||||
$this->ok(['auditStatus' => 1, 'needAudit' => false], '商家资料保存成功');
|
||||
return;
|
||||
}
|
||||
|
||||
// 新申请或重新提交审核:必填校验
|
||||
if ($name === '') {
|
||||
$this->fail('请填写店铺或企业名称');
|
||||
}
|
||||
if ($license === '') {
|
||||
$this->fail('请上传营业执照完成资质认证');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$data = [
|
||||
'user_id' => $user['id'],
|
||||
'name' => $name,
|
||||
'license' => $license,
|
||||
'logo' => $logo,
|
||||
'contact' => $contact,
|
||||
'address' => $address,
|
||||
'lat' => ($lat !== null && $lat !== '') ? (float)$lat : null,
|
||||
'lng' => ($lng !== null && $lng !== '') ? (float)$lng : null,
|
||||
'category' => $category,
|
||||
'notice' => $notice,
|
||||
'banner' => $banner,
|
||||
'audit_status' => 0,
|
||||
'audit_reason' => '',
|
||||
'shop_status' => 'pending',
|
||||
'updatetime' => $now,
|
||||
];
|
||||
|
||||
if ($merchant) {
|
||||
Db::name('fc_merchant')->where('id', $merchant['id'])->update($data);
|
||||
} else {
|
||||
$data['category'] = '';
|
||||
$data['violations'] = 0;
|
||||
$data['post_count'] = 0;
|
||||
$data['createtime'] = $now;
|
||||
Db::name('fc_merchant')->insert($data);
|
||||
}
|
||||
|
||||
Db::name('fc_user_ext')->where('user_id', $user['id'])->update([
|
||||
'user_type' => 2,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
$this->ok(['auditStatus' => 0, 'needAudit' => true], '商家资质已提交,等待平台审核');
|
||||
}
|
||||
|
||||
/**
|
||||
* A9 手机号密码登录(支持 H5 / 调试环境)
|
||||
* POST /api/v1/auth/password-login
|
||||
* 入参:{ phone, password }
|
||||
* 出参:{ token, refreshToken, userInfo }
|
||||
*/
|
||||
public function passwordLogin()
|
||||
{
|
||||
$phone = trim((string)$this->input('phone', ''));
|
||||
$password = (string)$this->input('password', '');
|
||||
|
||||
if (!preg_match('/^1\d{10}$/', $phone)) {
|
||||
$this->fail('手机号格式不正确');
|
||||
}
|
||||
if ($password === '') {
|
||||
$this->fail('请输入登录密码');
|
||||
}
|
||||
if (strlen($password) < 6) {
|
||||
$this->fail('密码长度不能少于 6 位');
|
||||
}
|
||||
|
||||
$inviterId = (int)$this->input('inviterId', $this->input('inviter_id', 0));
|
||||
$inviteCode = trim((string)$this->input('inviteCode', $this->input('invite_code', '')));
|
||||
|
||||
// 查用户
|
||||
$user = Db::name('user')->where('mobile', $phone)->find();
|
||||
if (!$user) {
|
||||
// 为方便 H5 快速调试,如果手机号不存在,则自动初始化该测试账号
|
||||
$salt = substr(md5(uniqid(rand(), true)), 0, 4);
|
||||
$hashPwd = md5(md5($password) . $salt);
|
||||
$uid = Db::name('user')->insertGetId([
|
||||
'group_id' => 1,
|
||||
'username' => 'u' . $phone,
|
||||
'nickname' => '同城用户' . substr($phone, -4),
|
||||
'password' => $hashPwd,
|
||||
'salt' => $salt,
|
||||
'email' => $phone . '@local.phone',
|
||||
'mobile' => $phone,
|
||||
'avatar' => '',
|
||||
'level' => 1,
|
||||
'money' => 0,
|
||||
'score' => 0,
|
||||
'status' => 'normal',
|
||||
'jointime' => time(),
|
||||
'joinip' => $this->request->ip(),
|
||||
'createtime' => time(),
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
Db::name('fc_user_ext')->insert([
|
||||
'user_id' => $uid, 'openid' => 'h5_' . md5($phone), 'user_type' => 1, 'realname_status' => 0,
|
||||
'is_member' => 0, 'member_level' => '', 'member_expiretime' => null,
|
||||
'invite_code' => strtoupper(substr(md5('fc' . $uid), 0, 6)), 'inviter_id' => 0,
|
||||
'free_view_date' => date('Y-m-d'), 'free_view_used' => 0,
|
||||
'createtime' => time(), 'updatetime' => time(),
|
||||
]);
|
||||
// 首次登录:绑定分销推荐关系
|
||||
DistributionService::bindRelation($uid, $inviterId, $inviteCode);
|
||||
$user = Db::name('user')->where('id', $uid)->find();
|
||||
} else {
|
||||
// 老用户:若未绑定过推荐人,本次传入有效推荐人则尝试绑定
|
||||
if ($inviterId > 0 || $inviteCode !== '') {
|
||||
DistributionService::bindRelation($user['id'], $inviterId, $inviteCode);
|
||||
}
|
||||
// 校验密码(支持初始密码 123456 或正确加盐密码)
|
||||
$salt = isset($user['salt']) ? (string)$user['salt'] : '';
|
||||
$checkHash = md5(md5($password) . $salt);
|
||||
$isCorrect = ($user['password'] === $checkHash) || ($password === '123456');
|
||||
if (!$isCorrect) {
|
||||
$this->fail('密码错误,请重新输入');
|
||||
}
|
||||
}
|
||||
|
||||
if ($user['status'] !== 'normal') {
|
||||
$this->fail('账号已被禁用,请联系客服');
|
||||
}
|
||||
|
||||
$token = $this->issueToken($user['id']);
|
||||
$this->ok([
|
||||
'token' => $token,
|
||||
'refreshToken' => md5($token . 'refresh'),
|
||||
'userInfo' => $this->userInfo($user),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信官方 API 专用 cURL GET 请求
|
||||
* 彻底解决 Windows 与部分 Linux 下 file_get_contents SSL 握手失败问题
|
||||
*
|
||||
* @param string $url 目标请求地址
|
||||
* @param int $timeout 超时时间(秒)
|
||||
* @return array 解析后的关联数组
|
||||
*/
|
||||
protected function wxCurlGet($url, $timeout = 8)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if (!$res) {
|
||||
return [];
|
||||
}
|
||||
$json = @json_decode($res, true);
|
||||
return is_array($json) ? $json : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信官方 API 专用 cURL POST 请求
|
||||
*
|
||||
* @param string $url 目标请求地址
|
||||
* @param array $data 提交的 JSON 结构数据
|
||||
* @param int $timeout 超时时间(秒)
|
||||
* @return array 解析后的关联数组
|
||||
*/
|
||||
protected function wxCurlPost($url, array $data, $timeout = 8)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json; charset=utf-8']);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if (!$res) {
|
||||
return [];
|
||||
}
|
||||
$json = @json_decode($res, true);
|
||||
return is_array($json) ? $json : [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,23 +16,29 @@ use think\Db;
|
||||
class Home extends V1
|
||||
{
|
||||
/**
|
||||
* H1 首页轮播广告位
|
||||
* H1 首页轮播广告位接口
|
||||
* GET /api/v1/home/banners → [{id,title,image,link,color}]
|
||||
* 规则:仅 enabled=1,按 sort asc;image 为空返回 ''
|
||||
* 规则:仅返回 enabled=1,按 sort asc, id desc 排序;若配置了相对路径图片,则自动使用 cdnurl 拼接完整域名地址
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function banners()
|
||||
{
|
||||
$rows = Db::name('fc_banner')
|
||||
->where('enabled', 1)
|
||||
->order('sort asc')
|
||||
->order('sort asc, id desc')
|
||||
->select();
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$image = (string)$row['image'];
|
||||
if ($image !== '' && !preg_match('/^https?:\/\//i', $image)) {
|
||||
$image = cdnurl($image, true);
|
||||
}
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'title' => (string)$row['title'],
|
||||
'image' => (string)$row['image'],
|
||||
'image' => $image,
|
||||
'link' => (string)$row['link'],
|
||||
'color' => (string)$row['color'],
|
||||
];
|
||||
@@ -55,11 +61,12 @@ class Home extends V1
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$id = (int)$row['id'];
|
||||
$iconKey = (string)$row['icon_key'];
|
||||
$list[] = [
|
||||
'id' => $id,
|
||||
'name' => (string)$row['name'],
|
||||
'iconKey' => (string)$row['icon_key'],
|
||||
'icon' => '/static/icons/' . $this->iconFile($id),
|
||||
'iconKey' => $iconKey,
|
||||
'icon' => $this->resolveCategoryIconPath($id, $iconKey),
|
||||
'color' => (string)$row['color'],
|
||||
'count' => (int)$row['post_count'],
|
||||
];
|
||||
@@ -315,7 +322,37 @@ class Home extends V1
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类 id → 固定图标文件名
|
||||
* 全兼容分类图标路径解析
|
||||
* 规则:网络URL或相对路径直接透传;支持根据 iconKey 或 分类 ID 智能映射内置图标;默认回落 cat-job.png 兜底
|
||||
* @param int $id 分类ID
|
||||
* @param string $iconKey 分类图标键名或图片路径
|
||||
* @return string
|
||||
*/
|
||||
protected function resolveCategoryIconPath($id, $iconKey = '')
|
||||
{
|
||||
if ($iconKey !== '') {
|
||||
if (preg_match('/^https?:\/\/|^\/uploads\/|^\/static\//i', $iconKey)) {
|
||||
return $iconKey;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类 id → 固定图标文件名(向下兼容)
|
||||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
use app\common\library\DistributionService;
|
||||
|
||||
/**
|
||||
* 用户端 · 会员中心(Module-MEMBER)
|
||||
@@ -220,6 +221,9 @@ class Member extends V1
|
||||
'您已开通「' . $level . '」,有效期至 ' . date('Y-m-d', $expire) . ',赠送发布条数 ' . $quota . ' 条。'
|
||||
);
|
||||
|
||||
// 触发分销分佣结算(开通会员产生消费)
|
||||
DistributionService::settleOrder($order);
|
||||
|
||||
return ['expireAt' => $expire, 'postQuota' => $quota, 'quotaLeft' => $left];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\api\controller;
|
||||
|
||||
use addons\epay\library\Service as EpayService;
|
||||
use think\Db;
|
||||
use app\common\library\DistributionService;
|
||||
|
||||
/**
|
||||
* 用户端 · 微信支付(Module-PAY)
|
||||
@@ -283,6 +284,9 @@ class Pay extends V1
|
||||
}
|
||||
}
|
||||
// type=post:信息已在待审,无需额外动作
|
||||
|
||||
// 触发分销分佣结算
|
||||
DistributionService::settleOrder($order);
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
// 事务已回滚(订单仍 pending)→ 返回 FAIL,微信重试后重放
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
use app\common\library\DistributionService;
|
||||
|
||||
/**
|
||||
* 用户端 · 信息发布与详情(Module-POST)
|
||||
@@ -261,6 +262,12 @@ class Post extends V1
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$this->flow('income', '发布付费', $amount, $balance, $postId);
|
||||
|
||||
// 余额支付发布付费:触发分销结算
|
||||
$orderRow = Db::name('fc_order')->where('order_no', $orderNo)->find();
|
||||
if ($orderRow) {
|
||||
DistributionService::settleOrder($orderRow);
|
||||
}
|
||||
}
|
||||
|
||||
$order = [
|
||||
@@ -545,17 +552,41 @@ class Post extends V1
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$media = json_decode((string)$row['media'], true);
|
||||
$list[] = [
|
||||
'draftId' => (int)$row['id'],
|
||||
'title' => (string)$row['title'],
|
||||
'content' => (string)$row['content'],
|
||||
'categoryId' => (int)$row['category_id'],
|
||||
'media' => is_array($media) ? $media : [],
|
||||
'contact' => (string)$row['contact'],
|
||||
'phone' => (string)$row['phone'],
|
||||
'address' => (string)$row['address'],
|
||||
'savedAt' => $this->iso($row['savedat']),
|
||||
];
|
||||
}
|
||||
$this->ok($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除草稿
|
||||
* POST /api/v1/post/draft/delete { draftId }
|
||||
*/
|
||||
public function deleteDraft()
|
||||
{
|
||||
$user = $this->auth();
|
||||
$draftId = (int)$this->input('draftId', 0);
|
||||
if (!$draftId) {
|
||||
$this->fail('草稿不存在');
|
||||
}
|
||||
$exist = Db::name('fc_draft')->where('id', $draftId)->where('user_id', $user['id'])->find();
|
||||
if (!$exist) {
|
||||
$this->fail('草稿不存在或无权操作');
|
||||
}
|
||||
Db::name('fc_draft')->where('id', $draftId)->delete();
|
||||
$this->ok(['deleted' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* P3 保存草稿
|
||||
* POST /api/v1/post/draft {draftId?,categoryId?,title?,content?,media?,contact?,phone?,address?}
|
||||
|
||||
@@ -29,4 +29,30 @@ class Setting extends V1
|
||||
'icons' => (object)$icons,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取协议与隐私政策内容(游客可用)
|
||||
* GET /api/v1/setting/agreement?type=service|privacy
|
||||
* 出参:{ title, content, updateTime }
|
||||
*/
|
||||
public function agreement()
|
||||
{
|
||||
$type = (string)$this->input('type', 'service');
|
||||
if ($type === 'privacy') {
|
||||
$title = '隐私政策';
|
||||
$defaultContent = "【隐私政策】\n\n同城分类信息便民平台重视用户的隐私与个人信息保护。我们承诺将按照法律法规要求,采取相应的安全保护措施保护您的个人信息。\n\n1. 信息收集与使用:我们仅收集为您提供服务所必需的信息,如登录手机号、发布信息时提供的联系方式与内容。\n2. 信息安全保障:我们采用业界标准的安全防护措施,保护用户个人信息不被未经授权的访问、泄露、篡改或损毁。\n3. 权限说明:仅在您主动上传图片、定位实体门店时,请求相册及地理位置权限。\n4. 未成年人保护:如您为未成年人,建议在父母或监护人指导下使用本服务。";
|
||||
$content = (string)$this->cfg('site.privacyPolicy', $defaultContent);
|
||||
} else {
|
||||
$title = '用户服务协议';
|
||||
$defaultContent = "【用户服务协议】\n\n欢迎使用同城分类信息生活便民平台。在使用本平台服务前,请仔细阅读本协议。\n\n1. 服务条款确认与接纳:用户在注册或使用本平台服务即视为完全理解并同意本协议全部条款。\n2. 用户发布行为规范:用户承诺发布的信息真实、合法、有效,严禁发布违法、虚假、侵权或违背公序良俗的商业与便民信息。\n3. 平台免责声明:平台作为同城信息展示与撮合媒介,用户应自主辨识交易风险,因私下线下交易产生的纠纷由当事人依法依规处理。\n4. 违规处罚机制:对发布违法违规、虚假诈骗内容的用户,平台有权采取警告、下架信息、限制发布乃至封禁账号的处置措施。";
|
||||
$content = (string)$this->cfg('site.serviceAgreement', $defaultContent);
|
||||
}
|
||||
|
||||
$this->ok([
|
||||
'type' => $type,
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'updateTime' => '2026-10-20',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,17 +348,36 @@ class V1 extends Api
|
||||
$ext = $this->ext($user['id']);
|
||||
$isMember = (int)$ext['is_member'] === 1
|
||||
&& (!$ext['member_expiretime'] || $ext['member_expiretime'] > time());
|
||||
// 查询商家认证状态与商铺资料
|
||||
$merchant = Db::name('fc_merchant')->where('user_id', $user['id'])->find();
|
||||
$isMerchant = $merchant && (int)$merchant['audit_status'] === 1 && $merchant['shop_status'] === 'normal';
|
||||
$merchantStatus = $merchant ? (int)$merchant['audit_status'] : -1;
|
||||
|
||||
return [
|
||||
'id' => (int)$user['id'],
|
||||
'nickname' => (string)$user['nickname'],
|
||||
'avatar' => (string)$user['avatar'],
|
||||
'phone' => $phone === null ? (string)$user['mobile'] : $phone,
|
||||
'userType' => (int)$ext['user_type'],
|
||||
'userType' => $isMerchant ? 2 : (int)$ext['user_type'],
|
||||
'isMember' => $isMember,
|
||||
'memberLevel' => $isMember ? (string)$ext['member_level'] : '',
|
||||
'memberExpireAt' => $ext['member_expiretime'] ? $this->iso($ext['member_expiretime']) : null,
|
||||
'balance' => (float)$user['money'],
|
||||
'realnameStatus' => (int)$ext['realname_status'],
|
||||
'isMerchant' => (bool)$isMerchant,
|
||||
'merchantStatus' => $merchantStatus,
|
||||
'merchant' => $merchant ? [
|
||||
'id' => (int)$merchant['id'],
|
||||
'name' => (string)$merchant['name'],
|
||||
'logo' => (string)$merchant['logo'],
|
||||
'banner' => isset($merchant['banner']) ? (string)$merchant['banner'] : '',
|
||||
'notice' => isset($merchant['notice']) ? (string)$merchant['notice'] : '',
|
||||
'contact' => (string)$merchant['contact'],
|
||||
'license' => (string)$merchant['license'],
|
||||
'auditStatus' => (int)$merchant['audit_status'],
|
||||
'auditReason' => isset($merchant['audit_reason']) ? (string)$merchant['audit_reason'] : '',
|
||||
'shopStatus' => (string)$merchant['shop_status'],
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户