feat: 完善分销提现审核与转账流程,增强帖子详情交互
这个提交包含在:
@@ -6,7 +6,7 @@ use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 同城-提现
|
||||
* 同城-提现管理与审核控制器
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
@@ -19,6 +19,11 @@ class Withdraw extends Backend
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* 初始化控制器
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
@@ -26,16 +31,115 @@ class Withdraw extends Backend
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
* 提现审核详情与核验
|
||||
*
|
||||
* @param mixed $ids 提现记录ID
|
||||
* @return string
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post('row/a');
|
||||
if ($params) {
|
||||
$params = $this->preExcludeFields($params);
|
||||
// 资金安全:严禁在编辑中篡改提现单号、金额、用户ID、渠道与微信单号
|
||||
unset($params['withdraw_no'], $params['amount'], $params['user_id'], $params['channel'], $params['out_bill_no'], $params['transfer_id']);
|
||||
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 只允许修改备注、处理时间等辅助信息
|
||||
$result = $row->allowField(['reason', 'paytime', 'updatetime'])->save($params);
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
|
||||
$userId = (int)$row['user_id'];
|
||||
|
||||
// 1. 获取申请用户信息
|
||||
$user = Db::name('user')
|
||||
->where('id', $userId)
|
||||
->field('id,username,nickname,mobile,avatar,money,score,createtime')
|
||||
->find();
|
||||
|
||||
// 2. 获取用户同城扩展信息(微信OpenID、实名认证等)
|
||||
$userExt = Db::name('fc_user_ext')
|
||||
->where('user_id', $userId)
|
||||
->field('openid,realname,realname_status,is_member,member_level')
|
||||
->find();
|
||||
|
||||
// 3. 计算用户分销佣金与提现对账数据
|
||||
$totalCommission = (float)Db::name('fc_commission')
|
||||
->where('user_id', $userId)
|
||||
->where('status', '<>', 2)
|
||||
->sum('amount');
|
||||
|
||||
$settledCommission = (float)Db::name('fc_commission')
|
||||
->where('user_id', $userId)
|
||||
->where('status', 1)
|
||||
->sum('amount');
|
||||
|
||||
$totalWithdrawn = (float)Db::name('fc_withdraw')
|
||||
->where('user_id', $userId)
|
||||
->where('status', 'paid')
|
||||
->sum('amount');
|
||||
|
||||
$appliedTotal = (float)Db::name('fc_withdraw')
|
||||
->where('user_id', $userId)
|
||||
->where('status', 'in', ['auditing', 'paying', 'paid'])
|
||||
->sum('amount');
|
||||
|
||||
// 当前剩余可提现金额
|
||||
$withdrawable = max(0, $settledCommission - $appliedTotal);
|
||||
|
||||
// 4. 预设快捷驳回原因模板
|
||||
$rejectReasons = [
|
||||
'微信未实名或实名与提现账户不一致',
|
||||
'提现用户未绑定微信或OpenID失效',
|
||||
'关联分销订单存在售后退款,佣金核验中',
|
||||
'账号涉嫌虚假刷单/违规套现,暂缓打款',
|
||||
'用户联系客服主动申请撤回提现',
|
||||
'微信商家转账账户余额不足,请稍后重试',
|
||||
];
|
||||
|
||||
$this->view->assign([
|
||||
'row' => $row,
|
||||
'userInfo' => $user ?: [],
|
||||
'userExt' => $userExt ?: [],
|
||||
'totalCommission' => round($totalCommission, 2),
|
||||
'settledCommission' => round($settledCommission, 2),
|
||||
'totalWithdrawn' => round($totalWithdrawn, 2),
|
||||
'withdrawable' => round($withdrawable, 2),
|
||||
'rejectReasons' => $rejectReasons,
|
||||
]);
|
||||
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现打款/驳回
|
||||
* 提现打款/驳回操作处理
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function pay()
|
||||
{
|
||||
@@ -134,6 +238,63 @@ class Withdraw extends Backend
|
||||
$this->success($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步微信商家转账状态(主动查询)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sync()
|
||||
{
|
||||
$ids = $this->request->post('ids');
|
||||
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
|
||||
$ids = array_filter($ids);
|
||||
if (!$ids) {
|
||||
$this->error('请选择要同步的提现记录');
|
||||
}
|
||||
|
||||
$withdraws = Db::name('fc_withdraw')
|
||||
->where('id', 'in', $ids)
|
||||
->where('status', 'paying')
|
||||
->select();
|
||||
|
||||
if (!$withdraws) {
|
||||
$this->error('选中的记录中没有处于「转账中」的提现单');
|
||||
}
|
||||
|
||||
$successCount = 0;
|
||||
$failedCount = 0;
|
||||
$payingCount = 0;
|
||||
$errors = [];
|
||||
|
||||
foreach ($withdraws as $withdraw) {
|
||||
try {
|
||||
$state = \app\common\library\WxTransfer::sync((int)$withdraw['id']);
|
||||
if ($state === 'paid') {
|
||||
$successCount++;
|
||||
} elseif ($state === 'failed') {
|
||||
$failedCount++;
|
||||
} else {
|
||||
$payingCount++;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$errors[] = $withdraw['withdraw_no'] . ':' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$msg = '状态同步完成:';
|
||||
if ($successCount > 0) {
|
||||
$msg .= $successCount . ' 笔已确认到账;';
|
||||
}
|
||||
if ($payingCount > 0) {
|
||||
$msg .= $payingCount . ' 笔仍待用户确认或处理中;';
|
||||
}
|
||||
if ($failedCount > 0) {
|
||||
$msg .= $failedCount . ' 笔转账失败;';
|
||||
}
|
||||
if ($errors) {
|
||||
$msg .= ' 异常:' . implode(';', $errors);
|
||||
}
|
||||
|
||||
$this->success($msg);
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户