<?php
/**
 * Created by PhpStorm.
 * User: zilongs
 * Date: 20-10-24
 * Time: 上午11:16
 */

namespace App\Models;

class Coupon extends BaseModel
{
    protected $appends = ['is_receive'];

    public function getIsReceiveAttribute()
    {
        $user = User::getUserByToken(false);
        if (!empty($user)) {
            if (UserCoupon::where('user_id', $user['id'])->where('coupon_id', $this->id)->exists()) {
                return 1;
            }
        }

        return 0;
    }
    public function couponType (){
        return $this->hasMany(CouponType::class);
    }
}
