91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\agent;
|
|
|
|
use app\common\controller\Backend;
|
|
use support\Response;
|
|
use Webman\Http\Request as WebmanRequest;
|
|
|
|
/**
|
|
* 代理佣金记录
|
|
*/
|
|
class CommissionRecord extends Backend
|
|
{
|
|
protected ?object $model = null;
|
|
|
|
protected string|array $preExcludeFields = ['id', 'create_time', 'update_time'];
|
|
|
|
protected string|array $quickSearchField = ['id', 'remark'];
|
|
|
|
protected string|array $defaultSortField = ['id' => 'desc'];
|
|
|
|
protected string|array $orderGuarantee = ['id' => 'desc'];
|
|
|
|
protected array $withJoinTable = ['settlementPeriod', 'channel', 'admin'];
|
|
|
|
protected bool $modelValidate = true;
|
|
|
|
protected bool $modelSceneValidate = true;
|
|
|
|
protected function initController(WebmanRequest $request): ?Response
|
|
{
|
|
$this->model = new \app\common\model\AgentCommissionRecord();
|
|
return null;
|
|
}
|
|
|
|
protected function _index(): Response
|
|
{
|
|
if ($this->request && $this->request->get('select')) {
|
|
return $this->select($this->request);
|
|
}
|
|
|
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
|
$res = $this->model
|
|
->field($this->indexField)
|
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
|
->with($this->withJoinTable)
|
|
->alias($alias)
|
|
->where($where)
|
|
->order($order)
|
|
->paginate($limit);
|
|
|
|
$list = $this->enrichCommissionRecordList($res->items());
|
|
|
|
return $this->success('', [
|
|
'list' => $list,
|
|
'total' => $res->total(),
|
|
'remark' => get_route_remark(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param array<int, mixed> $items
|
|
* @return array<int, mixed>
|
|
*/
|
|
private function enrichCommissionRecordList(array $items): array
|
|
{
|
|
if ($items === []) {
|
|
return $items;
|
|
}
|
|
|
|
$out = [];
|
|
foreach ($items as $item) {
|
|
$row = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
|
|
$gross = strval($row['commission_amount'] ?? '0.00');
|
|
$fee = strval($row['handling_fee'] ?? '0.00');
|
|
$net = strval($row['net_commission_amount'] ?? '0.00');
|
|
if (bccomp($net, '0', 2) <= 0 && (bccomp($gross, '0', 2) > 0 || bccomp($fee, '0', 2) > 0)) {
|
|
$net = bcsub($gross, $fee, 2);
|
|
if (bccomp($net, '0', 2) < 0) {
|
|
$net = '0.00';
|
|
}
|
|
$row['net_commission_amount'] = $net;
|
|
}
|
|
$out[] = $row;
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
}
|
|
|