1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Repositories\Transformers;
- use App\Models\Card;
- use App\Repositories\Enums\ModelStatusEnum;
- use League\Fractal\TransformerAbstract;
- class CardTransformer extends TransformerAbstract
- {
- public function transform(Card $card)
- {
- $data = [
- 'id' => $card->id,
- 'name' => $card->name,
- 'money' => $card->money,
- 'time' => $card->time,
- 'valid_time' => $card->valid_time,
- 'discount' => $card->discount,
- 'price' => bcdiv($card->money * $card->discount, 100, 2),
- 'status' => $card->status,
- 'status_text' => ModelStatusEnum::getDescription($card->status),
- 'created_at' => $card->created_at,
- 'updated_at' => $card->updated_at
- ];
- return $data;
- }
- }
|