- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
110 行
3.9 KiB
PHP
110 行
3.9 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Db;
|
||
|
||
/**
|
||
* 后台管理端 · 商家管理(Module-ADM-MERCHANT)
|
||
* 路由:
|
||
* GET /api/v1/admin/merchants AM1 商家列表
|
||
* POST /api/v1/admin/merchant/:id/audit AM2 商家资质审核
|
||
*/
|
||
class AdminMerchant extends V1
|
||
{
|
||
/** 管理端接口必须校验管理员身份(V1 默认关闭了 URI 权限校验) */
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->adminOnly();
|
||
}
|
||
|
||
/**
|
||
* AM1 商家列表
|
||
* GET /api/v1/admin/merchants 入参 {status?,keyword?,page,size}
|
||
* → 分页 {list:[{id,name,logo,contact,category,auditStatus,license,shopStatus,violations,postCount,createdAt}],page,size,total,hasMore}
|
||
* 注意:id 返回 fc_merchant.user_id(与前端商家列表一致)
|
||
*/
|
||
public function index()
|
||
{
|
||
$status = $this->input('status', '');
|
||
$keyword = trim((string)$this->input('keyword', ''));
|
||
|
||
// 闭包重建查询:TP5.0 的 count() 会清空 Query::options,不能复用同一对象
|
||
list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($status, $keyword) {
|
||
$q = Db::name('fc_merchant');
|
||
if ($status !== '' && $status !== null) {
|
||
$q->where('audit_status', (int)$status);
|
||
}
|
||
if ($keyword !== '') {
|
||
$q->where('name', 'like', '%' . $keyword . '%');
|
||
}
|
||
if ($forCount) {
|
||
return $q;
|
||
}
|
||
return $q->order('id desc');
|
||
});
|
||
|
||
$list = [];
|
||
foreach ($rows as $row) {
|
||
$list[] = [
|
||
'id' => (int)$row['user_id'],
|
||
'name' => (string)$row['name'],
|
||
'logo' => (string)$row['logo'],
|
||
'contact' => (string)$row['contact'],
|
||
'category' => (string)$row['category'],
|
||
'auditStatus' => (int)$row['audit_status'],
|
||
'license' => (string)$row['license'],
|
||
'shopStatus' => (string)$row['shop_status'],
|
||
'violations' => (int)$row['violations'],
|
||
'postCount' => (int)$row['post_count'],
|
||
'createdAt' => $this->iso($row['createtime']),
|
||
];
|
||
}
|
||
|
||
$this->ok($this->paginate($list, $total, $page, $size));
|
||
}
|
||
|
||
/**
|
||
* AM2 商家资质审核
|
||
* POST /api/v1/admin/merchant/:id/audit 入参 {auditStatus,reason?} → {id,auditStatus}
|
||
* 规则 BR-11:auditStatus 仅允许 1(通过)/2(驳回)
|
||
*/
|
||
public function audit()
|
||
{
|
||
$id = (int)$this->request->param('id', 0);
|
||
$auditStatus = (int)$this->input('auditStatus', 0);
|
||
$reason = trim((string)$this->input('reason', ''));
|
||
|
||
if (!in_array($auditStatus, [1, 2], true)) {
|
||
$this->fail('审核状态仅支持通过(1)/驳回(2)');
|
||
}
|
||
|
||
$merchant = Db::name('fc_merchant')->where('user_id', $id)->find();
|
||
if (!$merchant) {
|
||
$this->fail('商家不存在', 404);
|
||
}
|
||
|
||
Db::name('fc_merchant')->where('user_id', $id)->update([
|
||
'audit_status' => $auditStatus,
|
||
'audit_reason' => $reason,
|
||
'shop_status' => $auditStatus === 1 ? 'normal' : 'banned',
|
||
'updatetime' => time(),
|
||
]);
|
||
|
||
if ($auditStatus === 1) {
|
||
Db::name('fc_user_ext')->where('user_id', $id)->update([
|
||
'user_type' => 2,
|
||
'updatetime' => time(),
|
||
]);
|
||
$this->notify($id, 'system', '商家资质审核结果', '恭喜,您的商家资质已通过审核。');
|
||
} else {
|
||
$this->notify($id, 'system', '商家资质审核结果', '您的商家资质未通过:' . $reason);
|
||
}
|
||
|
||
$this->adminLog('审核商家 #' . $id . ' 结果' . $auditStatus);
|
||
|
||
$this->ok(['id' => $id, 'auditStatus' => $auditStatus]);
|
||
}
|
||
}
|