1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of ibrand/discount. |
5
|
|
|
* |
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace iBrand\Component\Discount\Models; |
13
|
|
|
|
14
|
|
|
use Carbon\Carbon; |
15
|
|
|
use iBrand\Component\Discount\Contracts\DiscountContract; |
16
|
|
|
use Illuminate\Database\Eloquent\Model; |
17
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
18
|
|
|
|
19
|
|
|
class Coupon extends Model implements DiscountContract |
20
|
|
|
{ |
21
|
|
|
use SoftDeletes; |
22
|
|
|
|
23
|
|
|
protected $guarded = ['id', 'orderAmountLimit']; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Address constructor. |
27
|
|
|
* |
28
|
|
|
* @param array $attributes |
29
|
|
|
*/ |
30
|
14 |
|
public function __construct(array $attributes = []) |
31
|
|
|
{ |
32
|
14 |
|
$this->setTable(config('ibrand.app.database.prefix', 'ibrand_').'discount_coupon'); |
33
|
|
|
|
34
|
14 |
|
parent::__construct($attributes); |
35
|
14 |
|
} |
36
|
|
|
|
37
|
6 |
|
public function discount() |
38
|
|
|
{ |
39
|
6 |
|
return $this->belongsTo(Discount::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function hasRules() |
46
|
|
|
{ |
47
|
|
|
return 0 !== $this->discount->rules()->count(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
public function isCouponBased() |
51
|
|
|
{ |
52
|
1 |
|
return $this->discount->coupon_based; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
public function getLabelAttribute() |
56
|
|
|
{ |
57
|
1 |
|
return $this->discount->label; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getStartsAtAttribute() |
61
|
|
|
{ |
62
|
|
|
return $this->getStartsAt(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getEndsAtAttribute() |
66
|
|
|
{ |
67
|
|
|
return $this->getEndsAt(); |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
public function getActions() |
71
|
|
|
{ |
72
|
1 |
|
return $this->discount->getActions(); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getRules() |
76
|
|
|
{ |
77
|
|
|
return $this->discount->rules; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
public function setCouponUsed() |
81
|
|
|
{ |
82
|
1 |
|
$this->used_at = Carbon::now(); |
|
|
|
|
83
|
1 |
|
$this->save(); |
84
|
1 |
|
} |
85
|
|
|
|
86
|
2 |
|
public function getStartsAt() |
87
|
|
|
{ |
88
|
2 |
|
return $this->discount->usestart_at; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
public function getEndsAt() |
92
|
|
|
{ |
93
|
2 |
|
if (empty($this->expires_at)) { |
|
|
|
|
94
|
2 |
|
return $this->discount->useend_at; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
return $this->expires_at; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
|
|
public function getUsed() |
104
|
|
|
{ |
105
|
|
|
// TODO: Implement getUsed() method. |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function getUsageLimit() |
112
|
|
|
{ |
113
|
|
|
// TODO: Implement getUsageLimit() method. |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.