CouponsUserBagsTransformer.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. *
  4. *
  5. * @category xxx
  6. * @package PSR
  7. * @subpackage Documentation\API
  8. * @author xxx <xxx@xxx.com>
  9. * @license GPL https://xxx.com
  10. * @link https://xxx.com
  11. * @ctime: 2020/4/7 13:55
  12. */
  13. namespace App\Transformers;
  14. use App\Models\Coupon;
  15. use App\Models\CouponsUserBag;
  16. use Carbon\Carbon;
  17. use League\Fractal\TransformerAbstract;
  18. class CouponsUserBagsTransformer extends TransformerAbstract
  19. {
  20. public function transform(CouponsUserBag $model)
  21. {
  22. $coupon = $model->coupons_data;
  23. return [
  24. 'id' => $model->id,
  25. 'get_type_name' => CouponsUserBag::$typeMaps[$model->type],
  26. 'type' => $coupon['type'],
  27. 'type_name' => Coupon::$typeMaps[$coupon['type']],
  28. 'valid_type_name' => CouponsUserBag::$validTypeMaps[$model->valid_type],
  29. 'valid_type' => $model->valid_type,
  30. 'valid_start_time' => Carbon::make($model->valid_start_time)->format('Y-m-d'),
  31. 'valid_end_time' => Carbon::make($model->valid_end_time)->format('Y-m-d'),
  32. 'valid_days' => $model->valid_days,
  33. 'created_at' => Carbon::make($model->created_at)->format('Y-m-d'),
  34. 'with_amount' => $coupon['with_amount'],
  35. 'used_amount' => $coupon['used_amount'],
  36. 'discount' => $coupon['discount'] / 10,
  37. 'order_type' => $model->order_type,
  38. 'order_type_name' => CouponsUserBag::$orderTypeMaps[$model->order_type],
  39. ];
  40. }
  41. }