'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 $items * @return array */ 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; } }