feat: 新增地址选择插件及订阅消息等多项功能优化
- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
这个提交包含在:
@@ -14,6 +14,13 @@ use think\Db;
|
||||
*/
|
||||
class AdminDist extends V1
|
||||
{
|
||||
/** 管理端接口必须校验管理员身份(V1 默认关闭了 URI 权限校验) */
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->adminOnly();
|
||||
}
|
||||
|
||||
/**
|
||||
* AD1 分销设置读取
|
||||
* GET /api/v1/admin/dist/setting → {enabled,level,level1Rate,level2Rate,settleCycle,minWithdraw}
|
||||
@@ -68,16 +75,38 @@ class AdminDist extends V1
|
||||
->order('w.createtime desc')
|
||||
->select();
|
||||
|
||||
// 兜底同步:转账中的单据主动查一次微信(回调丢失/本地无 HTTPS 回调时)
|
||||
$synced = 0;
|
||||
foreach ($rows as $row) {
|
||||
if ((string)$row['status'] === 'paying' && $synced < 5) {
|
||||
$synced++;
|
||||
try {
|
||||
\app\common\library\WxTransfer::sync((int)$row['id']);
|
||||
} catch (\Throwable $e) {
|
||||
// 同步失败不影响列表展示
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($synced > 0) {
|
||||
$rows = Db::name('fc_withdraw')->alias('w')
|
||||
->join('user u', 'u.id = w.user_id', 'LEFT')
|
||||
->field('w.*, u.nickname AS nickname')
|
||||
->order('w.createtime desc')
|
||||
->select();
|
||||
}
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'withdrawNo' => (string)$row['withdraw_no'],
|
||||
'user' => (string)$row['nickname'],
|
||||
'amount' => (float)$row['amount'],
|
||||
'status' => (string)$row['status'],
|
||||
'channel' => (string)$row['channel'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
'id' => (int)$row['id'],
|
||||
'withdrawNo' => (string)$row['withdraw_no'],
|
||||
'user' => (string)$row['nickname'],
|
||||
'amount' => (float)$row['amount'],
|
||||
'status' => (string)$row['status'],
|
||||
'channel' => (string)$row['channel'],
|
||||
'transferStatus' => (string)(isset($row['transfer_status']) ? $row['transfer_status'] : ''),
|
||||
'failReason' => (string)(isset($row['fail_reason']) ? $row['fail_reason'] : ''),
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -103,27 +132,72 @@ class AdminDist extends V1
|
||||
if (!$withdraw) {
|
||||
$this->fail('提现记录不存在', 404);
|
||||
}
|
||||
|
||||
if ($op === 'reject') {
|
||||
$status = 'rejected';
|
||||
Db::name('fc_withdraw')->where('id', $id)->update([
|
||||
'status' => $status,
|
||||
'reason' => $reason,
|
||||
]);
|
||||
$this->notify($withdraw['user_id'], 'system', '提现被驳回', '您的提现申请被驳回:' . $reason);
|
||||
} else {
|
||||
$status = 'paid';
|
||||
Db::name('fc_withdraw')->where('id', $id)->update([
|
||||
'status' => $status,
|
||||
'paytime' => time(),
|
||||
]);
|
||||
$this->flow('expense', '佣金提现', $withdraw['amount'], 0, $id);
|
||||
$this->notify($withdraw['user_id'], 'system', '提现已打款', '您的提现申请已打款,请注意查收。');
|
||||
if ((string)$withdraw['status'] !== 'auditing') {
|
||||
$this->fail('该提现记录已处理(当前状态:' . $withdraw['status'] . '),请勿重复操作');
|
||||
}
|
||||
|
||||
$this->adminLog('处理提现 #' . $id . ' 结果' . $status);
|
||||
if ($op === 'reject') {
|
||||
try {
|
||||
Db::transaction(function () use ($id, $reason) {
|
||||
$locked = Db::name('fc_withdraw')->where('id', $id)->lock(true)->find();
|
||||
if (!$locked || (string)$locked['status'] !== 'auditing') {
|
||||
throw new \RuntimeException('该提现记录已处理,请刷新后重试');
|
||||
}
|
||||
Db::name('fc_withdraw')->where('id', $id)->update([
|
||||
'status' => 'rejected',
|
||||
'reason' => $reason,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
$this->notify($locked['user_id'], 'system', '提现被驳回', '您的提现申请被驳回:' . $reason);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
$this->fail($e->getMessage() ?: '操作失败,请重试');
|
||||
}
|
||||
|
||||
$this->ok(['id' => (int)$id, 'status' => $status]);
|
||||
$this->adminLog('驳回提现 #' . $id);
|
||||
$this->ok(['id' => (int)$id, 'status' => 'rejected']);
|
||||
}
|
||||
|
||||
// 审核通过 → 自动发起微信商家转账(用户需在微信确认收款)
|
||||
try {
|
||||
$res = \app\common\library\WxTransfer::approve($id);
|
||||
} catch (\Throwable $e) {
|
||||
$this->fail('转账失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->adminLog('提现转账 #' . $id . ' 结果' . $res['state']);
|
||||
|
||||
$message = $res['withdrawState'] === 'paid'
|
||||
? '转账成功,已到账'
|
||||
: ($res['withdrawState'] === 'failed' ? '转账失败,请查看失败原因' : '已提交转账,等待用户确认收款');
|
||||
|
||||
$this->ok([
|
||||
'id' => (int)$id,
|
||||
'status' => $res['withdrawState'],
|
||||
'transferState' => $res['state'],
|
||||
], $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销「转账中」的提现单(用户长期不确认收款时使用)
|
||||
* POST /api/v1/admin/dist/withdraw/:id/cancel
|
||||
*/
|
||||
public function cancelWithdraw()
|
||||
{
|
||||
$id = (int)$this->request->param('id', 0);
|
||||
|
||||
try {
|
||||
$state = \app\common\library\WxTransfer::cancel($id);
|
||||
} catch (\Throwable $e) {
|
||||
$this->fail('撤销失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->adminLog('撤销提现转账 #' . $id);
|
||||
$this->ok([
|
||||
'id' => $id,
|
||||
'status' => (string)Db::name('fc_withdraw')->where('id', $id)->value('status'),
|
||||
'transferState' => $state,
|
||||
]);
|
||||
}
|
||||
|
||||
/** 组装分销设置结构 */
|
||||
|
||||
在新工单中引用
屏蔽一个用户