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\Repositories\Eloquent; |
13
|
|
|
|
14
|
|
|
use Carbon\Carbon; |
15
|
|
|
use iBrand\Component\Discount\Models\Coupon; |
16
|
|
|
use iBrand\Component\Discount\Repositories\CouponRepository; |
17
|
|
|
use Prettus\Repository\Eloquent\BaseRepository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class CouponRepositoryEloquent. |
21
|
|
|
*/ |
22
|
|
|
class CouponRepositoryEloquent extends BaseRepository implements CouponRepository |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Specify Model class name. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
4 |
|
public function model() |
30
|
|
|
{ |
31
|
4 |
|
return Coupon::class; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param $userId |
36
|
|
|
* @param int $paginate |
37
|
|
|
* @param string $channel |
|
|
|
|
38
|
|
|
* |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
4 |
|
public function findActiveByUser($userId, $paginate = 15) |
42
|
|
|
{ |
43
|
4 |
|
$res = $this->model->where('user_id', $userId)->whereNull('used_at') |
44
|
4 |
|
->where(function ($query) { |
45
|
4 |
|
$query->whereNull('expires_at') |
46
|
4 |
|
->orWhere(function ($query) { |
47
|
4 |
|
$query->where('expires_at', '>', Carbon::now()); |
48
|
4 |
|
}); |
49
|
4 |
|
}) |
50
|
4 |
|
->with('discount', 'discount.rules', 'discount.actions') |
51
|
|
|
->whereHas('discount', function ($query) { |
52
|
4 |
|
$query->where(function ($query) { |
53
|
4 |
|
$query->whereNull('useend_at') |
54
|
4 |
|
->orWhere(function ($query) { |
55
|
4 |
|
$query->where('useend_at', '>', Carbon::now()); |
56
|
4 |
|
}); |
57
|
4 |
|
})->where('status', 1); |
58
|
4 |
|
}); |
59
|
|
|
|
60
|
4 |
|
if (!$paginate) { |
61
|
3 |
|
return $res->get(); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
return $res->paginate($paginate); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $userId |
69
|
|
|
* @param int $paginate |
70
|
|
|
* |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
1 |
|
public function findInvalidByUser($userId, $paginate = 15) |
74
|
|
|
{ |
75
|
1 |
|
return $this->model->where('user_id', $userId)->whereNull('used_at') |
76
|
1 |
|
->with('discount', 'discount.rules', 'discount.actions') |
77
|
|
|
->where(function ($query) { |
78
|
1 |
|
$query->where(function ($query) { |
79
|
1 |
|
$query->whereNotNull('expires_at')->where('expires_at', '<=', Carbon::now()); |
80
|
1 |
|
}) |
81
|
|
|
->orWhere(function ($query) { |
82
|
1 |
|
$query->whereHas('discount', function ($query) { |
83
|
1 |
|
$query->where('status', 0)->orWhere('useend_at', '<=', Carbon::now()); |
84
|
1 |
|
}); |
85
|
1 |
|
}); |
86
|
1 |
|
})->paginate($paginate); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* 获取已使用的优惠券. |
91
|
|
|
* |
92
|
|
|
* @param $userId |
93
|
|
|
* @param int $paginate |
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
1 |
|
public function findUsedByUser($userId, $paginate = 15) |
98
|
|
|
{ |
99
|
1 |
|
return $this->model->where('user_id', $userId)->whereNotNull('used_at') |
100
|
1 |
|
->with('discount', 'discount.rules', 'discount.actions') |
101
|
1 |
|
->paginate($paginate); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.