Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
d3ccabbf
Commit
d3ccabbf
authored
Dec 23, 2018
by
Junling Bu
Browse files
feat[litemall-wx, litemall-wx-api]: 小商场前端支持兑换码优惠券
parent
cd24f3d6
Changes
7
Hide whitespace changes
Inline
Side-by-side
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/util/WxResponseCode.java
View file @
d3ccabbf
...
...
@@ -31,5 +31,7 @@ public class WxResponseCode {
public
static
final
int
COUPON_EXCEED_LIMIT
=
740
;
public
static
final
int
COUPON_RECEIVE_FAIL
=
741
;
public
static
final
int
COUPON_CODE_INVALID
=
742
;
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCouponController.java
View file @
d3ccabbf
...
...
@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.validation.constraints.NotNull
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -113,14 +114,14 @@ public class WxCouponController {
couponVo
.
setMin
(
coupon
.
getMin
().
toPlainString
());
couponVo
.
setDiscount
(
coupon
.
getDiscount
().
toPlainString
());
Short
days
=
coupon
.
get
Days
();
if
(
days
==
0
)
{
Short
timeType
=
coupon
.
get
TimeType
();
if
(
timeType
.
equals
(
CouponConstant
.
TIME_TYPE_TIME
)
)
{
couponVo
.
setStartTime
(
coupon
.
getStartTime
());
couponVo
.
setEndTime
(
coupon
.
getEndTime
());
}
else
{
couponVo
.
setStartTime
(
coupon
.
getAddTime
());
couponVo
.
setEndTime
(
coupon
.
getAddTime
().
plusDays
(
d
ays
));
couponVo
.
setEndTime
(
coupon
.
getAddTime
().
plusDays
(
coupon
.
getD
ays
()
));
}
couponVoList
.
add
(
couponVo
);
}
...
...
@@ -231,6 +232,9 @@ public class WxCouponController {
if
(
type
.
equals
(
CouponConstant
.
TYPE_REGISTER
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"新用户优惠券自动发送"
);
}
else
if
(
type
.
equals
(
CouponConstant
.
TYPE_CODE
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"优惠券只能兑换"
);
}
else
if
(!
type
.
equals
(
CouponConstant
.
TYPE_COMMON
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"优惠券类型不支持"
);
}
...
...
@@ -240,7 +244,77 @@ public class WxCouponController {
if
(
status
.
equals
(
CouponConstant
.
STATUS_OUT
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_EXCEED_LIMIT
,
"优惠券已领完"
);
}
if
(
status
.
equals
(
CouponConstant
.
STATUS_EXPIRED
)){
else
if
(
status
.
equals
(
CouponConstant
.
STATUS_EXPIRED
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"优惠券已经过期"
);
}
// 用户领券记录
LitemallCouponUser
couponUser
=
new
LitemallCouponUser
();
couponUser
.
setCouponId
(
couponId
);
couponUser
.
setUserId
(
userId
);
couponUserService
.
add
(
couponUser
);
return
ResponseUtil
.
ok
();
}
/**
* 优惠券兑换
*
* @param userId 用户ID
* @param body 请求内容, { code: xxx }
* @return 操作结果
*/
@PostMapping
(
"exchange"
)
public
Object
exchange
(
@LoginUser
Integer
userId
,
@RequestBody
String
body
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
String
code
=
JacksonUtil
.
parseString
(
body
,
"code"
);
if
(
code
==
null
){
return
ResponseUtil
.
badArgument
();
}
LitemallCoupon
coupon
=
couponService
.
findByCode
(
code
);
if
(
coupon
==
null
){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_CODE_INVALID
,
"优惠券不正确"
);
}
Integer
couponId
=
coupon
.
getId
();
// 当前已领取数量和总数量比较
Integer
total
=
coupon
.
getTotal
();
Integer
totalCoupons
=
couponUserService
.
countCoupon
(
couponId
);
if
((
total
!=
0
)
&&
(
totalCoupons
>=
total
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_EXCEED_LIMIT
,
"优惠券已兑换"
);
}
// 当前用户已领取数量和用户限领数量比较
Integer
limit
=
coupon
.
getLimit
().
intValue
();
Integer
userCounpons
=
couponUserService
.
countUserAndCoupon
(
userId
,
couponId
);
if
((
limit
!=
0
)
&&
(
userCounpons
>=
limit
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_EXCEED_LIMIT
,
"优惠券已兑换"
);
}
// 优惠券分发类型
// 例如注册赠券类型的优惠券不能领取
Short
type
=
coupon
.
getType
();
if
(
type
.
equals
(
CouponConstant
.
TYPE_REGISTER
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"新用户优惠券自动发送"
);
}
else
if
(
type
.
equals
(
CouponConstant
.
TYPE_COMMON
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"优惠券只能领取,不能兑换"
);
}
else
if
(!
type
.
equals
(
CouponConstant
.
TYPE_CODE
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"优惠券类型不支持"
);
}
// 优惠券状态,已下架或者过期不能领取
Short
status
=
coupon
.
getStatus
();
if
(
status
.
equals
(
CouponConstant
.
STATUS_OUT
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_EXCEED_LIMIT
,
"优惠券已兑换"
);
}
else
if
(
status
.
equals
(
CouponConstant
.
STATUS_EXPIRED
)){
return
ResponseUtil
.
fail
(
WxResponseCode
.
COUPON_RECEIVE_FAIL
,
"优惠券已经过期"
);
}
...
...
litemall-wx/config/api.js
View file @
d3ccabbf
...
...
@@ -93,6 +93,7 @@ module.exports = {
CouponMyList
:
WxApiRoot
+
'
coupon/mylist
'
,
//我的优惠券列表
CouponSelectList
:
WxApiRoot
+
'
coupon/selectlist
'
,
//当前订单可用优惠券列表
CouponReceive
:
WxApiRoot
+
'
coupon/receive
'
,
//优惠券领取
CouponExchange
:
WxApiRoot
+
'
coupon/exchange
'
,
//优惠券兑换
StorageUpload
:
WxApiRoot
+
'
storage/upload
'
,
//图片上传,
...
...
litemall-wx/pages/ucenter/couponList/couponList.js
View file @
d3ccabbf
...
...
@@ -6,6 +6,7 @@ var app = getApp();
Page
({
data
:
{
couponList
:
[],
code
:
''
,
status
:
0
,
page
:
1
,
size
:
10
,
...
...
@@ -78,13 +79,6 @@ Page({
showPage
:
false
,
couponList
:
[]
});
// 页面渲染完成
wx
.
showToast
({
title
:
'
加载中...
'
,
icon
:
'
loading
'
,
duration
:
2000
});
util
.
request
(
api
.
CouponMyList
,
{
status
:
that
.
data
.
status
,
page
:
that
.
data
.
page
,
...
...
@@ -99,20 +93,40 @@ Page({
count
:
res
.
data
.
count
});
}
wx
.
hideToast
();
});
},
goExchange
:
function
()
{
wx
.
showToast
({
title
:
'
目前不支持
'
,
icon
:
'
none
'
,
duration
:
2000
bindExchange
:
function
(
e
)
{
this
.
setData
({
code
:
e
.
detail
.
value
});
},
clearExchange
:
function
()
{
this
.
setData
({
code
:
''
});
},
goUse
:
function
()
{
wx
.
reLaunch
({
url
:
'
/pages/index/index
'
goExchange
:
function
()
{
if
(
this
.
data
.
code
.
length
===
0
)
{
util
.
showErrorToast
(
"
请输入兑换码
"
);
return
;
}
let
that
=
this
;
util
.
request
(
api
.
CouponExchange
,
{
code
:
that
.
data
.
code
},
'
POST
'
).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
that
.
getCouponList
();
that
.
clearExchange
();
wx
.
showToast
({
title
:
"
领取成功
"
,
duration
:
2000
})
}
else
{
util
.
showErrorToast
(
res
.
errmsg
);
}
});
},
nextPage
:
function
(
event
)
{
...
...
litemall-wx/pages/ucenter/couponList/couponList.wxml
View file @
d3ccabbf
...
...
@@ -16,8 +16,8 @@
<view class="coupon-form" wx:if="{{status == 0}}">
<view class="input-box">
<input class="coupon-sn" placeholder="请输入优惠码" />
<image class="clear-icon"
src="http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/clear-fb-dd9d604f86.p
ng"></image>
<input class="coupon-sn" placeholder="请输入优惠码"
value="{{code}}" bindinput="bindExchange"
/>
<image class="clear-icon"
wx:if="{{ code.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearExcha
ng
e
"></image>
</view>
<view class="add-btn" bindtap='goExchange'>兑换</view>
</view>
...
...
litemall-wx/pages/ucenter/couponList/couponList.wxss
View file @
d3ccabbf
...
...
@@ -84,10 +84,13 @@ page {
.container .b .clear-icon {
position: absolute;
top: 21rpx;
right: 30rpx;
width: 28rpx;
height: 28rpx;
top: 10rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.container .b .add-btn {
...
...
litemall-wx/project.config.json
View file @
d3ccabbf
...
...
@@ -29,7 +29,7 @@
"list"
:
[]
},
"miniprogram"
:
{
"current"
:
37
,
"current"
:
22
,
"list"
:
[
{
"id"
:
-1
,
...
...
@@ -164,9 +164,9 @@
"query"
:
"orderId=2&type=0&valueId=1116011"
},
{
"id"
:
-1
,
"id"
:
22
,
"name"
:
"我的优惠券"
,
"pathName"
:
"pages/ucenter/coupon/coupon"
,
"pathName"
:
"pages/ucenter/coupon
List
/coupon
List
"
,
"query"
:
""
},
{
...
...
@@ -256,7 +256,8 @@
{
"id"
:
-1
,
"name"
:
"优惠券列表"
,
"pathName"
:
"pages/coupon/coupon"
"pathName"
:
"pages/coupon/coupon"
,
"query"
:
""
}
]
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment