1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- /**
- *
- *
- * @category xxx
- * @package PSR
- * @subpackage Documentation\API
- * @author xxx <xxx@xxx.com>
- * @license GPL https://xxx.com
- * @link https://xxx.com
- * @ctime: 2020/4/7 13:55
- */
- namespace App\Transformers;
- use App\Models\Coupon;
- use App\Models\CouponsUserBag;
- use Carbon\Carbon;
- use League\Fractal\TransformerAbstract;
- class CouponsUserBagsTransformer extends TransformerAbstract
- {
- public function transform(CouponsUserBag $model)
- {
- $coupon = $model->coupons_data;
- return [
- 'id' => $model->id,
- 'get_type_name' => CouponsUserBag::$typeMaps[$model->type],
- 'type' => $coupon['type'],
- 'type_name' => Coupon::$typeMaps[$coupon['type']],
- 'valid_type_name' => CouponsUserBag::$validTypeMaps[$model->valid_type],
- 'valid_type' => $model->valid_type,
- 'valid_start_time' => Carbon::make($model->valid_start_time)->format('Y-m-d'),
- 'valid_end_time' => Carbon::make($model->valid_end_time)->format('Y-m-d'),
- 'valid_days' => $model->valid_days,
- 'created_at' => Carbon::make($model->created_at)->format('Y-m-d'),
- 'with_amount' => $coupon['with_amount'],
- 'used_amount' => $coupon['used_amount'],
- 'discount' => $coupon['discount'] / 10,
- 'order_type' => $model->order_type,
- 'order_type_name' => CouponsUserBag::$orderTypeMaps[$model->order_type],
- ];
- }
- }
|