* @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; $valid_days_end_time = null; if($model->valid_type == CouponsUserBag::VALID_TYPE_RELATIVE){ $valid_days_end_time = Carbon::make($model->created_at)->addDays($model->valid_days)->format('Y-m-d'); } 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, 'valid_days_end_time' => $valid_days_end_time, '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], ];//$model->toArray(); } }