文件
xionggeshop/application/admin/controller/shopro/split/Receiver.php
可乐加冰 9181c7144f ```
feat(split): 完善分账接收方列表展示功能

- 添加用户信息查询和展示,包括昵称、手机号等用户详情
- 增加汇付进件状态显示和账号匹配校验功能
- 优化前端表格界面,新增用户关联信息、进件核对状态等列
- 改进数据格式化处理,提供更详细的分账接收方信息展示
- 更新表单提示文案,明确用户ID填写规则和要求
```
2026-10-05 12:56:57 +08:00

238 行
8.2 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller\shopro\split;
use app\admin\controller\shopro\Base;
use addons\shopro\library\split\Config as SplitConfig;
use addons\shopro\library\split\ProfitSharingService;
use app\admin\model\shopro\user\User as ShopUser;
use think\Db;
class Receiver extends Base
{
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \addons\shopro\model\split\Receiver;
}
public function index()
{
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
list($where, $sort, $order, $offset, $limit) = $this->custombuildparams();
$total = $this->model->where($where)->count();
$list = $this->model->where($where)->order($sort, $order)->limit($offset, $limit)->select();
$list = $this->formatReceiverList($list);
return $this->success('操作成功', null, ['total' => $total, 'rows' => $list]);
}
$this->assignconfig('splitHuifuOnly', (new SplitConfig())->isHuifuMode());
return $this->view->fetch();
}
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post('row/a');
if (empty($params['receiver_account'])) {
$this->error('请填写接收方账号');
}
$this->model->create($params);
$this->success('添加成功');
}
return $this->view->fetch();
}
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error('记录不存在');
}
if ($this->request->isPost()) {
$params = $this->request->post('row/a');
$row->save($params);
$this->success('保存成功');
}
$this->view->assign('row', $row);
return $this->view->fetch();
}
public function del($ids = null)
{
$row = $this->model->get($ids);
if ($row) {
$row->status = 'forbidden';
$row->save();
}
$this->success('操作成功');
}
protected function formatReceiverList($list)
{
$rows = [];
$userIds = [];
foreach ($list as $item) {
$data = is_array($item) ? $item : $item->toArray();
$roleId = intval($data['role_id'] ?? 0);
if ($roleId > 0) {
$userIds[] = $roleId;
}
}
$userIds = array_values(array_unique($userIds));
$users = [];
if ($userIds) {
$userRows = ShopUser::where('id', 'in', $userIds)->field('id,nickname,mobile')->select();
foreach ($userRows as $user) {
$u = is_array($user) ? $user : $user->toArray();
$users[intval($u['id'])] = $u;
}
}
$onboardMap = [];
if ($userIds) {
try {
$onboardRows = Db::name('shopro_huifu_onboard')
->where('user_id', 'in', $userIds)
->order('id desc')
->select();
foreach ($onboardRows as $ob) {
$uid = intval($ob['user_id']);
if (!isset($onboardMap[$uid])) {
$onboardMap[$uid] = $ob;
}
}
} catch (\Throwable $e) {
$onboardMap = [];
}
}
foreach ($list as $item) {
$data = is_array($item) ? $item : $item->toArray();
$roleId = intval($data['role_id'] ?? 0);
$user = $roleId > 0 && isset($users[$roleId]) ? $users[$roleId] : null;
$onboard = $roleId > 0 && isset($onboardMap[$roleId]) ? $onboardMap[$roleId] : null;
$data['user_id'] = $roleId;
$data['user_nickname'] = is_array($user) ? trim((string) ($user['nickname'] ?? '')) : '';
$data['user_mobile'] = is_array($user) ? trim((string) ($user['mobile'] ?? '')) : '';
$data['user_display'] = $this->formatUserDisplay($roleId, $user);
$data['role_id_text'] = $roleId > 0 ? (string) $roleId : '0(通用)';
$onboardHuifuId = trim((string) ($onboard['huifu_id'] ?? ''));
$receiverAccount = trim((string) ($data['receiver_account'] ?? ''));
$data['onboard_huifu_id'] = $onboardHuifuId;
$data['onboard_status'] = $onboard['onboard_status'] ?? '';
$data['onboard_status_text'] = $this->formatOnboardStatus($onboard['onboard_status'] ?? '');
$data['account_match'] = ($onboardHuifuId !== '' && $receiverAccount !== '' && $onboardHuifuId === $receiverAccount) ? 1 : 0;
$data['account_match_text'] = $this->formatAccountMatch($roleId, $onboardHuifuId, $receiverAccount);
$data['channel_text'] = ($data['channel'] ?? '') === 'huifu' ? '汇付' : '微信';
$data['role_type_text'] = $this->roleTypeLabel($data['role_type'] ?? '');
$data['status_text'] = ($data['status'] ?? '') === 'forbidden' ? '禁用' : '正常';
$data['createtime_text'] = !empty($data['createtime'])
? date('Y-m-d H:i:s', $data['createtime'])
: '-';
$rows[] = $data;
}
return $rows;
}
protected function formatUserDisplay($roleId, $user)
{
if ($roleId <= 0) {
return '—(规则模式通用接收方)';
}
if (!is_array($user)) {
return '用户#' . $roleId . '(未找到)';
}
$nickname = trim((string) ($user['nickname'] ?? ''));
$mobile = trim((string) ($user['mobile'] ?? ''));
if ($nickname !== '' && $mobile !== '') {
return $nickname . '(' . $mobile . ')';
}
if ($nickname !== '') {
return $nickname;
}
if ($mobile !== '') {
return $mobile;
}
return '用户#' . $roleId;
}
protected function formatOnboardStatus($status)
{
$map = [
'draft' => '草稿',
'submitting' => '提交中',
'basic_ok' => '基础进件完成',
'busi_pending' => '业务开通中',
'approved' => '已通过',
'rejected' => '已驳回',
'failed' => '失败',
];
$status = trim((string) $status);
return $status !== '' ? ($map[$status] ?? $status) : '—';
}
protected function formatAccountMatch($roleId, $onboardHuifuId, $receiverAccount)
{
if ($roleId <= 0) {
return '—';
}
if ($onboardHuifuId === '' && $receiverAccount === '') {
return '未配置';
}
if ($onboardHuifuId === '') {
return '未进件';
}
if ($receiverAccount === '') {
return '未填账号';
}
return $onboardHuifuId === $receiverAccount ? '与进件一致' : '与进件不一致';
}
protected function roleTypeLabel($type)
{
$map = [
'platform' => '平台',
'promoter' => '推广员',
'regional_agent' => '区域公司',
];
return $map[$type] ?? ($type ?: '-');
}
public function syncWx($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error('记录不存在');
}
if ((new SplitConfig())->isHuifuMode()) {
$this->error('当前为汇付分账:无需同步微信接收方。请在汇付控台绑定分账关系,并在此填写 huifu_id');
}
try {
$service = new ProfitSharingService();
$service->addReceiver([
'type' => $row['receiver_type'],
'account' => $row['receiver_account'],
'name' => $row['receiver_name'],
'relation_type' => $row['relation_type'] ?: 'USER',
]);
$row->wx_status = 1;
$row->wx_message = '同步成功';
$row->save();
$this->success('同步成功');
} catch (\Exception $e) {
$row->wx_status = 2;
$row->wx_message = $e->getMessage();
$row->save();
$this->error($e->getMessage());
}
}
}