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
7023b205
Unverified
Commit
7023b205
authored
Nov 17, 2019
by
staney
Committed by
GitHub
Nov 17, 2019
Browse files
Merge pull request #1 from linlinjava/master
同步更新代码
parents
c6ab92f9
506a8c01
Changes
66
Hide whitespace changes
Inline
Side-by-side
litemall-vue/src/views/order/payment/index.vue
View file @
7023b205
...
...
@@ -39,8 +39,9 @@
<
script
>
import
{
Radio
,
RadioGroup
,
Dialog
}
from
'
vant
'
;
import
{
orderDetail
,
orderPrepay
}
from
'
@/api/api
'
;
import
{
orderDetail
,
orderPrepay
,
orderH5pay
}
from
'
@/api/api
'
;
import
_
from
'
lodash
'
;
import
{
getLocalStorage
,
setLocalStorage
}
from
'
@/utils/local-storage
'
;
export
default
{
name
:
'
payment
'
,
...
...
@@ -72,20 +73,109 @@ export default {
Dialog
.
alert
({
message
:
'
你选择了
'
+
(
this
.
payWay
===
'
wx
'
?
'
微信支付
'
:
'
支付宝支付
'
)
}).
then
(()
=>
{
if
(
this
.
payWay
===
'
wx
'
)
{
let
ua
=
navigator
.
userAgent
.
toLowerCase
();
let
isWeixin
=
ua
.
indexOf
(
'
micromessenger
'
)
!=
-
1
;
if
(
isWeixin
)
{
orderPrepay
({
orderId
:
this
.
orderId
})
.
then
(
res
=>
{
let
data
=
res
.
data
.
data
;
let
prepay_data
=
JSON
.
stringify
({
appId
:
data
.
appId
,
timeStamp
:
data
.
timeStamp
,
nonceStr
:
data
.
nonceStr
,
package
:
data
.
packageValue
,
signType
:
'
MD5
'
,
paySign
:
data
.
paySign
});
setLocalStorage
({
prepay_data
:
prepay_data
});
this
.
$router
.
push
({
name
:
'
paymentStatus
'
,
params
:
{
status
:
'
success
'
if
(
typeof
WeixinJSBridge
==
'
undefined
'
)
{
if
(
document
.
addEventListener
)
{
document
.
addEventListener
(
'
WeixinJSBridgeReady
'
,
this
.
onBridgeReady
,
false
);
}
else
if
(
document
.
attachEvent
)
{
document
.
attachEvent
(
'
WeixinJSBridgeReady
'
,
this
.
onBridgeReady
);
document
.
attachEvent
(
'
onWeixinJSBridgeReady
'
,
this
.
onBridgeReady
);
}
}
else
{
this
.
onBridgeReady
();
}
})
.
catch
(
err
=>
{
Dialog
.
alert
({
message
:
err
.
data
.
errmsg
});
that
.
$router
.
replace
({
name
:
'
paymentStatus
'
,
params
:
{
status
:
'
failed
'
}
});
});
}
else
{
orderH5pay
({
orderId
:
this
.
orderId
})
.
then
(
res
=>
{
let
data
=
res
.
data
.
data
;
window
.
location
.
replace
(
data
.
mwebUrl
+
'
&redirect_url=
'
+
encodeURIComponent
(
window
.
location
.
origin
+
'
/#/?orderId=
'
+
this
.
orderId
+
'
&tip=yes
'
)
);
})
.
catch
(
err
=>
{
Dialog
.
alert
({
message
:
err
.
data
.
errmsg
});
});
}
});
}
else
{
//todo : alipay
}
});
// // 利用weixin-js-sdk调用微信支付
// orderPrepay({orderId: this.orderId}).then(res => {
// var payParams = res.data.data;
// });
},
onBridgeReady
()
{
let
that
=
this
;
let
data
=
getLocalStorage
(
'
prepay_data
'
);
// eslint-disable-next-line no-undef
WeixinJSBridge
.
invoke
(
'
getBrandWCPayRequest
'
,
JSON
.
parse
(
data
.
prepay_data
),
function
(
res
)
{
if
(
res
.
err_msg
==
'
get_brand_wcpay_request:ok
'
)
{
that
.
$router
.
replace
({
name
:
'
paymentStatus
'
,
params
:
{
status
:
'
success
'
}
});
}
else
if
(
res
.
err_msg
==
'
get_brand_wcpay_request:cancel
'
)
{
that
.
$router
.
replace
({
name
:
'
paymentStatus
'
,
params
:
{
status
:
'
cancel
'
}
});
}
else
{
that
.
$router
.
replace
({
name
:
'
paymentStatus
'
,
params
:
{
status
:
'
failed
'
}
});
}
}
);
}
},
...
...
litemall-vue/src/views/user/user-information-set/set-mobile/index.vue
View file @
7023b205
...
...
@@ -24,7 +24,7 @@
class=
"verifi_code red"
:class=
"
{verifi_code_counting: counting}"
@click="getCode">
<countdown
v-if=
"counting"
:time=
"60000"
@
countdown
end=
"countdownend"
>
<countdown
v-if=
"counting"
:time=
"60000"
@
end=
"countdownend"
>
<template
slot-scope=
"props"
>
{{
+
props
.
seconds
||
60
}}
秒后获取
</
template
>
</countdown>
<span
v-else
>
获取验证码
</span>
...
...
litemall-vue/src/views/user/user-information-set/set-password/index.vue
View file @
7023b205
...
...
@@ -19,7 +19,7 @@
class=
"verifi_code red"
:class=
"
{verifi_code_counting: counting}"
@click="getCode">
<countdown
v-if=
"counting"
:time=
"60000"
@
countdown
end=
"countdownend"
>
<countdown
v-if=
"counting"
:time=
"60000"
@
end=
"countdownend"
>
<template
slot-scope=
"props"
>
{{
+
props
.
seconds
||
60
}}
秒后获取
</
template
>
</countdown>
<span
v-else
>
获取验证码
</span>
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java
View file @
7023b205
...
...
@@ -3,6 +3,7 @@ package org.linlinjava.litemall.wx.service;
import
com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse
;
import
com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult
;
import
com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult
;
import
com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult
;
import
com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest
;
import
com.github.binarywang.wxpay.bean.result.BaseWxPayResult
;
import
com.github.binarywang.wxpay.constant.WxPayConstants
;
...
...
@@ -17,6 +18,7 @@ import org.linlinjava.litemall.core.notify.NotifyService;
import
org.linlinjava.litemall.core.notify.NotifyType
;
import
org.linlinjava.litemall.core.qcode.QCodeService
;
import
org.linlinjava.litemall.core.system.SystemConfig
;
import
org.linlinjava.litemall.core.task.TaskService
;
import
org.linlinjava.litemall.core.util.DateTimeUtil
;
import
org.linlinjava.litemall.core.util.JacksonUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
...
...
@@ -26,6 +28,7 @@ import org.linlinjava.litemall.db.util.CouponUserConstant;
import
org.linlinjava.litemall.db.util.OrderHandleOption
;
import
org.linlinjava.litemall.db.util.OrderUtil
;
import
org.linlinjava.litemall.core.util.IpUtil
;
import
org.linlinjava.litemall.wx.task.OrderUnpaidTask
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -104,6 +107,8 @@ public class WxOrderService {
private
LitemallCouponUserService
couponUserService
;
@Autowired
private
CouponVerifyService
couponVerifyService
;
@Autowired
private
TaskService
taskService
;
/**
* 订单列表
...
...
@@ -152,6 +157,7 @@ public class WxOrderService {
orderGoodsVo
.
put
(
"number"
,
orderGoods
.
getNumber
());
orderGoodsVo
.
put
(
"picUrl"
,
orderGoods
.
getPicUrl
());
orderGoodsVo
.
put
(
"specifications"
,
orderGoods
.
getSpecifications
());
orderGoodsVo
.
put
(
"price"
,
orderGoods
.
getPrice
());
orderGoodsVoList
.
add
(
orderGoodsVo
);
}
orderVo
.
put
(
"goodsList"
,
orderGoodsVoList
);
...
...
@@ -185,6 +191,7 @@ public class WxOrderService {
Map
<
String
,
Object
>
orderVo
=
new
HashMap
<
String
,
Object
>();
orderVo
.
put
(
"id"
,
order
.
getId
());
orderVo
.
put
(
"orderSn"
,
order
.
getOrderSn
());
orderVo
.
put
(
"message"
,
order
.
getMessage
());
orderVo
.
put
(
"addTime"
,
order
.
getAddTime
());
orderVo
.
put
(
"consignee"
,
order
.
getConsignee
());
orderVo
.
put
(
"mobile"
,
order
.
getMobile
());
...
...
@@ -239,6 +246,7 @@ public class WxOrderService {
Integer
cartId
=
JacksonUtil
.
parseInteger
(
body
,
"cartId"
);
Integer
addressId
=
JacksonUtil
.
parseInteger
(
body
,
"addressId"
);
Integer
couponId
=
JacksonUtil
.
parseInteger
(
body
,
"couponId"
);
Integer
userCouponId
=
JacksonUtil
.
parseInteger
(
body
,
"userCouponId"
);
String
message
=
JacksonUtil
.
parseString
(
body
,
"message"
);
Integer
grouponRulesId
=
JacksonUtil
.
parseInteger
(
body
,
"grouponRulesId"
);
Integer
grouponLinkId
=
JacksonUtil
.
parseInteger
(
body
,
"grouponLinkId"
);
...
...
@@ -300,7 +308,7 @@ public class WxOrderService {
BigDecimal
couponPrice
=
new
BigDecimal
(
0.00
);
// 如果couponId=0则没有优惠券,couponId=-1则不使用优惠券
if
(
couponId
!=
0
&&
couponId
!=
-
1
)
{
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponId
,
checkedGoodsPrice
);
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponId
,
userCouponId
,
checkedGoodsPrice
);
if
(
coupon
==
null
)
{
return
ResponseUtil
.
badArgumentValue
();
}
...
...
@@ -389,7 +397,7 @@ public class WxOrderService {
// 如果使用了优惠券,设置优惠券使用状态
if
(
couponId
!=
0
&&
couponId
!=
-
1
)
{
LitemallCouponUser
couponUser
=
couponUserService
.
queryOne
(
userId
,
c
ouponId
);
LitemallCouponUser
couponUser
=
couponUserService
.
findById
(
userC
ouponId
);
couponUser
.
setStatus
(
CouponUserConstant
.
STATUS_USED
);
couponUser
.
setUsedTime
(
LocalDateTime
.
now
());
couponUser
.
setOrderId
(
orderId
);
...
...
@@ -419,6 +427,9 @@ public class WxOrderService {
grouponService
.
createGroupon
(
groupon
);
}
// 订单支付超期任务
taskService
.
addTask
(
new
OrderUnpaidTask
(
orderId
));
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"orderId"
,
orderId
);
return
ResponseUtil
.
ok
(
data
);
...
...
@@ -560,6 +571,60 @@ public class WxOrderService {
return
ResponseUtil
.
ok
(
result
);
}
/**
* 微信H5支付
*
* @param userId
* @param body
* @param request
* @return
*/
@Transactional
public
Object
h5pay
(
Integer
userId
,
String
body
,
HttpServletRequest
request
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
Integer
orderId
=
JacksonUtil
.
parseInteger
(
body
,
"orderId"
);
if
(
orderId
==
null
)
{
return
ResponseUtil
.
badArgument
();
}
LitemallOrder
order
=
orderService
.
findById
(
orderId
);
if
(
order
==
null
)
{
return
ResponseUtil
.
badArgumentValue
();
}
if
(!
order
.
getUserId
().
equals
(
userId
))
{
return
ResponseUtil
.
badArgumentValue
();
}
// 检测是否能够取消
OrderHandleOption
handleOption
=
OrderUtil
.
build
(
order
);
if
(!
handleOption
.
isPay
())
{
return
ResponseUtil
.
fail
(
ORDER_INVALID_OPERATION
,
"订单不能支付"
);
}
WxPayMwebOrderResult
result
=
null
;
try
{
WxPayUnifiedOrderRequest
orderRequest
=
new
WxPayUnifiedOrderRequest
();
orderRequest
.
setOutTradeNo
(
order
.
getOrderSn
());
orderRequest
.
setTradeType
(
"MWEB"
);
orderRequest
.
setBody
(
"订单:"
+
order
.
getOrderSn
());
// 元转成分
int
fee
=
0
;
BigDecimal
actualPrice
=
order
.
getActualPrice
();
fee
=
actualPrice
.
multiply
(
new
BigDecimal
(
100
)).
intValue
();
orderRequest
.
setTotalFee
(
fee
);
orderRequest
.
setSpbillCreateIp
(
IpUtil
.
getIpAddr
(
request
));
result
=
wxPayService
.
createOrder
(
orderRequest
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
ResponseUtil
.
ok
(
result
);
}
/**
* 微信付款成功或失败回调接口
* <p>
...
...
@@ -612,7 +677,7 @@ public class WxOrderService {
}
// 检查这个订单是否已经处理过
if
(
OrderUtil
.
i
sPay
Status
(
order
)
&&
order
.
getPayId
()
!=
null
)
{
if
(
OrderUtil
.
ha
sPay
ed
(
order
))
{
return
WxPayNotifyResponse
.
success
(
"订单已经处理成功!"
);
}
...
...
@@ -658,6 +723,37 @@ public class WxOrderService {
if
(
grouponService
.
updateById
(
groupon
)
==
0
)
{
return
WxPayNotifyResponse
.
fail
(
"更新数据已失效"
);
}
// 团购已达成,更新关联订单支付状态
if
(
groupon
.
getGrouponId
()
>
0
)
{
List
<
LitemallGroupon
>
grouponList
=
grouponService
.
queryJoinRecord
(
groupon
.
getGrouponId
());
if
(
grouponList
.
size
()
>=
grouponRules
.
getDiscountMember
()
-
1
)
{
for
(
LitemallGroupon
grouponActivity
:
grouponList
)
{
if
(
grouponActivity
.
getOrderId
().
equals
(
order
.
getId
()))
{
//当前订单
continue
;
}
LitemallOrder
grouponOrder
=
orderService
.
findById
(
grouponActivity
.
getOrderId
());
if
(
grouponOrder
.
getOrderStatus
().
equals
(
OrderUtil
.
STATUS_PAY_GROUPON
))
{
grouponOrder
.
setOrderStatus
(
OrderUtil
.
STATUS_PAY
);
orderService
.
updateWithOptimisticLocker
(
grouponOrder
);
}
}
LitemallGroupon
grouponSource
=
grouponService
.
queryById
(
groupon
.
getGrouponId
());
LitemallOrder
grouponOrder
=
orderService
.
findById
(
grouponSource
.
getOrderId
());
if
(
grouponOrder
.
getOrderStatus
().
equals
(
OrderUtil
.
STATUS_PAY_GROUPON
))
{
grouponOrder
.
setOrderStatus
(
OrderUtil
.
STATUS_PAY
);
orderService
.
updateWithOptimisticLocker
(
grouponOrder
);
}
}
}
else
{
order
=
orderService
.
findBySn
(
orderSn
);
order
.
setOrderStatus
(
OrderUtil
.
STATUS_PAY_GROUPON
);
orderService
.
updateWithOptimisticLocker
(
order
);
}
}
//TODO 发送邮件和短信通知,这里采用异步发送
...
...
@@ -678,6 +774,9 @@ public class WxOrderService {
notifyService
.
notifyWxTemplate
(
result
.
getOpenid
(),
NotifyType
.
PAY_SUCCEED
,
parms
,
"pages/index/index?orderId="
+
order
.
getId
());
// 取消订单超时未支付任务
taskService
.
removeTask
(
new
OrderUnpaidTask
(
order
.
getId
()));
return
WxPayNotifyResponse
.
success
(
"处理成功!"
);
}
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/task/OrderUnpaidTask.java
0 → 100644
View file @
7023b205
package
org.linlinjava.litemall.wx.task
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.linlinjava.litemall.core.system.SystemConfig
;
import
org.linlinjava.litemall.core.task.Task
;
import
org.linlinjava.litemall.core.util.BeanUtil
;
import
org.linlinjava.litemall.db.domain.LitemallOrder
;
import
org.linlinjava.litemall.db.domain.LitemallOrderGoods
;
import
org.linlinjava.litemall.db.service.LitemallGoodsProductService
;
import
org.linlinjava.litemall.db.service.LitemallOrderGoodsService
;
import
org.linlinjava.litemall.db.service.LitemallOrderService
;
import
org.linlinjava.litemall.db.util.OrderUtil
;
import
java.time.LocalDateTime
;
import
java.util.List
;
public
class
OrderUnpaidTask
extends
Task
{
private
final
Log
logger
=
LogFactory
.
getLog
(
OrderUnpaidTask
.
class
);
private
int
orderId
=
-
1
;
public
OrderUnpaidTask
(
Integer
orderId
,
long
delayInMilliseconds
){
super
(
"OrderUnpaidTask-"
+
orderId
,
delayInMilliseconds
);
this
.
orderId
=
orderId
;
}
public
OrderUnpaidTask
(
Integer
orderId
){
super
(
"OrderUnpaidTask-"
+
orderId
,
SystemConfig
.
getOrderUnpaid
()
*
60
*
1000
);
this
.
orderId
=
orderId
;
}
@Override
public
void
run
()
{
logger
.
info
(
"系统开始处理延时任务---订单超时未付款---"
+
this
.
orderId
);
LitemallOrderService
orderService
=
BeanUtil
.
getBean
(
LitemallOrderService
.
class
);
LitemallOrderGoodsService
orderGoodsService
=
BeanUtil
.
getBean
(
LitemallOrderGoodsService
.
class
);
LitemallGoodsProductService
productService
=
BeanUtil
.
getBean
(
LitemallGoodsProductService
.
class
);
LitemallOrder
order
=
orderService
.
findById
(
this
.
orderId
);
if
(
order
==
null
){
return
;
}
if
(!
OrderUtil
.
isCreateStatus
(
order
)){
return
;
}
// 设置订单已取消状态
order
.
setOrderStatus
(
OrderUtil
.
STATUS_AUTO_CANCEL
);
order
.
setEndTime
(
LocalDateTime
.
now
());
if
(
orderService
.
updateWithOptimisticLocker
(
order
)
==
0
)
{
throw
new
RuntimeException
(
"更新数据已失效"
);
}
// 商品货品数量增加
Integer
orderId
=
order
.
getId
();
List
<
LitemallOrderGoods
>
orderGoodsList
=
orderGoodsService
.
queryByOid
(
orderId
);
for
(
LitemallOrderGoods
orderGoods
:
orderGoodsList
)
{
Integer
productId
=
orderGoods
.
getProductId
();
Short
number
=
orderGoods
.
getNumber
();
if
(
productService
.
addStock
(
productId
,
number
)
==
0
)
{
throw
new
RuntimeException
(
"商品货品库存增加失败"
);
}
}
logger
.
info
(
"系统结束处理延时任务---订单超时未付款---"
+
this
.
orderId
);
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/task/TaskStartupRunner.java
0 → 100644
View file @
7023b205
package
org.linlinjava.litemall.wx.task
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.linlinjava.litemall.core.system.SystemConfig
;
import
org.linlinjava.litemall.core.task.TaskService
;
import
org.linlinjava.litemall.db.domain.LitemallOrder
;
import
org.linlinjava.litemall.db.service.LitemallOrderService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
import
java.time.temporal.ChronoUnit
;
import
java.util.List
;
@Component
public
class
TaskStartupRunner
implements
ApplicationRunner
{
@Autowired
private
LitemallOrderService
orderService
;
@Autowired
private
TaskService
taskService
;
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
List
<
LitemallOrder
>
orderList
=
orderService
.
queryUnpaid
(
SystemConfig
.
getOrderUnpaid
());
for
(
LitemallOrder
order
:
orderList
){
LocalDateTime
add
=
order
.
getAddTime
();
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
expire
=
add
.
plusMinutes
(
SystemConfig
.
getOrderUnpaid
());
if
(
expire
.
isBefore
(
now
))
{
// 已经过期,则加入延迟队列
taskService
.
addTask
(
new
OrderUnpaidTask
(
order
.
getId
(),
0
));
}
else
{
// 还没过期,则加入延迟队列
long
delay
=
ChronoUnit
.
MILLIS
.
between
(
now
,
expire
);
taskService
.
addTask
(
new
OrderUnpaidTask
(
order
.
getId
(),
delay
));
}
}
}
}
\ No newline at end of file
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/vo/CouponVo.java
View file @
7023b205
...
...
@@ -4,6 +4,7 @@ import java.time.LocalDateTime;
public
class
CouponVo
{
private
Integer
id
;
private
Integer
cid
;
private
String
name
;
private
String
desc
;
private
String
tag
;
...
...
@@ -11,6 +12,7 @@ public class CouponVo {
private
String
discount
;
private
LocalDateTime
startTime
;
private
LocalDateTime
endTime
;
private
boolean
available
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -20,6 +22,14 @@ public class CouponVo {
this
.
id
=
id
;
}
public
Integer
getCid
()
{
return
cid
;
}
public
void
setCid
(
Integer
cid
)
{
this
.
cid
=
cid
;
}
public
String
getName
()
{
return
name
;
}
...
...
@@ -75,4 +85,12 @@ public class CouponVo {
public
void
setEndTime
(
LocalDateTime
endTime
)
{
this
.
endTime
=
endTime
;
}
public
boolean
isAvailable
()
{
return
available
;
}
public
void
setAvailable
(
boolean
available
)
{
this
.
available
=
available
;
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java
View file @
7023b205
...
...
@@ -239,10 +239,12 @@ public class WxAuthController {
String
password
=
JacksonUtil
.
parseString
(
body
,
"password"
);
String
mobile
=
JacksonUtil
.
parseString
(
body
,
"mobile"
);
String
code
=
JacksonUtil
.
parseString
(
body
,
"code"
);
// 如果是小程序注册,则必须非空
// 其他情况,可以为空
String
wxCode
=
JacksonUtil
.
parseString
(
body
,
"wxCode"
);
if
(
StringUtils
.
isEmpty
(
username
)
||
StringUtils
.
isEmpty
(
password
)
||
StringUtils
.
isEmpty
(
mobile
)
||
StringUtils
.
isEmpty
(
wxCode
)
||
StringUtils
.
isEmpty
(
code
))
{
||
StringUtils
.
isEmpty
(
code
))
{
return
ResponseUtil
.
badArgument
();
}
...
...
@@ -264,24 +266,28 @@ public class WxAuthController {
return
ResponseUtil
.
fail
(
AUTH_CAPTCHA_UNMATCH
,
"验证码错误"
);
}
String
openId
=
null
;
try
{
WxMaJscode2SessionResult
result
=
this
.
wxService
.
getUserService
().
getSessionInfo
(
wxCode
);
openId
=
result
.
getOpenid
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
ResponseUtil
.
fail
(
AUTH_OPENID_UNACCESS
,
"openid 获取失败"
);
}
userList
=
userService
.
queryByOpenid
(
openId
);
if
(
userList
.
size
()
>
1
)
{
return
ResponseUtil
.
serious
();
}
if
(
userList
.
size
()
==
1
)
{
LitemallUser
checkUser
=
userList
.
get
(
0
);
String
checkUsername
=
checkUser
.
getUsername
();
String
checkPassword
=
checkUser
.
getPassword
();
if
(!
checkUsername
.
equals
(
openId
)
||
!
checkPassword
.
equals
(
openId
))
{
return
ResponseUtil
.
fail
(
AUTH_OPENID_BINDED
,
"openid已绑定账号"
);
String
openId
=
""
;
// 非空,则是小程序注册
// 继续验证openid
if
(!
StringUtils
.
isEmpty
(
wxCode
))
{
try
{
WxMaJscode2SessionResult
result
=
this
.
wxService
.
getUserService
().
getSessionInfo
(
wxCode
);
openId
=
result
.
getOpenid
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
ResponseUtil
.
fail
(
AUTH_OPENID_UNACCESS
,
"openid 获取失败"
);
}
userList
=
userService
.
queryByOpenid
(
openId
);
if
(
userList
.
size
()
>
1
)
{
return
ResponseUtil
.
serious
();
}
if
(
userList
.
size
()
==
1
)
{
LitemallUser
checkUser
=
userList
.
get
(
0
);
String
checkUsername
=
checkUser
.
getUsername
();
String
checkPassword
=
checkUser
.
getPassword
();
if
(!
checkUsername
.
equals
(
openId
)
||
!
checkPassword
.
equals
(
openId
))
{
return
ResponseUtil
.
fail
(
AUTH_OPENID_BINDED
,
"openid已绑定账号"
);
}
}
}
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java
View file @
7023b205
package
org.linlinjava.litemall.wx.web
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.linlinjava.litemall.core.system.SystemConfig
;
...
...
@@ -14,10 +15,7 @@ import org.springframework.validation.annotation.Validated;
import
org.springframework.web.bind.annotation.*
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
static
org
.
linlinjava
.
litemall
.
wx
.
util
.
WxResponseCode
.
GOODS_NO_STOCK
;
import
static
org
.
linlinjava
.
litemall
.
wx
.
util
.
WxResponseCode
.
GOODS_UNSHELVE
;
...
...
@@ -60,7 +58,22 @@ public class WxCartController {
return
ResponseUtil
.
unlogin
();
}
List
<
LitemallCart
>
cartList
=
cartService
.
queryByUid
(
userId
);
List
<
LitemallCart
>
list
=
cartService
.
queryByUid
(
userId
);
List
<
LitemallCart
>
cartList
=
new
ArrayList
<>();
// TODO
// 如果系统检查商品已删除或已下架,则系统自动删除。
// 更好的效果应该是告知用户商品失效,允许用户点击按钮来清除失效商品。
for
(
LitemallCart
cart
:
list
)
{
LitemallGoods
goods
=
goodsService
.
findById
(
cart
.
getGoodsId
());
if
(
goods
==
null
||
!
goods
.
getIsOnSale
())
{
cartService
.
deleteById
(
cart
.
getId
());
logger
.
debug
(
"系统自动删除失效购物车商品 goodsId="
+
cart
.
getGoodsId
()
+
" productId="
+
cart
.
getProductId
());
}
else
{
cartList
.
add
(
cart
);
}
}
Integer
goodsCount
=
0
;
BigDecimal
goodsAmount
=
new
BigDecimal
(
0.00
);
Integer
checkedGoodsCount
=
0
;
...
...
@@ -133,7 +146,12 @@ public class WxCartController {
cart
.
setId
(
null
);
cart
.
setGoodsSn
(
goods
.
getGoodsSn
());
cart
.
setGoodsName
((
goods
.
getName
()));
cart
.
setPicUrl
(
goods
.
getPicUrl
());
if
(
StringUtils
.
isEmpty
(
product
.
getUrl
())){
cart
.
setPicUrl
(
goods
.
getPicUrl
());
}
else
{
cart
.
setPicUrl
(
product
.
getUrl
());
}
cart
.
setPrice
(
product
.
getPrice
());
cart
.
setSpecifications
(
product
.
getSpecifications
());
cart
.
setUserId
(
userId
);
...
...
@@ -202,7 +220,12 @@ public class WxCartController {
cart
.
setId
(
null
);
cart
.
setGoodsSn
(
goods
.
getGoodsSn
());
cart
.
setGoodsName
((
goods
.
getName
()));
cart
.
setPicUrl
(
goods
.
getPicUrl
());
if
(
StringUtils
.
isEmpty
(
product
.
getUrl
())){
cart
.
setPicUrl
(
goods
.
getPicUrl
());
}
else
{
cart
.
setPicUrl
(
product
.
getUrl
());
}
cart
.
setPrice
(
product
.
getPrice
());
cart
.
setSpecifications
(
product
.
getSpecifications
());
cart
.
setUserId
(
userId
);
...
...
@@ -386,7 +409,7 @@ public class WxCartController {
* @return 购物车操作结果
*/
@GetMapping
(
"checkout"
)
public
Object
checkout
(
@LoginUser
Integer
userId
,
Integer
cartId
,
Integer
addressId
,
Integer
couponId
,
Integer
grouponRulesId
)
{
public
Object
checkout
(
@LoginUser
Integer
userId
,
Integer
cartId
,
Integer
addressId
,
Integer
couponId
,
Integer
userCouponId
,
Integer
grouponRulesId
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
...
...
@@ -445,10 +468,12 @@ public class WxCartController {
// 计算优惠券可用情况
BigDecimal
tmpCouponPrice
=
new
BigDecimal
(
0.00
);
Integer
tmpCouponId
=
0
;
Integer
tmpUserCouponId
=
0
;
int
tmpCouponLength
=
0
;
List
<
LitemallCouponUser
>
couponUserList
=
couponUserService
.
queryAll
(
userId
);
for
(
LitemallCouponUser
couponUser
:
couponUserList
){
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponUser
.
getCouponId
(),
checkedGoodsPrice
);
tmpUserCouponId
=
couponUser
.
getId
();
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponUser
.
getCouponId
(),
tmpUserCouponId
,
checkedGoodsPrice
);
if
(
coupon
==
null
){
continue
;
}
...
...
@@ -468,17 +493,20 @@ public class WxCartController {
// 3. 用户已选择优惠券,则测试优惠券是否合适
if
(
couponId
==
null
||
couponId
.
equals
(-
1
)){
couponId
=
-
1
;
userCouponId
=
-
1
;
}
else
if
(
couponId
.
equals
(
0
))
{
couponPrice
=
tmpCouponPrice
;
couponId
=
tmpCouponId
;
userCouponId
=
tmpUserCouponId
;
}
else
{
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponId
,
checkedGoodsPrice
);
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponId
,
userCouponId
,
checkedGoodsPrice
);
// 用户选择的优惠券有问题,则选择合适优惠券,否则使用用户选择的优惠券
if
(
coupon
==
null
){
couponPrice
=
tmpCouponPrice
;
couponId
=
tmpCouponId
;
userCouponId
=
tmpUserCouponId
;
}
else
{
couponPrice
=
coupon
.
getDiscount
();
...
...
@@ -502,6 +530,7 @@ public class WxCartController {
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"addressId"
,
addressId
);
data
.
put
(
"couponId"
,
couponId
);
data
.
put
(
"userCouponId"
,
userCouponId
);
data
.
put
(
"cartId"
,
cartId
);
data
.
put
(
"grouponRulesId"
,
grouponRulesId
);
data
.
put
(
"grouponPrice"
,
grouponPrice
);
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCatalogController.java
View file @
7023b205
...
...
@@ -30,6 +30,20 @@ public class WxCatalogController {
@Autowired
private
LitemallCategoryService
categoryService
;
@GetMapping
(
"/getfirstcategory"
)
public
Object
getFirstCategory
()
{
// 所有一级分类目录
List
<
LitemallCategory
>
l1CatList
=
categoryService
.
queryL1
();
return
ResponseUtil
.
ok
(
l1CatList
);
}
@GetMapping
(
"/getsecondcategory"
)
public
Object
getSecondCategory
(
@NotNull
Integer
id
)
{
// 所有二级分类目录
List
<
LitemallCategory
>
currentSubCategory
=
categoryService
.
queryByPid
(
id
);
return
ResponseUtil
.
ok
(
currentSubCategory
);
}
/**
* 分类详情
*
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCouponController.java
View file @
7023b205
...
...
@@ -79,7 +79,7 @@ public class WxCouponController {
*/
@GetMapping
(
"mylist"
)
public
Object
mylist
(
@LoginUser
Integer
userId
,
@NotNull
Short
status
,
Short
status
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
page
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
limit
,
@Sort
@RequestParam
(
defaultValue
=
"add_time"
)
String
sort
,
...
...
@@ -99,7 +99,8 @@ public class WxCouponController {
Integer
couponId
=
couponUser
.
getCouponId
();
LitemallCoupon
coupon
=
couponService
.
findById
(
couponId
);
CouponVo
couponVo
=
new
CouponVo
();
couponVo
.
setId
(
coupon
.
getId
());
couponVo
.
setId
(
couponUser
.
getId
());
couponVo
.
setCid
(
coupon
.
getId
());
couponVo
.
setName
(
coupon
.
getName
());
couponVo
.
setDesc
(
coupon
.
getDesc
());
couponVo
.
setTag
(
coupon
.
getTag
());
...
...
@@ -160,17 +161,12 @@ public class WxCouponController {
// 计算优惠券可用情况
List
<
LitemallCouponUser
>
couponUserList
=
couponUserService
.
queryAll
(
userId
);
List
<
LitemallCouponUser
>
availableCouponUserList
=
new
ArrayList
<>(
couponUserList
.
size
());
for
(
LitemallCouponUser
couponUser
:
couponUserList
)
{
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
couponUser
.
getCouponId
(),
checkedGoodsPrice
);
if
(
coupon
==
null
)
{
continue
;
}
availableCouponUserList
.
add
(
couponUser
);
List
<
CouponVo
>
couponVoList
=
change
(
couponUserList
);
for
(
CouponVo
cv
:
couponVoList
)
{
LitemallCoupon
coupon
=
couponVerifyService
.
checkCoupon
(
userId
,
cv
.
getCid
(),
cv
.
getId
(),
checkedGoodsPrice
);
cv
.
setAvailable
(
coupon
!=
null
);
}
List
<
CouponVo
>
couponVoList
=
change
(
availableCouponUserList
);
return
ResponseUtil
.
okList
(
couponVoList
);
}
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java
View file @
7023b205
...
...
@@ -90,6 +90,18 @@ public class WxOrderController {
return
wxOrderService
.
prepay
(
userId
,
body
,
request
);
}
/**
* 微信H5支付
* @param userId
* @param body
* @param request
* @return
*/
@PostMapping
(
"h5pay"
)
public
Object
h5pay
(
@LoginUser
Integer
userId
,
@RequestBody
String
body
,
HttpServletRequest
request
)
{
return
wxOrderService
.
h5pay
(
userId
,
body
,
request
);
}
/**
* 微信付款成功或失败回调接口
* <p>
...
...
litemall-wx/config/api.js
View file @
7023b205
...
...
@@ -4,7 +4,7 @@ var WxApiRoot = 'http://localhost:8080/wx/';
// 局域网测试使用
// var WxApiRoot = 'http://192.168.0.101:8080/wx/';
// 云平台部署时使用
// var WxApiRoot = 'http://1
18.24.0.153
:8080/wx/';
// var WxApiRoot = 'http://1
22.51.199.160
:8080/wx/';
// 云平台上线时使用
// var WxApiRoot = 'https://www.menethil.com.cn/wx/';
...
...
litemall-wx/pages/cart/cart.wxml
View file @
7023b205
...
...
@@ -31,7 +31,7 @@
<text class="name">{{item.goodsName}}</text>
<text class="num">x{{item.number}}</text>
</view>
<view class="attr">{{ isEditCart ? '已选择:' : ''}}{{item.
goodsS
pecification
Value
s||''}}</view>
<view class="attr">{{ isEditCart ? '已选择:' : ''}}{{item.
s
pecifications||''}}</view>
<view class="b">
<text class="price">¥{{item.price}}</text>
<view class="selnum">
...
...
litemall-wx/pages/checkout/checkout.js
View file @
7023b205
...
...
@@ -17,6 +17,7 @@ Page({
cartId
:
0
,
addressId
:
0
,
couponId
:
0
,
userCouponId
:
0
,
message
:
''
,
grouponLinkId
:
0
,
//参与的团购,如果是发起则为0
grouponRulesId
:
0
//团购规则ID
...
...
@@ -32,6 +33,7 @@ Page({
cartId
:
that
.
data
.
cartId
,
addressId
:
that
.
data
.
addressId
,
couponId
:
that
.
data
.
couponId
,
userCouponId
:
that
.
data
.
userCouponId
,
grouponRulesId
:
that
.
data
.
grouponRulesId
}).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
...
...
@@ -47,6 +49,7 @@ Page({
orderTotalPrice
:
res
.
data
.
orderTotalPrice
,
addressId
:
res
.
data
.
addressId
,
couponId
:
res
.
data
.
couponId
,
userCouponId
:
res
.
data
.
userCouponId
,
grouponRulesId
:
res
.
data
.
grouponRulesId
,
});
}
...
...
@@ -90,6 +93,10 @@ Page({
if
(
couponId
===
""
)
{
couponId
=
0
;
}
var
userCouponId
=
wx
.
getStorageSync
(
'
userCouponId
'
);
if
(
userCouponId
===
""
)
{
userCouponId
=
0
;
}
var
grouponRulesId
=
wx
.
getStorageSync
(
'
grouponRulesId
'
);
if
(
grouponRulesId
===
""
)
{
grouponRulesId
=
0
;
...
...
@@ -103,6 +110,7 @@ Page({
cartId
:
cartId
,
addressId
:
addressId
,
couponId
:
couponId
,
userCouponId
:
userCouponId
,
grouponRulesId
:
grouponRulesId
,
grouponLinkId
:
grouponLinkId
});
...
...
@@ -131,6 +139,7 @@ Page({
cartId
:
this
.
data
.
cartId
,
addressId
:
this
.
data
.
addressId
,
couponId
:
this
.
data
.
couponId
,
userCouponId
:
this
.
data
.
userCouponId
,
message
:
this
.
data
.
message
,
grouponRulesId
:
this
.
data
.
grouponRulesId
,
grouponLinkId
:
this
.
data
.
grouponLinkId
...
...
litemall-wx/pages/topicComment/topicComment.js
View file @
7023b205
...
...
@@ -45,15 +45,15 @@ Page({
if
(
that
.
data
.
showType
==
0
)
{
that
.
setData
({
allCommentList
:
that
.
data
.
allCommentList
.
concat
(
res
.
data
.
data
),
allPage
:
res
.
data
.
currentP
age
,
comments
:
that
.
data
.
allCommentList
.
concat
(
res
.
data
.
data
)
allCommentList
:
that
.
data
.
allCommentList
.
concat
(
res
.
data
.
list
),
allPage
:
res
.
data
.
p
age
,
comments
:
that
.
data
.
allCommentList
.
concat
(
res
.
data
.
list
)
});
}
else
{
that
.
setData
({
picCommentList
:
that
.
data
.
picCommentList
.
concat
(
res
.
data
.
data
),
picPage
:
res
.
data
.
currentP
age
,
comments
:
that
.
data
.
picCommentList
.
concat
(
res
.
data
.
data
)
picCommentList
:
that
.
data
.
picCommentList
.
concat
(
res
.
data
.
list
),
picPage
:
res
.
data
.
p
age
,
comments
:
that
.
data
.
picCommentList
.
concat
(
res
.
data
.
list
)
});
}
}
...
...
@@ -84,21 +84,30 @@ Page({
// 页面关闭
},
switchTab
:
function
()
{
this
.
setData
({
showType
:
this
.
data
.
showType
==
1
?
0
:
1
});
switchTab
:
function
()
{
let
that
=
this
;
if
(
that
.
data
.
showType
==
0
)
{
that
.
setData
({
allCommentList
:
[],
allPage
:
1
,
comments
:
[],
showType
:
1
});
}
else
{
that
.
setData
({
picCommentList
:
[],
picPage
:
1
,
comments
:
[],
showType
:
0
});
}
this
.
getCommentList
();
},
onReachBottom
:
function
()
{
console
.
log
(
'
onPullDownRefresh
'
);
if
(
this
.
data
.
showType
==
0
)
{
if
(
this
.
data
.
allCount
/
this
.
data
.
limit
<
this
.
data
.
allPage
)
{
return
false
;
}
this
.
setData
({
allPage
:
this
.
data
.
allPage
+
1
});
...
...
@@ -106,14 +115,10 @@ Page({
if
(
this
.
data
.
hasPicCount
/
this
.
data
.
limit
<
this
.
data
.
picPage
)
{
return
false
;
}
this
.
setData
({
picPage
:
this
.
data
.
picPage
+
1
});
}
this
.
getCommentList
();
}
})
\ No newline at end of file
litemall-wx/pages/topicComment/topicComment.wxml
View file @
7023b205
<view class="comments">
<view class="h">
<view class="item {{ showType == 0 ? 'active' : ''}}" bindtap="switchTab">
<view class="txt">全部({{allCount}})</view>
</view>
<view class="item {{ showType == 0 ? '' : 'active'}}" bindtap="switchTab">
<view class="txt">有图({{hasPicCount}})</view>
</view>
</view>
<view class="b">
<view class="item" wx:for="{{comments}}" wx:key="id">
<view class="info">
...
...
@@ -10,7 +18,7 @@
</view>
<view class="comment">{{item.content}}</view>
<view class="imgs" wx:if="{{item.picList.length > 0}}">
<image class="img" wx:for="{{item.picList}}" wx:key="
id
" wx:for-item="pitem" src="{{pitem
.picUrl
}}"></image>
<image class="img" wx:for="{{item.picList}}" wx:key="
*this
" wx:for-item="pitem" src="{{pitem}}"></image>
</view>
</view>
...
...
litemall-wx/pages/topicComment/topicComment.wxss
View file @
7023b205
...
...
@@ -6,7 +6,44 @@
margin: 20rpx 0;
}
.comments .h {
position: fixed;
left: 0;
top: 0;
z-index: 1000;
width: 100%;
display: flex;
background: #fff;
height: 84rpx;
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
}
.comments .h .item {
display: inline-block;
height: 82rpx;
width: 50%;
padding: 0 15rpx;
text-align: center;
}
.comments .h .item .txt {
display: inline-block;
height: 82rpx;
padding: 0 20rpx;
line-height: 82rpx;
color: #333;
font-size: 30rpx;
width: 170rpx;
}
.comments .h .item.active .txt {
color: #ab2b2b;
border-bottom: 4rpx solid #ab2b2b;
}
.comments .b {
margin-top: 85rpx;
height: auto;
width: 720rpx;
}
...
...
litemall-wx/pages/ucenter/couponSelect/couponSelect.js
View file @
7023b205
...
...
@@ -8,6 +8,7 @@ Page({
couponList
:
[],
cartId
:
0
,
couponId
:
0
,
userCouponId
:
0
,
grouponLinkId
:
0
,
scrollTop
:
0
},
...
...
@@ -46,6 +47,11 @@ Page({
couponId
=
0
;
}
var
userCouponId
=
wx
.
getStorageSync
(
'
userCouponId
'
);
if
(
!
userCouponId
)
{
userCouponId
=
0
;
}
var
grouponRulesId
=
wx
.
getStorageSync
(
'
grouponRulesId
'
);
if
(
!
grouponRulesId
)
{
grouponRulesId
=
0
;
...
...
@@ -54,6 +60,7 @@ Page({
this
.
setData
({
cartId
:
cartId
,
couponId
:
couponId
,
userCouponId
:
userCouponId
,
grouponRulesId
:
grouponRulesId
});
...
...
@@ -116,8 +123,14 @@ Page({
grouponRulesId
:
that
.
data
.
grouponRulesId
,
}).
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
let
list
=
[];
for
(
var
i
=
0
;
i
<
res
.
data
.
list
.
length
;
i
++
)
{
if
(
res
.
data
.
list
[
i
].
available
)
{
list
.
push
(
res
.
data
.
list
[
i
]);
}
}
that
.
setData
({
couponList
:
res
.
data
.
list
couponList
:
list
});
}
wx
.
hideToast
();
...
...
@@ -126,7 +139,8 @@ Page({
},
selectCoupon
:
function
(
e
)
{
try
{
wx
.
setStorageSync
(
'
couponId
'
,
e
.
currentTarget
.
dataset
.
id
);
wx
.
setStorageSync
(
'
couponId
'
,
e
.
currentTarget
.
dataset
.
cid
);
wx
.
setStorageSync
(
'
userCouponId
'
,
e
.
currentTarget
.
dataset
.
id
);
}
catch
(
error
)
{
}
...
...
@@ -137,6 +151,7 @@ Page({
// 如果优惠券ID设置-1,则表示订单不使用优惠券
try
{
wx
.
setStorageSync
(
'
couponId
'
,
-
1
);
wx
.
setStorageSync
(
'
userCouponId
'
,
-
1
);
}
catch
(
error
)
{
}
...
...
litemall-wx/pages/ucenter/couponSelect/couponSelect.wxml
View file @
7023b205
...
...
@@ -4,7 +4,7 @@
<view class="unselect" bindtap='unselectCoupon'>不选择优惠券</view>
<view class="item" wx:for="{{couponList}}" wx:for-index="index" wx:for-item="item" wx:key="id" bindtap="selectCoupon" data-id="{{item.id}}">
<view class="item" wx:for="{{couponList}}" wx:for-index="index" wx:for-item="item" wx:key="id" bindtap="selectCoupon" data-id="{{item.id}}"
data-cid="{{item.cid}}"
>
<view class="tag">{{item.tag}}</view>
<view class="content">
<view class="left">
...
...
Prev
1
2
3
4
Next
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