Files
pingan_new/app/Models/ActivityCoupon.php
2020-10-13 08:49:57 +08:00

90 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use App\Models\Traits\BelongsToActivity;
use App\Models\Traits\BelongsToOutlet;
class ActivityCoupon extends Model
{
use BelongsToOutlet, BelongsToActivity;
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 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();
}
/**
* Notes: 是否可以撤销
* @Author: 玄尘
* @Date : 2020/10/12 11:57
* @return bool
*/
public function canReversal()
{
return $this->status == self::STATUS_USED;
}
/**
* Notes: 撤销
* @Author: 玄尘
* @Date : 2020/10/12 13:56
*/
public function reversal()
{
$this->status = self::STATUS_INIT;
$this->save();
}
}