Favorite.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Models;
use App\Models\EpGiftCard\EpGiftCard;
use App\Models\GiftCard\GiftCard;
use App\Models\Goods\Goods;
use App\Models\Groupon\Goods as GrouponGoods;
use App\Models\Groupon\Activity;
use App\Models\PointsMall\Goods as PointsMallGoods;
use App\Models\Traits\MorphMapTrait;
use App\Models\User\User;
use Encore\Admin\Traits\DefaultDatetimeFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Favorite extends Model
{
use MorphMapTrait;
// add by Richer 于 2022年4月13日16:45:14 解决时间展示问题
use DefaultDatetimeFormat;
// 指定数据库表
const TABLE = 'favorites';
protected $table = self::TABLE ;
// 指定对象显示名称:方便系统统一查询和做其他处理
const OBJ_NAME = 'favorite';
const OBJ_NAME_ZH = '收藏';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id', 'enterprise_id','product_id','favoriteable_type', 'favoriteable_id', 'status'
];
/**
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
/**
* @return MorphTo
*/
public function favoriteable(): MorphTo
{
return $this->morphTo();
}
/**
* @return HasMany
*/
public function records(): HasMany
{
return $this->hasMany(Favorite::class, 'product_id', 'product_id');
}
/**
* 获取 type options
*
* @return array
*/
public static function getClassType()
{
return [
Goods::OBJ_NAME => Goods::class,
GiftCard::OBJ_NAME => GiftCard::class,
EpGiftCard::OBJ_NAME => EpGiftCard::class,
PointsMallGoods::OBJ_NAME => PointsMallGoods::class,
GrouponGoods::OBJ_NAME => GrouponGoods::class,
];
}
/**
* 获取 type options
*
* @return array
*/
public static function getType()
{
return [
Goods::OBJ_NAME => Goods::OBJ_NAME_ZH,
GiftCard::OBJ_NAME => GiftCard::OBJ_NAME_ZH,
EpGiftCard::OBJ_NAME => EpGiftCard::OBJ_NAME_ZH,
PointsMallGoods::OBJ_NAME => PointsMallGoods::OBJ_NAME_ZH,
GrouponGoods::OBJ_NAME => GrouponGoods::OBJ_NAME_ZH,
];
return self::getMorphTypeZHOptions();
}
}