id = $model->id; $dto->userId = $model->user_id; $dto->fundId = $model->fund_id; $dto->amount = $model->amount; $dto->operateId = $model->operate_id; $dto->operateType = $model->operate_type; $dto->remark = $model->remark; $dto->createTime = $model->create_time; $dto->createIp = $model->create_ip; $dto->laterBalance = $model->later_balance; $dto->beforeBalance = $model->before_balance; $dto->dateKey = $model->date_key; $dto->hash = $model->hash; $dto->prevHash = $model->prev_hash; // 如果提供了资金类型名称映射,则设置资金类型名称 if (!empty($fundNames) && isset($fundNames[$model->fund_id])) { $dto->fundName = $fundNames[$model->fund_id]; } // 如果提供了操作类型名称映射,则设置操作类型名称 if (!empty($operateTypeNames) && isset($operateTypeNames[$model->operate_type instanceof LOG_TYPE ? $model->operate_type->value : $model->operate_type])) { $dto->operateTypeName = $operateTypeNames[$model->operate_type instanceof LOG_TYPE ? $model->operate_type->value : $model->operate_type]; } return $dto; } /** * 转换为数组 * * @return array */ public function toArray(): array { $result = [ 'id' => $this->id, 'user_id' => $this->userId, 'fund_id' => $this->fundId, 'amount' => $this->amount, 'operate_id' => $this->operateId, 'operate_type' => $this->operateType instanceof LOG_TYPE ? $this->operateType->value : $this->operateType, 'remark' => $this->remark, 'create_time' => $this->createTime, 'create_ip' => $this->createIp, 'later_balance' => $this->laterBalance, 'before_balance' => $this->beforeBalance, 'date_key' => $this->dateKey, 'hash' => $this->hash, 'prev_hash' => $this->prevHash, ]; if ($this->fundName !== null) { $result['fund_name'] = $this->fundName; } if ($this->operateTypeName !== null) { $result['operate_type_name'] = $this->operateTypeName; } return $result; } }