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
c480e78e
"src/main/resources/application-pro.yml" did not exist on "da21280bb35139c3203936023e334b7ff67c797c"
Commit
c480e78e
authored
Aug 04, 2018
by
Menethil
Browse files
添加团购
parent
58fc87d2
Changes
22
Hide whitespace changes
Inline
Side-by-side
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java
0 → 100644
View file @
c480e78e
package
org.linlinjava.litemall.wx.web
;
import
org.linlinjava.litemall.core.qcode.QCodeService
;
import
org.linlinjava.litemall.core.util.JacksonUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.db.domain.LitemallGoods
;
import
org.linlinjava.litemall.db.domain.LitemallGroupon
;
import
org.linlinjava.litemall.db.domain.LitemallGrouponRules
;
import
org.linlinjava.litemall.db.service.LitemallGoodsService
;
import
org.linlinjava.litemall.db.service.LitemallGrouponRulesService
;
import
org.linlinjava.litemall.db.service.LitemallGrouponService
;
import
org.linlinjava.litemall.wx.annotation.LoginUser
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.constraints.NotNull
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/wx/groupon"
)
@Validated
public
class
WxGrouponController
{
@Autowired
private
LitemallGrouponRulesService
rulesService
;
@Autowired
private
LitemallGrouponService
grouponService
;
@Autowired
private
LitemallGoodsService
goodsService
;
@Autowired
private
QCodeService
qCodeService
;
@GetMapping
(
"detail"
)
public
Object
detail
(
@LoginUser
Integer
userId
,
@NotNull
Integer
grouponId
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
LitemallGroupon
groupon
=
grouponService
.
queryById
(
grouponId
);
if
(
groupon
==
null
)
{
return
ResponseUtil
.
badArgumentValue
();
}
LitemallGrouponRules
rules
=
rulesService
.
queryById
(
groupon
.
getRulesId
());
if
(
rules
==
null
)
{
return
ResponseUtil
.
badArgumentValue
();
}
LitemallGoods
goods
=
goodsService
.
findById
(
rules
.
getGoodsId
());
int
count
=
grouponService
.
countGroupon
(
grouponId
);
Map
<
String
,
Object
>
groupInfo
=
new
HashMap
<>();
groupInfo
.
put
(
"groupon"
,
groupon
);
groupInfo
.
put
(
"rules"
,
rules
);
groupInfo
.
put
(
"goods"
,
goods
);
groupInfo
.
put
(
"count"
,
count
);
return
ResponseUtil
.
ok
(
groupInfo
);
}
@GetMapping
(
"query"
)
public
Object
query
(
@NotNull
Integer
goodsId
)
{
LitemallGoods
goods
=
goodsService
.
findById
(
goodsId
);
if
(
goods
==
null
)
{
return
ResponseUtil
.
fail
(-
1
,
"未找到对应的商品"
);
}
List
<
LitemallGrouponRules
>
rules
=
rulesService
.
queryByGoodsId
(
goodsId
);
return
ResponseUtil
.
ok
(
rules
);
}
@RequestMapping
(
"join"
)
public
Object
join
(
@LoginUser
Integer
userId
,
@RequestBody
String
body
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
Integer
rulesId
=
JacksonUtil
.
parseInteger
(
body
,
"rulesId"
);
LitemallGrouponRules
rules
=
rulesService
.
queryById
(
rulesId
);
if
(
rules
==
null
)
{
return
ResponseUtil
.
fail
(-
1
,
"未找到对应的团购规则"
);
}
Integer
grouponId
=
JacksonUtil
.
parseInteger
(
body
,
"grouponId"
);
LitemallGroupon
groupon
=
grouponService
.
queryById
(
grouponId
);
if
(
groupon
==
null
)
{
return
ResponseUtil
.
fail
(-
1
,
"未找到对应的团购活动"
);
}
LitemallGroupon
groupon2
=
new
LitemallGroupon
();
groupon2
.
setUserId
(
userId
);
groupon2
.
setRulesId
(
rulesId
);
groupon2
.
setShareUrl
(
""
);
//参与者
groupon2
.
setUserType
(
false
);
groupon2
.
setGrouponId
(
grouponId
);
groupon2
.
setAddTime
(
LocalDateTime
.
now
());
//过期时间与创建一致
groupon2
.
setExpireTime
(
groupon
.
getExpireTime
());
grouponService
.
createGroupon
(
groupon
);
return
ResponseUtil
.
ok
();
}
@GetMapping
(
"create"
)
public
Object
create
(
@LoginUser
Integer
userId
,
@NotNull
Integer
rulesId
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
LitemallGrouponRules
rules
=
rulesService
.
queryById
(
rulesId
);
if
(
rules
==
null
)
{
return
ResponseUtil
.
fail
(-
1
,
"未找到对应的团购规则"
);
}
LitemallGroupon
groupon
=
new
LitemallGroupon
();
groupon
.
setUserId
(
userId
);
groupon
.
setRulesId
(
rulesId
);
//发起者
groupon
.
setUserType
(
true
);
groupon
.
setGrouponId
(
0
);
groupon
.
setAddTime
(
LocalDateTime
.
now
());
groupon
.
setExpireTime
(
LocalDateTime
.
now
().
plusDays
(
2
));
grouponService
.
createGroupon
(
groupon
);
qCodeService
.
createGrouponShareImage
(
rules
.
getGoodsName
(),
rules
.
getPicUrl
(),
groupon
);
groupon
.
setShareUrl
(
qCodeService
.
getShareImageUrl
(
groupon
.
getId
().
toString
()));
grouponService
.
update
(
groupon
);
return
ResponseUtil
.
ok
();
}
@RequestMapping
(
"list"
)
public
Object
list
(
@LoginUser
Integer
userId
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
List
<
LitemallGroupon
>
myGroupOn
=
grouponService
.
queryByUserId
(
userId
);
return
ResponseUtil
.
ok
(
myGroupOn
);
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java
View file @
c480e78e
...
...
@@ -11,6 +11,7 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
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.util.DateTimeUtil
;
import
org.linlinjava.litemall.core.util.JacksonUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
...
...
@@ -82,15 +83,18 @@ public class WxOrderController {
private
LitemallRegionService
regionService
;
@Autowired
private
LitemallProductService
productService
;
@Autowired
private
WxPayService
wxPayService
;
@Autowired
private
NotifyService
notifyService
;
@Autowired
private
LitemallUserFormIdService
formIdService
;
@Autowired
private
LitemallGrouponRulesService
grouponRulesService
;
@Autowired
private
LitemallGrouponService
grouponService
;
@Autowired
private
QCodeService
qCodeService
;
public
WxOrderController
()
{
}
...
...
@@ -267,6 +271,9 @@ public class WxOrderController {
Integer
cartId
=
JacksonUtil
.
parseInteger
(
body
,
"cartId"
);
Integer
addressId
=
JacksonUtil
.
parseInteger
(
body
,
"addressId"
);
Integer
couponId
=
JacksonUtil
.
parseInteger
(
body
,
"couponId"
);
Integer
grouponId
=
JacksonUtil
.
parseInteger
(
body
,
"grouponId"
);
Integer
grouponLinkId
=
JacksonUtil
.
parseInteger
(
body
,
"grouponLinkId"
);
if
(
cartId
==
null
||
addressId
==
null
||
couponId
==
null
)
{
return
ResponseUtil
.
badArgument
();
}
...
...
@@ -304,9 +311,15 @@ public class WxOrderController {
// 可以使用的其他钱,例如用户积分
BigDecimal
integralPrice
=
new
BigDecimal
(
0.00
);
// 团购优惠
BigDecimal
grouponPrice
=
new
BigDecimal
(
0.00
);
LitemallGrouponRules
grouponRules
=
grouponRulesService
.
queryById
(
grouponId
);
if
(
grouponRules
!=
null
)
{
grouponPrice
=
grouponRules
.
getDiscount
();
}
// 订单费用
BigDecimal
orderTotalPrice
=
checkedGoodsPrice
.
add
(
freightPrice
).
subtract
(
couponPrice
);
BigDecimal
orderTotalPrice
=
checkedGoodsPrice
.
add
(
freightPrice
).
subtract
(
couponPrice
)
.
subtract
(
grouponPrice
)
;
BigDecimal
actualPrice
=
orderTotalPrice
.
subtract
(
integralPrice
);
// 开启事务管理
...
...
@@ -332,6 +345,14 @@ public class WxOrderController {
order
.
setIntegralPrice
(
integralPrice
);
order
.
setOrderPrice
(
orderTotalPrice
);
order
.
setActualPrice
(
actualPrice
);
// 有团购活动
if
(
grouponRules
!=
null
)
{
order
.
setGrouponPrice
(
grouponPrice
);
// 团购价格
}
else
{
order
.
setGrouponPrice
(
new
BigDecimal
(
0.00
));
// 团购价格
}
// 添加订单表项
orderService
.
add
(
order
);
orderId
=
order
.
getId
();
...
...
@@ -369,6 +390,29 @@ public class WxOrderController {
product
.
setNumber
(
remainNumber
);
productService
.
updateById
(
product
);
}
//如果是团购项目,添加团购信息
if
(
grouponId
!=
null
&&
grouponId
>
0
)
{
LitemallGroupon
groupon
=
new
LitemallGroupon
();
groupon
.
setOrderId
(
orderId
);
groupon
.
setPayed
(
false
);
groupon
.
setUserId
(
userId
);
groupon
.
setRulesId
(
grouponId
);
//参与者
if
(
grouponLinkId
!=
null
&&
grouponLinkId
>
0
)
{
groupon
.
setUserType
(
false
);
groupon
.
setGrouponId
(
grouponLinkId
);
}
else
{
groupon
.
setUserType
(
true
);
groupon
.
setGrouponId
(
0
);
}
groupon
.
setAddTime
(
LocalDateTime
.
now
());
groupon
.
setExpireTime
(
LocalDateTime
.
now
().
plusDays
(
2
));
grouponService
.
createGroupon
(
groupon
);
}
}
catch
(
Exception
ex
)
{
txManager
.
rollback
(
status
);
logger
.
error
(
"系统内部错误"
,
ex
);
...
...
@@ -545,6 +589,7 @@ public class WxOrderController {
String
orderSn
=
result
.
getOutTradeNo
();
String
payId
=
result
.
getTransactionId
();
// 分转化成元
String
totalFee
=
BaseWxPayResult
.
fenToYuan
(
result
.
getTotalFee
());
...
...
@@ -568,6 +613,20 @@ public class WxOrderController {
order
.
setOrderStatus
(
OrderUtil
.
STATUS_PAY
);
orderService
.
updateById
(
order
);
// 支付成功,有团购信息,更新团购信息
LitemallGroupon
groupon
=
grouponService
.
queryByOrderId
(
order
.
getId
());
if
(
groupon
!=
null
)
{
LitemallGrouponRules
grouponRules
=
grouponRulesService
.
queryById
(
groupon
.
getRulesId
());
//仅当发起者才创建分享图片
if
(
groupon
.
getGrouponId
()
==
0
)
{
qCodeService
.
createGrouponShareImage
(
grouponRules
.
getGoodsName
(),
grouponRules
.
getPicUrl
(),
groupon
);
groupon
.
setShareUrl
(
qCodeService
.
getShareImageUrl
(
groupon
.
getId
().
toString
()));
}
groupon
.
setPayed
(
true
);
grouponService
.
update
(
groupon
);
}
//TODO 发送邮件和短信通知,这里采用异步发送
// 订单支付成功以后,会发送短信给用户,以及发送邮件给管理员
notifyService
.
notifyMail
(
"新订单通知"
,
order
.
toString
());
...
...
Prev
1
2
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