问题说明:我的推广页面佣金累计、可提现、冻结展示有误,原因是退款后冻结佣金没有及时处理
修改文件:app\services\user\UserBrokerageServices
修改方法:orderRefundBrokerageBack()
public function orderRefundBrokerageBack($order)
{
$id = (int)$order['id'];
$where = [
'uid' => [$order['spread_uid'], $order['spread_two_uid']],
'type' => ['self_brokerage', 'one_brokerage', 'two_brokerage'],
'link_id' => $id,
'pm' => 1
];
$brokerageList = $this->dao->getUserBrokerageList($where);
//子订单
if (!$brokerageList && $order['pid']) {
$where['link_id'] = $order['pid'];
$p_brokerageList = $this->dao->getUserBrokerageList($where);
//主订单已分佣 子订单按订单拆分后计算结果回退
if ($p_brokerageList) {
$brokerageList = [
['uid' => $order['spread_uid'], 'number' => $order['one_brokerage']],
['uid' => $order['spread_two_uid'], 'number' => $order['two_brokerage']],
];
}
}
$res = true;
if ($brokerageList) {
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$brokerages = $userServices->getColumn([['uid', 'in', array_column($brokerageList, 'uid')]], 'brokerage_price', 'uid');
$brokerageData = [];
foreach ($brokerageList as $item) {
if (!$item['uid'] || $item['uid'] <= 0) continue;
$usermoney = $brokerages[$item['uid']] ?? 0;
if ($item['number'] > $usermoney) {
$item['number'] = $usermoney;
}
if ($item['number'] <= 0) continue;
$res = $res && $userServices->bcDec($item['uid'], 'brokerage_price', (string)$item['number'], 'uid', 2, false);
$brokerageData[] = [
'title' => '退款退佣金',
'uid' => $item['uid'],
'pm' => 0,
'add_time' => time(),
'type' => 'refund',
'number' => $item['number'],
'link_id' => $id,
'balance' => bcsub((string)$usermoney, (string)$item['number'], 2),
'mark' => '订单退款扣除佣金' . floatval($item['number']) . '元'
];
}
if ($brokerageData) {
$res = $res && $this->dao->saveAll($brokerageData);
if ($res) {
foreach ($brokerageData as $items){
$this->dao->update([
'link_id' => $id,
'uid' => $items['uid'],
'pm' => 1,
], ['frozen_time' => 0]);
}
}
}
}
return $res;
}