feat(wallet): 用户提交时直连汇付API优化流程 - 移除数据库事务包装汇付API调用,避免长耗时锁表问题 - 用户提交申请时直接连接汇付服务,不再仅保存草稿等待后台处理 - 修改汇付重提交方法名为resubmit以明确区分不同操作 - 更新异常处理机制,增加Throwable捕获确保错误正确处理 - 调整提交成功后的消息提示内容,准确反映当前处理状态 fix(agent): 代理申请流程汇付集成优化 - 统一汇付进件提交失败的消息提示文本 - 优化代理申请状态判断逻辑,根据汇付载荷存在性决定提交方式 - 更新区域代理申请成功提示,区分已提交汇付和待提交场景 - 修复业务审核通过后的汇付提交触发机制 docs(huifu): 更新汇付进件相关文档说明 - 修改后台管理界面描述,体现用户直连汇付的新流程 - 更新业务审核状态下的操作指引说明 - 调整汇付网关类的方法注释,明确各方法职责变化 - 修正canSaveHuifuDraft方法注释,说明字段兼容性和新功能 ```
258 行
9.9 KiB
PHP
258 行
9.9 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\controller\regional_agent;
|
|
|
|
use addons\shopro\model\Area;
|
|
use addons\shopro\model\regional_agent\Agent as AgentModel;
|
|
use addons\shopro\model\regional_agent\Level as LevelModel;
|
|
use addons\shopro\model\regional_agent\Order as RegionalOrderModel;
|
|
use addons\shopro\model\regional_agent\Reward as RewardModel;
|
|
|
|
class Agent extends RegionalAgent
|
|
{
|
|
/**
|
|
* 代理信息
|
|
*/
|
|
public function info()
|
|
{
|
|
$userId = $this->auth->id;
|
|
$agents = AgentModel::with(['agentLevel'])
|
|
->where('user_id', $userId)
|
|
->order('id desc')
|
|
->select();
|
|
|
|
$delayMoney = RewardModel::waiting()->where('agent_user_id', $userId)->sum('commission');
|
|
|
|
$payload = [
|
|
'agents' => $agents,
|
|
'delay_money' => round($delayMoney, 2),
|
|
'apply_form' => $this->_config->getApplyForm(),
|
|
];
|
|
if (class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardGate')) {
|
|
$latestAgent = AgentModel::where('user_id', $userId)->order('id desc')->find();
|
|
$refId = $latestAgent ? $latestAgent['id'] : 0;
|
|
$onboardRow = $refId
|
|
? \addons\shopro_huifu\model\Onboard::findByRole($userId, 'regional_agent', $refId)
|
|
: null;
|
|
$agentStatus = $latestAgent ? ($latestAgent['status'] ?? '') : '';
|
|
$payload['huifu_onboard'] = \addons\shopro_huifu\library\onboard\HuifuOnboardGate::publicStatus(
|
|
$onboardRow,
|
|
$userId,
|
|
'regional_agent',
|
|
$refId,
|
|
$agentStatus
|
|
);
|
|
$payload['agent_check'] = $this->_config->isAgentCheck();
|
|
}
|
|
$this->success('获取成功', $payload);
|
|
}
|
|
|
|
/**
|
|
* 申请成为区域代理
|
|
*/
|
|
public function apply()
|
|
{
|
|
$areaId = intval($this->request->post('area_id'));
|
|
$areaLevel = intval($this->request->post('area_level'));
|
|
$applyData = $this->request->post('data/a', []);
|
|
|
|
if (!$areaId || !$areaLevel) {
|
|
$this->error('请选择公司区域');
|
|
}
|
|
|
|
$exists = AgentModel::where('user_id', $this->auth->id)
|
|
->where('area_id', $areaId)
|
|
->where('status', '<>', AgentModel::STATUS_FORBIDDEN)
|
|
->find();
|
|
if ($exists) {
|
|
$this->error('您已申请或已是该区域公司');
|
|
}
|
|
|
|
$conflict = AgentModel::available()
|
|
->where('area_id', $areaId)
|
|
->where('area_level', $areaLevel)
|
|
->find();
|
|
if ($conflict) {
|
|
$this->error('该区域已有公司');
|
|
}
|
|
|
|
$area = Area::get($areaId);
|
|
$level = LevelModel::where('area_level', $areaLevel)->order('level asc')->find();
|
|
if (!$level) {
|
|
$this->error('公司等级不存在');
|
|
}
|
|
|
|
$huifuRequired = class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardGate')
|
|
&& \addons\shopro_huifu\library\onboard\HuifuOnboardGate::isOnboardRequired();
|
|
// 汇付分账模式下必须后台审核;否则遵循区域公司申请审核开关
|
|
$status = ($this->_config->isAgentCheck() || $huifuRequired)
|
|
? AgentModel::STATUS_PENDING
|
|
: AgentModel::STATUS_NORMAL;
|
|
|
|
$userId = $this->auth->id;
|
|
$huifuOnboard = $this->request->post('huifu_onboard/a', []);
|
|
\think\Db::transaction(function () use ($level, $areaId, $areaLevel, $area, $applyData, $status, $userId, $huifuOnboard) {
|
|
$agentRow = AgentModel::create([
|
|
'user_id' => $userId,
|
|
'level' => $level['level'],
|
|
'area_id' => $areaId,
|
|
'area_level' => $areaLevel,
|
|
'area_name' => $area ? $area['name'] : '',
|
|
'apply_info' => json_encode($applyData, JSON_UNESCAPED_UNICODE),
|
|
'status' => $status,
|
|
'becometime' => $status === AgentModel::STATUS_NORMAL ? time() : null,
|
|
]);
|
|
|
|
if (class_exists('\\addons\\shopro_huifu\\library\\Bridge') && !empty($huifuOnboard)) {
|
|
$hookParams = [
|
|
'user_id' => $userId,
|
|
'regional_agent_id' => $agentRow['id'],
|
|
'huifu_onboard' => $huifuOnboard,
|
|
];
|
|
try {
|
|
\think\Hook::listen('shopro_regional_agent_apply_after', $hookParams);
|
|
} catch (\Throwable $e) {
|
|
$this->error($e->getMessage() ?: '汇付进件提交失败');
|
|
}
|
|
}
|
|
});
|
|
|
|
if ($status === AgentModel::STATUS_PENDING) {
|
|
$msg = $huifuRequired
|
|
? (!empty($huifuOnboard)
|
|
? '申请已提交,汇付进件已同步提交,请耐心等待审核'
|
|
: '申请已提交,请等待后台审核;通过后请到「提现」页完成汇付进件')
|
|
: '申请已提交,请等待后台审核';
|
|
} else {
|
|
$msg = '申请已通过,您已成为该区域公司';
|
|
if ($huifuRequired && !empty($huifuOnboard)) {
|
|
$msg = '申请已通过,汇付进件已同步提交,请耐心等待审核';
|
|
} elseif ($huifuRequired && class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardGate')) {
|
|
// 无随申请提交资料时,兜底尝试提交历史 draft
|
|
\addons\shopro_huifu\library\onboard\HuifuOnboardGate::submitOnBusinessApproved(
|
|
$userId,
|
|
'regional_agent',
|
|
AgentModel::where('user_id', $userId)->order('id desc')->value('id')
|
|
);
|
|
}
|
|
}
|
|
$this->success($msg, ['status' => $status]);
|
|
}
|
|
|
|
/**
|
|
* 区域业绩统计
|
|
*/
|
|
public function stats()
|
|
{
|
|
$userId = $this->auth->id;
|
|
$startTime = $this->request->get('start_time');
|
|
$endTime = $this->request->get('end_time');
|
|
$start = $startTime ? (is_numeric($startTime) ? intval($startTime) : strtotime($startTime)) : 0;
|
|
$end = $endTime ? (is_numeric($endTime) ? intval($endTime) : strtotime($endTime . ' 23:59:59')) : 0;
|
|
|
|
$agents = AgentModel::where('user_id', $userId)->where('status', AgentModel::STATUS_NORMAL)->select();
|
|
|
|
$stats = [];
|
|
$totalOrderCount = 0;
|
|
$totalOrderMoney = 0;
|
|
$totalIncome = 0;
|
|
$totalDelay = 0;
|
|
|
|
foreach ($agents as $agent) {
|
|
$orderCountQuery = RegionalOrderModel::where('agent_id', $agent['id']);
|
|
$orderSumQuery = RegionalOrderModel::where('agent_id', $agent['id']);
|
|
$rewardSumQuery = RewardModel::where('agent_id', $agent['id'])->where('status', 1);
|
|
if ($start && $end) {
|
|
$orderCountQuery->where('createtime', 'between', [$start, $end]);
|
|
$orderSumQuery->where('createtime', 'between', [$start, $end]);
|
|
$rewardSumQuery->where('createtime', 'between', [$start, $end]);
|
|
}
|
|
|
|
$orderCount = $orderCountQuery->count();
|
|
$orderMoney = round($orderSumQuery->sum('amount'), 2);
|
|
$income = round($rewardSumQuery->sum('commission'), 2);
|
|
$delayMoney = round(RewardModel::waiting()->where('agent_user_id', $userId)->where('agent_id', $agent['id'])->sum('commission'), 2);
|
|
|
|
$stats[] = [
|
|
'agent' => $agent,
|
|
'order_count' => $orderCount,
|
|
'order_money' => $orderMoney,
|
|
'total_income' => $income,
|
|
'delay_money' => $delayMoney,
|
|
];
|
|
|
|
$totalOrderCount += $orderCount;
|
|
$totalOrderMoney += $orderMoney;
|
|
$totalIncome += $income;
|
|
$totalDelay += $delayMoney;
|
|
}
|
|
|
|
$this->success('获取成功', [
|
|
'list' => $stats,
|
|
'summary' => [
|
|
'order_count' => $totalOrderCount,
|
|
'order_money' => round($totalOrderMoney, 2),
|
|
'total_income' => round($totalIncome, 2),
|
|
'delay_money' => round($totalDelay, 2),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 区域订单列表
|
|
*/
|
|
public function orders()
|
|
{
|
|
$userId = $this->auth->id;
|
|
$perPage = $this->request->get('per_page', 10);
|
|
$startTime = $this->request->get('start_time');
|
|
$endTime = $this->request->get('end_time');
|
|
|
|
$query = RegionalOrderModel::where('agent_user_id', $userId);
|
|
if ($startTime && $endTime) {
|
|
$start = is_numeric($startTime) ? intval($startTime) : strtotime($startTime);
|
|
$end = is_numeric($endTime) ? intval($endTime) : strtotime($endTime . ' 23:59:59');
|
|
$query->where('createtime', 'between', [$start, $end]);
|
|
}
|
|
|
|
$orders = $query->order('id desc')->paginate($perPage);
|
|
|
|
$this->success('获取成功', $orders);
|
|
}
|
|
|
|
/**
|
|
* 佣金明细
|
|
*/
|
|
public function rewards()
|
|
{
|
|
$userId = $this->auth->id;
|
|
$perPage = $this->request->get('per_page', 10);
|
|
$startTime = $this->request->get('start_time');
|
|
$endTime = $this->request->get('end_time');
|
|
$status = $this->request->get('status');
|
|
|
|
$query = RewardModel::where('agent_user_id', $userId);
|
|
if ($startTime && $endTime) {
|
|
$start = is_numeric($startTime) ? intval($startTime) : strtotime($startTime);
|
|
$end = is_numeric($endTime) ? intval($endTime) : strtotime($endTime . ' 23:59:59');
|
|
$query->where('createtime', 'between', [$start, $end]);
|
|
}
|
|
if ($status !== null && $status !== '') {
|
|
$query->where('status', intval($status));
|
|
}
|
|
|
|
$rewards = $query->order('id desc')->paginate($perPage);
|
|
|
|
$this->success('获取成功', $rewards);
|
|
}
|
|
|
|
/**
|
|
* 可代理等级列表
|
|
*/
|
|
public function levels()
|
|
{
|
|
$levels = LevelModel::order('level asc')->select();
|
|
$this->success('获取成功', $levels);
|
|
}
|
|
}
|