Files
pingan_new/app/Models/ActivityCoupon.php

78 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use App\Models\Traits\BelongsToOutlet;
class ActivityCoupon extends Model
{
use BelongsToOutlet;
protected $dates = [
'start_at',
'end_at',
'used_at',
];
const STATUS_INIT = 1;
const STATUS_USED = 2;
const STATUS_CLOSE = 3;
const STATUS = [
self::STATUS_INIT => '未使用',
self::STATUS_USED => '已使用',
self::STATUS_CLOSE => '已作废',
];
/**
* 默认加载的关联
* @var array
*/
protected $with = ['activity'];
/**
* Notes: 关联活动
* @Author: 玄尘
* @Date : 2020/6/30 9:40
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function activity()
{
return $this->belongsTo(Activity::class);
}
/**
* Notes: 卡券状态
* @Author: 玄尘
* @Date : 2020/6/30 9:40
* @return string
*/
public function getStatusTextAttribute()
{
return self::STATUS[$this->status] ?? '未知';
}
/**
* Notes: 是否可以核销
* @Author: 玄尘
* @Date : 2020/6/30 9:41
* @return bool
*/
public function canRedemption()
{
return $this->status == ActivityCoupon::STATUS_INIT;
}
/**
* Notes: 是否可以销毁
* @Author: 玄尘
* @Date : 2020/6/30 9:41
* @return bool
*/
public function canDestroy()
{
return $this->canRedemption();
}
}