feat(shopro_huifu): 完善汇付分账服务功能 - 实现分账确认金额解析逻辑,确保与汇付待确认金额一致 - 添加分账项目缩放调整功能,防止分配总额超出限制 - 优化分账金额计算精度处理,使用BC数学函数保证准确性 - 改进后台重试接口错误提示,提供详细的失败原因信息 ```
91 行
3.4 KiB
PHP
91 行
3.4 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller\shopro\split;
|
||
|
||
use app\admin\controller\shopro\Base;
|
||
use addons\shopro\library\split\SplitExecutor;
|
||
use addons\shopro\library\split\ProfitSharingService;
|
||
|
||
class Order extends Base
|
||
{
|
||
protected $model = null;
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->model = new \addons\shopro\model\split\SplitOrder;
|
||
}
|
||
|
||
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->with('receivers')->where($where)->order($sort, $order)->limit($offset, $limit)->select();
|
||
return $this->success('操作成功', null, ['total' => $total, 'rows' => $list]);
|
||
}
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function retry($ids = null)
|
||
{
|
||
$id = $ids ?: $this->request->post('id');
|
||
$row = $this->model->get($id);
|
||
$result = (new SplitExecutor())->retry($id);
|
||
if ($result) {
|
||
$this->success('重试成功');
|
||
}
|
||
$hint = '';
|
||
if ($row) {
|
||
$latest = $this->model->where('order_id', $row['order_id'])
|
||
->where('channel', $row['channel'] ?? 'wechat')
|
||
->order('id', 'desc')
|
||
->find();
|
||
if ($latest && !empty($latest['wx_result'])) {
|
||
$raw = is_string($latest['wx_result']) ? $latest['wx_result'] : json_encode($latest['wx_result'], JSON_UNESCAPED_UNICODE);
|
||
$decoded = json_decode($raw, true);
|
||
if (is_array($decoded)) {
|
||
$parts = array_filter([
|
||
$decoded['resp_desc'] ?? '',
|
||
$decoded['resp_code'] ?? '',
|
||
$decoded['bank_message'] ?? '',
|
||
]);
|
||
$hint = $parts ? (':' . implode(' ', $parts)) : (':' . mb_substr($raw, 0, 300));
|
||
} else {
|
||
$hint = ':' . mb_substr($raw, 0, 300);
|
||
}
|
||
}
|
||
}
|
||
if ($hint === '') {
|
||
$hint = ':常见为分账明细为空(佣金/规则未匹配到汇付接收方)、汇付未开通分账/延时分账权限、接收方未绑定分账关系';
|
||
}
|
||
$this->error('重试失败,请查看分账记录 wx_result' . $hint);
|
||
}
|
||
|
||
public function query($ids = null)
|
||
{
|
||
$row = $this->model->get($ids);
|
||
if (!$row) {
|
||
$this->error('记录不存在');
|
||
}
|
||
try {
|
||
if (($row['channel'] ?? 'wechat') === 'huifu' && class_exists('\\addons\\shopro_huifu\\library\\HuifuSplitService')) {
|
||
$service = new \addons\shopro_huifu\library\HuifuSplitService();
|
||
$result = $service->querySplit($row['transaction_id']);
|
||
} else {
|
||
$service = new ProfitSharingService();
|
||
$result = $service->queryOrder([
|
||
'out_order_no' => $row['out_order_no'],
|
||
'transaction_id' => $row['transaction_id'],
|
||
]);
|
||
}
|
||
$row->wx_result = json_encode($result, JSON_UNESCAPED_UNICODE);
|
||
$row->save();
|
||
$this->success('查询成功', null, $result);
|
||
} catch (\Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
}
|
||
}
|