Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
3220e8db
提交
3220e8db
authored
5月 08, 2019
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 后端:Order 模块,解决报错问题。
上级
ec9622ad
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
40 行增加
和
79 行删除
+40
-79
OrderController.java
...l/order/application/controller/users/OrderController.java
+4
-10
UsersCartController.java
...der/application/controller/users/UsersCartController.java
+19
-43
CartService.java
.../src/main/java/cn/iocoder/mall/order/api/CartService.java
+12
-11
CartServiceImpl.java
...va/cn/iocoder/mall/order/biz/service/CartServiceImpl.java
+0
-0
OrderReturnServiceImpl.java
...ocoder/mall/order/biz/service/OrderReturnServiceImpl.java
+1
-1
OrderServiceImpl.java
...a/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java
+4
-14
没有找到文件。
order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java
浏览文件 @
3220e8db
...
...
@@ -13,17 +13,14 @@ import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
import
cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO
;
import
cn.iocoder.mall.order.api.dto.OrderCreateDTO
;
import
cn.iocoder.mall.order.api.dto.OrderQueryDTO
;
import
cn.iocoder.mall.order.api.dto.OrderReturnApplyDTO
;
import
cn.iocoder.mall.order.application.convert.CartConvert
;
import
cn.iocoder.mall.order.application.convert.OrderConvertAPP
;
import
cn.iocoder.mall.order.application.convert.OrderReturnConvert
;
import
cn.iocoder.mall.order.application.po.user.OrderCreatePO
;
import
cn.iocoder.mall.order.application.po.user.OrderReturnApplyPO
;
import
cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO
;
import
cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder
;
import
org.apache.dubbo.config.annotation.Reference
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.dubbo.config.annotation.Reference
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -76,7 +73,7 @@ public class OrderController {
HttpServletRequest
request
)
{
Integer
userId
=
UserSecurityContextHolder
.
getContext
().
getUserId
();
// 获得购物车中选中的商品
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
userId
,
true
)
.
getData
()
;
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
userId
,
true
);
if
(
cartItems
.
isEmpty
())
{
return
ServiceExceptionUtil
.
error
(
OrderErrorCodeEnum
.
ORDER_CREATE_CART_IS_EMPTY
.
getCode
());
}
...
...
@@ -105,12 +102,9 @@ public class OrderController {
.
setUserId
(
UserSecurityContextHolder
.
getContext
().
getUserId
())
.
setItems
(
Collections
.
singletonList
(
new
CalcOrderPriceDTO
.
Item
(
skuId
,
quantity
,
true
)))
.
setCouponCardId
(
couponCardId
);
CommonResult
<
CalcOrderPriceBO
>
calcOrderPriceResult
=
cartService
.
calcOrderPrice
(
calcOrderPriceDTO
);
if
(
calcOrderPriceResult
.
isError
())
{
return
CommonResult
.
error
(
calcOrderPriceResult
);
}
CalcOrderPriceBO
calcOrderPrice
=
cartService
.
calcOrderPrice
(
calcOrderPriceDTO
);
// 执行数据拼装
return
CommonResult
.
success
(
CartConvert
.
INSTANCE
.
convert
(
calcOrderPrice
Result
.
getData
()
));
return
CommonResult
.
success
(
CartConvert
.
INSTANCE
.
convert
(
calcOrderPrice
));
}
@PostMapping
(
"confirm_receiving"
)
...
...
order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java
浏览文件 @
3220e8db
...
...
@@ -23,6 +23,8 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.Set
;
import
static
cn
.
iocoder
.
common
.
framework
.
vo
.
CommonResult
.
success
;
@RestController
@RequestMapping
(
"users/cart"
)
public
class
UsersCartController
{
...
...
@@ -38,26 +40,17 @@ public class UsersCartController {
public
CommonResult
<
Integer
>
add
(
@RequestParam
(
"skuId"
)
Integer
skuId
,
@RequestParam
(
"quantity"
)
Integer
quantity
)
{
// 添加到购物车
CommonResult
<
Boolean
>
addResult
=
cartService
.
add
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
skuId
,
quantity
);
// 添加失败,则直接返回错误
if
(
addResult
.
isError
())
{
return
CommonResult
.
error
(
addResult
);
}
cartService
.
add
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
skuId
,
quantity
);
// 获得目前购物车商品总数量
return
cartService
.
count
(
UserSecurityContextHolder
.
getContext
().
getUserId
(
));
return
success
(
cartService
.
count
(
UserSecurityContextHolder
.
getContext
().
getUserId
()
));
}
@PostMapping
(
"update_quantity"
)
public
CommonResult
<
UsersCartDetailVO
>
updateQuantity
(
@RequestParam
(
"skuId"
)
Integer
skuId
,
// TODO 芋艿,先暂用这个 VO 。等促销活动出来后,做调整
@RequestParam
(
"quantity"
)
Integer
quantity
)
{
// 添加到购物车
CommonResult
<
Boolean
>
updateQuantityResult
=
cartService
.
updateQuantity
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
cartService
.
updateQuantity
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
skuId
,
quantity
);
// 添加失败,则直接返回错误
if
(
updateQuantityResult
.
isError
())
{
return
CommonResult
.
error
(
updateQuantityResult
);
}
// 获得目前购物车明细
return
getCartDetail
();
}
...
...
@@ -66,19 +59,14 @@ public class UsersCartController {
public
CommonResult
<
UsersCartDetailVO
>
updateSelected
(
@RequestParam
(
"skuIds"
)
Set
<
Integer
>
skuIds
,
// TODO 芋艿,先暂用这个 VO 。等促销活动出来后,做调整
@RequestParam
(
"selected"
)
Boolean
selected
)
{
// 添加到购物车
CommonResult
<
Boolean
>
updateSelectedResult
=
cartService
.
updateSelected
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
skuIds
,
selected
);
// 添加失败,则直接返回错误
if
(
updateSelectedResult
.
isError
())
{
return
CommonResult
.
error
(
updateSelectedResult
);
}
cartService
.
updateSelected
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
skuIds
,
selected
);
// 获得目前购物车明细
return
getCartDetail
();
}
@GetMapping
(
"count"
)
public
CommonResult
<
Integer
>
count
()
{
return
cartService
.
count
(
UserSecurityContextHolder
.
getContext
().
getUserId
(
));
return
success
(
cartService
.
count
(
UserSecurityContextHolder
.
getContext
().
getUserId
()
));
}
@GetMapping
(
"/list"
)
...
...
@@ -88,50 +76,42 @@ public class UsersCartController {
private
CommonResult
<
UsersCartDetailVO
>
getCartDetail
()
{
// 获得购物车中选中的
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
null
)
.
getData
()
;
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
UserSecurityContextHolder
.
getContext
().
getUserId
(),
null
);
// 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回
if
(
cartItems
.
isEmpty
())
{
UsersCartDetailVO
result
=
new
UsersCartDetailVO
();
result
.
setItemGroups
(
Collections
.
emptyList
());
result
.
setFee
(
new
UsersCartDetailVO
.
Fee
(
0
,
0
,
0
,
0
));
return
CommonResult
.
success
(
result
);
return
success
(
result
);
}
// 计算商品价格
CommonResult
<
CalcOrderPriceBO
>
calcOrderPriceResult
=
list0
(
cartItems
,
null
);
if
(
calcOrderPriceResult
.
isError
())
{
return
CommonResult
.
error
(
calcOrderPriceResult
);
}
CalcOrderPriceBO
calcOrder
=
list0
(
cartItems
,
null
);
// 执行数据拼装
return
CommonResult
.
success
(
CartConvert
.
INSTANCE
.
convert2
(
calcOrderPriceResult
.
getData
()
));
return
success
(
CartConvert
.
INSTANCE
.
convert2
(
calcOrder
));
}
@GetMapping
(
"/confirm_create_order"
)
public
CommonResult
<
UsersOrderConfirmCreateVO
>
getConfirmCreateOrder
(
@RequestParam
(
value
=
"couponCardId"
,
required
=
false
)
Integer
couponCardId
)
{
Integer
userId
=
UserSecurityContextHolder
.
getContext
().
getUserId
();
// 获得购物车中选中的
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
userId
,
true
)
.
getData
()
;
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
userId
,
true
);
// 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回
if
(
cartItems
.
isEmpty
())
{
UsersOrderConfirmCreateVO
result
=
new
UsersOrderConfirmCreateVO
();
result
.
setItemGroups
(
Collections
.
emptyList
());
result
.
setFee
(
new
UsersOrderConfirmCreateVO
.
Fee
(
0
,
0
,
0
,
0
));
return
CommonResult
.
success
(
result
);
return
success
(
result
);
}
// 计算商品价格
CommonResult
<
CalcOrderPriceBO
>
calcOrderPriceResult
=
list0
(
cartItems
,
couponCardId
);
if
(
calcOrderPriceResult
.
isError
())
{
return
CommonResult
.
error
(
calcOrderPriceResult
);
}
CalcOrderPriceBO
calcOrderPrice
=
list0
(
cartItems
,
couponCardId
);
// 获得优惠劵
CalcOrderPriceBO
calcOrderPrice
=
calcOrderPriceResult
.
getData
();
List
<
CouponCardAvailableBO
>
couponCards
=
couponService
.
getCouponCardList
(
userId
,
CartConvert
.
INSTANCE
.
convertList
(
calcOrderPrice
.
getItemGroups
()))
.
getData
()
;
CartConvert
.
INSTANCE
.
convertList
(
calcOrderPrice
.
getItemGroups
()));
// 执行数据拼装
return
CommonResult
.
success
(
CartConvert
.
INSTANCE
.
convert
(
calcOrderPrice
)
.
setCouponCards
(
couponCards
));
return
success
(
CartConvert
.
INSTANCE
.
convert
(
calcOrderPrice
).
setCouponCards
(
couponCards
));
}
private
C
ommonResult
<
CalcOrderPriceBO
>
list0
(
List
<
CartItemBO
>
cartItems
,
Integer
couponCardId
)
{
private
C
alcOrderPriceBO
list0
(
List
<
CartItemBO
>
cartItems
,
Integer
couponCardId
)
{
// 创建计算的 DTO
CalcOrderPriceDTO
calcOrderPriceDTO
=
new
CalcOrderPriceDTO
()
.
setUserId
(
UserSecurityContextHolder
.
getContext
().
getUserId
())
...
...
@@ -148,12 +128,8 @@ public class UsersCartController {
@PermitAll
public
CommonResult
<
UsersCalcSkuPriceVO
>
calcSkuPrice
(
@RequestParam
(
"skuId"
)
Integer
skuId
)
{
// 计算 sku 的价格
CommonResult
<
CalcSkuPriceBO
>
calcSkuPriceResult
=
cartService
.
calcSkuPrice
(
skuId
);
// 返回结果
if
(
calcSkuPriceResult
.
isError
())
{
return
CommonResult
.
error
(
calcSkuPriceResult
);
}
return
CommonResult
.
success
(
CartConvert
.
INSTANCE
.
convert2
(
calcSkuPriceResult
.
getData
()));
CalcSkuPriceBO
calcSkuPrice
=
cartService
.
calcSkuPrice
(
skuId
);
return
success
(
CartConvert
.
INSTANCE
.
convert2
(
calcSkuPrice
));
}
public
CommonResult
<
Object
>
confirmOrder
()
{
...
...
order/order-service-api/src/main/java/cn/iocoder/mall/order/api/CartService.java
浏览文件 @
3220e8db
package
cn
.
iocoder
.
mall
.
order
.
api
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.order.api.bo.*
;
import
cn.iocoder.mall.order.api.bo.CalcOrderPriceBO
;
import
cn.iocoder.mall.order.api.bo.CalcSkuPriceBO
;
import
cn.iocoder.mall.order.api.bo.CartItemBO
;
import
cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO
;
import
org.springframework.lang.Nullable
;
...
...
@@ -20,7 +21,7 @@ public interface CartService {
* @param quantity 数量
* @return 是否成功
*/
CommonResult
<
Boolean
>
add
(
Integer
userId
,
Integer
skuId
,
Integer
quantity
);
Boolean
add
(
Integer
userId
,
Integer
skuId
,
Integer
quantity
);
/**
* 购物车更新商品数量
...
...
@@ -30,7 +31,7 @@ public interface CartService {
* @param quantity 数量
* @return 是否成功
*/
CommonResult
<
Boolean
>
updateQuantity
(
Integer
userId
,
Integer
skuId
,
Integer
quantity
);
Boolean
updateQuantity
(
Integer
userId
,
Integer
skuId
,
Integer
quantity
);
/**
* 购物车更新商品是否选中
...
...
@@ -40,7 +41,7 @@ public interface CartService {
* @param selected 是否选中
* @return 是否成功
*/
CommonResult
<
Boolean
>
updateSelected
(
Integer
userId
,
Collection
<
Integer
>
skuIds
,
Boolean
selected
);
Boolean
updateSelected
(
Integer
userId
,
Collection
<
Integer
>
skuIds
,
Boolean
selected
);
/**
* 购物车删除商品
...
...
@@ -50,7 +51,7 @@ public interface CartService {
*
* @return 是否成功
*/
CommonResult
<
Boolean
>
deleteList
(
Integer
userId
,
List
<
Integer
>
skuIds
);
Boolean
deleteList
(
Integer
userId
,
List
<
Integer
>
skuIds
);
/**
* 清空购物车
...
...
@@ -58,7 +59,7 @@ public interface CartService {
* @param userId 用户编号
* @return 是否成功
*/
CommonResult
<
Boolean
>
deleteAll
(
Integer
userId
);
Boolean
deleteAll
(
Integer
userId
);
/**
* 查询用户在购物车中的商品数量
...
...
@@ -66,7 +67,7 @@ public interface CartService {
* @param userId 用户编号
* @return 商品数量
*/
CommonResult
<
Integer
>
count
(
Integer
userId
);
Integer
count
(
Integer
userId
);
/**
* 显示买家购物车中的商品列表,并根据 selected 进行过滤。
...
...
@@ -75,7 +76,7 @@ public interface CartService {
* @param selected 是否选中。若为空,则不进行筛选
* @return 购物车中商品列表信息
*/
CommonResult
<
List
<
CartItemBO
>
>
list
(
Integer
userId
,
@Nullable
Boolean
selected
);
List
<
CartItemBO
>
list
(
Integer
userId
,
@Nullable
Boolean
selected
);
// ========== 购物车与订单相关的逻辑 ==========
...
...
@@ -85,7 +86,7 @@ public interface CartService {
* @param calcOrderPriceDTO 计算订单金额 DTO
* @return 计算订单金额结果
*/
C
ommonResult
<
CalcOrderPriceBO
>
calcOrderPrice
(
CalcOrderPriceDTO
calcOrderPriceDTO
);
C
alcOrderPriceBO
calcOrderPrice
(
CalcOrderPriceDTO
calcOrderPriceDTO
);
/**
* 计算指定商品 SKU 的金额,并返回计算结果
...
...
@@ -95,6 +96,6 @@ public interface CartService {
* @param skuId 商品 SKU 编号
* @return 计算订单金额结果
*/
C
ommonResult
<
CalcSkuPriceBO
>
calcSkuPrice
(
Integer
skuId
);
C
alcSkuPriceBO
calcSkuPrice
(
Integer
skuId
);
}
order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java
浏览文件 @
3220e8db
差异被折叠。
点击展开。
order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java
浏览文件 @
3220e8db
...
...
@@ -141,7 +141,7 @@ public class OrderReturnServiceImpl implements OrderReturnService {
);
}
@Override
//
@Override
public
CommonResult
agree
(
Integer
id
)
{
OrderReturnDO
orderReturnDO
=
orderReturnMapper
.
selectById
(
id
);
if
(
orderReturnDO
==
null
)
{
...
...
order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java
浏览文件 @
3220e8db
...
...
@@ -224,11 +224,7 @@ public class OrderServiceImpl implements OrderService {
}
// 价格计算
CommonResult
<
CalcOrderPriceBO
>
calcOrderPriceResult
=
calcOrderPrice
(
productList
,
orderCreateDTO
);
if
(
calcOrderPriceResult
.
isError
())
{
return
CommonResult
.
error
(
calcOrderPriceResult
);
}
CalcOrderPriceBO
calcOrderPrice
=
calcOrderPriceResult
.
getData
();
CalcOrderPriceBO
calcOrderPrice
=
calcOrderPrice
(
productList
,
orderCreateDTO
);
// 设置 orderItem
Map
<
Integer
,
ProductSkuDetailBO
>
productSpuBOMap
=
productList
...
...
@@ -261,10 +257,7 @@ public class OrderServiceImpl implements OrderService {
// 标记优惠劵已使用
if
(
orderCreateDTO
.
getCouponCardId
()
!=
null
)
{
CommonResult
<
Boolean
>
useCouponCardResult
=
couponService
.
useCouponCard
(
userId
,
orderCreateDTO
.
getCouponCardId
());
if
(
useCouponCardResult
.
isError
())
{
return
CommonResult
.
error
(
useCouponCardResult
);
}
couponService
.
useCouponCard
(
userId
,
orderCreateDTO
.
getCouponCardId
());
}
// TODO 芋艿,扣除库存
...
...
@@ -329,10 +322,7 @@ public class OrderServiceImpl implements OrderService {
orderItemMapper
.
insert
(
orderItemDOList
);
// 创建预订单
CommonResult
<
PayTransactionBO
>
createPayTransactionResult
=
createPayTransaction
(
orderDO
,
orderItemDOList
,
orderCreateDTO
.
getIp
());
if
(
calcOrderPriceResult
.
isError
())
{
return
CommonResult
.
error
(
calcOrderPriceResult
);
}
createPayTransaction
(
orderDO
,
orderItemDOList
,
orderCreateDTO
.
getIp
());
// if (commonResult.isError()) {
// //手动开启事务回滚
...
...
@@ -349,7 +339,7 @@ public class OrderServiceImpl implements OrderService {
);
}
private
C
ommonResult
<
CalcOrderPriceBO
>
calcOrderPrice
(
List
<
ProductSkuDetailBO
>
skus
,
OrderCreateDTO
orderCreateDTO
)
{
private
C
alcOrderPriceBO
calcOrderPrice
(
List
<
ProductSkuDetailBO
>
skus
,
OrderCreateDTO
orderCreateDTO
)
{
// 创建计算的 DTO
CalcOrderPriceDTO
calcOrderPriceDTO
=
new
CalcOrderPriceDTO
()
.
setUserId
(
orderCreateDTO
.
getUserId
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论