FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SSRPanel/app/Http/Controllers/CouponController.php at master · programmejava/SSRPanel · GitHub
programmejava
SSRPanel
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
SSRPanel
/
app
/
Http
/
Controllers
/
CouponController.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
156 lines (129 loc) · 5.52 KB
Breadcrumbs
SSRPanel
/
app
/
Http
/
Controllers
/
CouponController.php
Copy path
File metadata and controls
156 lines (129 loc) · 5.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace
App
\
Http
\
Controllers
;
use
App
\
Http
\
Models
\
Coupon
;
use
Illuminate
\
Http
\
Request
;
use
Maatwebsite
\
Excel
\
Facades
\
Excel
;
use
Response
;
use
Redirect
;
use
DB
;
use
Log
;
/**
* 优惠券控制器
* Class LoginController
* @package App\Http\Controllers
*/
class
CouponController
extends
Controller
{
protected
static
$
config
;
function
__construct
()
{
self
::
$
config
=
$
this
->
systemConfig
();
}
// 优惠券列表
public
function
couponList
(
Request
$
request
)
{
$
couponList
=
Coupon
::
query
()->
where
(
'
is_del
'
,
0
)->
orderBy
(
'
id
'
,
'
desc
'
)->
paginate
(
10
);
foreach
(
$
couponList
as
$
coupon
) {
$
coupon
->
amount
=
$
coupon
->
amount
/
100
;
}
$
view
[
'
couponList
'
] =
$
couponList
;
return
Response
::
view
(
'
coupon/couponList
'
,
$
view
);
}
// 添加商品
public
function
addCoupon
(
Request
$
request
)
{
if
(
$
request
->
method
() ==
'
POST
'
) {
$
name
=
$
request
->
get
(
'
name
'
);
$
type
=
$
request
->
get
(
'
type
'
,
1
);
$
usage
=
$
request
->
get
(
'
usage
'
,
1
);
$
num
=
$
request
->
get
(
'
num
'
,
1
);
$
amount
=
$
request
->
get
(
'
amount
'
);
$
discount
=
$
request
->
get
(
'
discount
'
);
$
available_start
=
$
request
->
get
(
'
available_start
'
);
$
available_end
=
$
request
->
get
(
'
available_end
'
);
if
(
empty
(
$
num
) || (
empty
(
$
amount
) &&
empty
(
$
discount
)) ||
empty
(
$
available_start
) ||
empty
(
$
available_end
)) {
$
request
->
session
()->
flash
(
'
errorMsg
'
,
'
请填写完整
'
);
return
Redirect
::
back
()->
withInput
();
}
if
(
strtotime
(
$
available_start
) >=
strtotime
(
$
available_end
)) {
$
request
->
session
()->
flash
(
'
errorMsg
'
,
'
有效期范围错误
'
);
return
Redirect
::
back
()->
withInput
();
}
// 商品LOGO
$
logo
=
''
;
if
(
$
request
->
hasFile
(
'
logo
'
)) {
$
file
=
$
request
->
file
(
'
logo
'
);
$
fileType
=
$
file
->
getClientOriginalExtension
();
$
logoName
=
date
(
'
YmdHis
'
) .
mt_rand
(
1000
,
2000
) .
'
.
'
.
$
fileType
;
$
move
=
$
file
->
move
(
base_path
() .
'
/public/upload/image/coupon/
'
,
$
logoName
);
$
logo
=
$
move
?
'
/upload/image/coupon/
'
.
$
logoName
:
''
;
}
DB
::
beginTransaction
();
try
{
for
(
$
i
=
0
;
$
i
<
$
num
;
$
i
++) {
$
obj
=
new
Coupon
();
$
obj
->
name
=
$
name
;
$
obj
->
sn
=
strtoupper
(
$
this
->
makeRandStr
(
7
));
$
obj
->
logo
=
$
logo
;
$
obj
->
type
=
$
type
;
$
obj
->
usage
=
$
usage
;
$
obj
->
amount
=
empty
(
$
amount
) ?
0
:
$
amount
*
100
;
$
obj
->
discount
=
empty
(
$
discount
) ?
0
:
$
discount
/
10
;
$
obj
->
available_start
=
strtotime
(
date
(
'
Y-m-d 0:0:0
'
,
strtotime
(
$
available_start
)));
$
obj
->
available_end
=
strtotime
(
date
(
'
Y-m-d 23:59:59
'
,
strtotime
(
$
available_end
)));
$
obj
->
status
=
0
;
$
obj
->
save
();
}
DB
::
commit
();
$
request
->
session
()->
flash
(
'
successMsg
'
,
'
生成成功
'
);
}
catch
(
\
Exception
$
e
) {
DB
::
rollBack
();
Log
::
error
(
'
生成优惠券失败:
'
.
$
e
->
getMessage
());
$
request
->
session
()->
flash
(
'
errorMsg
'
,
'
生成失败:
'
.
$
e
->
getMessage
());
}
return
Redirect
::
to
(
'
coupon/addCoupon
'
);
}
else
{
return
Response
::
view
(
'
coupon/addCoupon
'
);
}
}
// 删除优惠券
public
function
delCoupon
(
Request
$
request
)
{
$
id
=
$
request
->
get
(
'
id
'
);
Coupon
::
query
()->
where
(
'
id
'
,
$
id
)->
update
([
'
is_del
'
=>
1
]);
return
Response
::
json
([
'
status
'
=>
'
success
'
,
'
data
'
=>
''
,
'
message
'
=>
'
删除成功
'
]);
}
// 导出优惠券
public
function
exportCoupon
(
Request
$
request
)
{
$
cashCouponList
=
Coupon
::
query
()->
where
(
'
is_del
'
,
0
)->
where
(
'
status
'
,
0
)->
where
(
'
type
'
,
1
)->
get
();
$
discountCouponList
=
Coupon
::
query
()->
where
(
'
is_del
'
,
0
)->
where
(
'
status
'
,
0
)->
where
(
'
type
'
,
2
)->
get
();
$
filename
=
'
卡券
'
.
date
(
'
Ymd
'
);
Excel
::
create
(
$
filename
,
function
(
$
excel
)
use
(
$
cashCouponList
,
$
discountCouponList
) {
$
excel
->
sheet
(
'
现金券
'
,
function
(
$
sheet
)
use
(
$
cashCouponList
) {
$
sheet
->
row
(
1
,
array
(
'
名称
'
,
'
用途
'
,
'
有效期
'
,
'
券码
'
));
if
(!
$
cashCouponList
->
isEmpty
()) {
foreach
(
$
cashCouponList
as
$
k
=>
$
vo
) {
$
sheet
->
row
(
$
k
+
2
,
array
(
$
vo
->
name
,
$
vo
->
type
==
1
?
'
一次性
'
:
'
可重复
'
,
date
(
'
Y-m-d
'
,
$
vo
->
available_start
) .
'
~
'
.
date
(
'
Y-m-d
'
,
$
vo
->
available_end
),
$
vo
->
sn
));
}
}
});
$
excel
->
sheet
(
'
折扣券
'
,
function
(
$
sheet
)
use
(
$
discountCouponList
) {
$
sheet
->
row
(
1
,
array
(
'
名称
'
,
'
用途
'
,
'
有效期
'
,
'
券码
'
));
if
(!
$
discountCouponList
->
isEmpty
()) {
foreach
(
$
discountCouponList
as
$
k
=>
$
vo
) {
$
sheet
->
row
(
$
k
+
2
,
array
(
$
vo
->
name
,
$
vo
->
type
==
1
?
'
一次性
'
:
'
可重复
'
,
date
(
'
Y-m-d
'
,
$
vo
->
available_start
) .
'
~
'
.
date
(
'
Y-m-d
'
,
$
vo
->
available_end
),
$
vo
->
sn
));
}
}
});
})->
export
(
'
xls
'
);
}
}
Back
|
FazBrowse Home
|
New Git URL