104 lines
2.3 KiB
PHP
104 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Traits\BelongsToUser;
|
|
|
|
class WoCoupon extends Model
|
|
{
|
|
|
|
use BelongsToUser;
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
self::created(function ($model) {
|
|
$model->log()->create([
|
|
'type' => $model->service,
|
|
'mobile' => $model->mobile,
|
|
]);
|
|
});
|
|
|
|
}
|
|
|
|
public function getStatusTextAttribute()
|
|
{
|
|
switch ($this->status) {
|
|
case 0:
|
|
return '未使用';
|
|
break;
|
|
case 1:
|
|
if ($this->service == 'ticketGrant') {
|
|
return '发券成功';
|
|
} else {
|
|
return '退订成功';
|
|
}
|
|
|
|
break;
|
|
case 2:
|
|
return '发券失败';
|
|
break;
|
|
case 3:
|
|
return '退订成功';
|
|
break;
|
|
default:
|
|
return '未知状态';
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function getServiceTextAttribute()
|
|
{
|
|
switch ($this->service) {
|
|
case 'ticketGrant':
|
|
return '发券请求';
|
|
break;
|
|
case 'ticketBuyback':
|
|
return '返销请求';
|
|
break;
|
|
case 'ticketInvalid':
|
|
return '作废请求';
|
|
break;
|
|
case 'ticketQuery':
|
|
return '查询请求';
|
|
break;
|
|
default:
|
|
return '未知状态';
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function getActivityTextAttribute()
|
|
{
|
|
switch ($this->activityId) {
|
|
case '97LJ202025':
|
|
return '25元兑换券';
|
|
break;
|
|
case '97LJ202010':
|
|
return '100元兑换券';
|
|
break;
|
|
case '97LJ202018':
|
|
return '180元话费券';
|
|
break;
|
|
case '97LJ202001':
|
|
return '10元购物券';
|
|
break;
|
|
default:
|
|
return '未知活动';
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function log()
|
|
{
|
|
return $this->hasOne(WoCouponLog::class);
|
|
}
|
|
|
|
public function logs()
|
|
{
|
|
return $this->hasMany(WoCouponLog::class, 'mobile', 'mobile');
|
|
}
|
|
|
|
}
|