| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Transformer\Points;
- class PointsTransformer
- {
- const TYPE_LABELS = [
- 'video' => '视频生成',
- 'video_refund' => '视频生成退款',
- 'image' => '图片生成',
- 'image_refund' => '图片生成退款',
- 'chat' => 'AI对话',
- 'chat_refund' => 'AI对话退款',
- ];
- /**
- * 积分流水列表
- *
- * @param $data
- * @return array
- */
- public function newBuildPointsRecords($data): array
- {
- return [
- 'meta' => getMeta($data),
- 'list' => $this->newEachPointsRecord($data),
- ];
- }
- /**
- * 单条积分流水
- *
- * @param $list
- * @return array
- */
- public function newEachPointsRecord($list): array
- {
- $result = [];
- if (empty($list)) return $result;
- foreach ($list as $item) {
- $chargeInfo = getProp($item, 'charge_info');
- if (is_string($chargeInfo)) {
- $chargeInfo = json_decode($chargeInfo, true);
- }
- $chargeInfo = is_array($chargeInfo) ? $chargeInfo : [];
- $type = getProp($item, 'type', '');
- $result[] = [
- 'id' => (int)getProp($item, 'id'),
- 'type' => $type,
- 'type_label' => self::TYPE_LABELS[$type] ?? $type,
- 'api_type' => getProp($item, 'api_type'),
- 'task_id' => (int)getProp($item, 'task_id'),
- 'charge_info' => [
- 'model' => getProp($chargeInfo, 'model'),
- 'modality' => getProp($chargeInfo, 'modality'),
- 'video_resolution' => getProp($chargeInfo, 'video_resolution'),
- 'video_duration' => getProp($chargeInfo, 'video_duration'),
- 'ratio' => getProp($chargeInfo, 'ratio'),
- ],
- 'points_consumed' => (float)getProp($item, 'points_consumed', 0),
- 'points_before' => (float)getProp($item, 'points_before', 0),
- 'points_after' => (float)getProp($item, 'points_after', 0),
- 'tokens_consumed' => (int)getProp($item, 'tokens_consumed', 0),
- 'remark' => getProp($item, 'remark'),
- 'created_at' => getProp($item, 'created_at'),
- ];
- }
- return $result;
- }
- }
|