[新增] first commit
This commit is contained in:
89
app/Models/ActivityCoupon.php
Normal file
89
app/Models/ActivityCoupon.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user