Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
38b2613a
提交
38b2613a
authored
6 年前
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
后端 + 前端:提交购物车订单
上级
b2abc625
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
146 行增加
和
38 行删除
+146
-38
order.js
mobile-web/src/api/order.js
+24
-1
index.vue
mobile-web/src/page/cart/index.vue
+1
-1
order.vue
mobile-web/src/page/shipping/order.vue
+48
-22
UsersOrderController.java
...er/application/controller/users/UsersOrderController.java
+32
-0
OrderConvertAPP.java
...coder/mall/order/application/convert/OrderConvertAPP.java
+19
-4
CartService.java
.../src/main/java/cn/iocoder/mall/order/api/CartService.java
+1
-1
CartItemStatusEnum.java
...n/iocoder/mall/order/api/constant/CartItemStatusEnum.java
+1
-1
OrderErrorCodeEnum.java
...n/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java
+1
-0
CartMapper.java
...c/main/java/cn/iocoder/mall/order/biz/dao/CartMapper.java
+4
-3
CartServiceImpl.java
...va/cn/iocoder/mall/order/biz/service/CartServiceImpl.java
+6
-3
CartMapper.xml
...der-service-impl/src/main/resources/mapper/CartMapper.xml
+9
-2
没有找到文件。
mobile-web/src/api/order.js
浏览文件 @
38b2613a
...
...
@@ -21,7 +21,7 @@ export function confirmReceiving(orderId) {
});
}
export
function
getConfirmCreateOrder
(
skuId
,
quantity
)
{
export
function
get
Order
ConfirmCreateOrder
(
skuId
,
quantity
)
{
return
request
({
url
:
'/order-api/users/order/confirm_create_order'
,
method
:
'get'
,
...
...
@@ -45,6 +45,18 @@ export function createOrder(params) {
});
}
export
function
createOrderFromCart
(
userAddressId
,
remark
)
{
return
request
({
url
:
'/order-api/users/order/create_order_from_cart'
,
method
:
'post'
,
params
:
{
userAddressId
,
remark
,
}
});
}
// Cart
export
function
addCart
(
skuId
,
quantity
)
{
...
...
@@ -87,6 +99,17 @@ export function updateCartSelected(skuIds, selected) {
});
}
export
function
getCartConfirmCreateOrder
(
skuId
,
quantity
)
{
return
request
({
url
:
'/order-api/users/cart/confirm_create_order'
,
method
:
'get'
,
params
:
{
skuId
,
quantity
,
}
});
}
// 物流信息
export
function
getLogisticsInfo
(
params
)
{
...
...
This diff is collapsed.
Click to expand it.
mobile-web/src/page/cart/index.vue
浏览文件 @
38b2613a
...
...
@@ -157,7 +157,7 @@ export default {
})
},
onSubmit
()
{
this
.
$router
.
push
(
'/order'
)
this
.
$router
.
push
(
'/order
?from=cart
'
)
},
convertProduct
(
item
)
{
// debugger;
...
...
This diff is collapsed.
Click to expand it.
mobile-web/src/page/shipping/order.vue
浏览文件 @
38b2613a
...
...
@@ -68,7 +68,12 @@
<
script
>
import
{
createOrder
,
getConfirmCreateOrder
}
from
'../../api/order'
;
import
{
createOrder
,
getOrderConfirmCreateOrder
,
getCartConfirmCreateOrder
,
createOrderFromCart
}
from
'../../api/order'
;
import
{
GetDefaultAddress
}
from
'../../api/user'
;
import
orderStore
from
'../../store/order'
...
...
@@ -96,30 +101,43 @@
},
methods
:
{
onSubmit
()
{
const
{
skuId
,
quantity
}
=
this
.
$route
.
query
;
const
userAddressId
=
this
.
addressData
.
id
;
const
remark
=
''
;
const
orderItems
=
[{
skuId
,
quantity
,
}];
createOrder
({
orderItems
,
userAddressId
,
remark
,
}).
then
(
result
=>
{
if
(
result
)
{
const
{
orderNo
}
=
result
;
this
.
$router
.
push
({
//核心语句
path
:
`/order/success`
,
//跳转的路径
query
:{
//路由传参时push和query搭配使用 ,作用时传递参数
...
result
,
if
(
this
.
from
===
'direct_order'
)
{
const
{
skuId
,
quantity
}
=
this
.
$route
.
query
;
const
orderItems
=
[{
skuId
,
quantity
,
}];
createOrder
({
orderItems
,
userAddressId
,
remark
,
}).
then
(
result
=>
{
if
(
result
)
{
const
{
orderNo
}
=
result
;
this
.
$router
.
push
({
//核心语句
path
:
`/order/success`
,
//跳转的路径
query
:{
//路由传参时push和query搭配使用 ,作用时传递参数
...
result
,
}
});
}
});
}
})
}
else
if
(
this
.
from
===
'cart'
)
{
createOrderFromCart
(
userAddressId
,
remark
).
then
(
result
=>
{
if
(
result
)
{
const
{
orderNo
}
=
result
;
this
.
$router
.
push
({
//核心语句
path
:
`/order/success`
,
//跳转的路径
query
:{
//路由传参时push和query搭配使用 ,作用时传递参数
...
result
,
}
});
}
});
}
},
convertProduct
(
item
)
{
// debugger;
...
...
@@ -143,13 +161,18 @@
this
.
addressData
=
this
.
$store
.
state
.
addressData
;
// 加载商品信息
// debugger;
if
(
this
.
from
===
'direct_order'
)
{
getConfirmCreateOrder
(
this
.
skuId
,
this
.
quantity
).
then
(
data
=>
{
getOrderConfirmCreateOrder
(
this
.
skuId
,
this
.
quantity
).
then
(
data
=>
{
this
.
itemGroups
=
data
.
itemGroups
;
this
.
fee
=
data
.
fee
;
})
}
else
if
(
this
.
from
===
'cart'
)
{
getCartConfirmCreateOrder
().
then
(
data
=>
{
this
.
itemGroups
=
data
.
itemGroups
;
this
.
fee
=
data
.
fee
;
})
}
},
created
()
{
// 加载地址
...
...
@@ -160,6 +183,9 @@
}
})
// 处理来源
if
(
this
.
$route
.
query
.
from
===
'cart'
)
{
this
.
from
=
this
.
$route
.
query
.
from
;
}
},
store
:
orderStore
,
};
...
...
This diff is collapsed.
Click to expand it.
order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java
浏览文件 @
38b2613a
package
cn
.
iocoder
.
mall
.
order
.
application
.
controller
.
users
;
import
cn.iocoder.common.framework.util.HttpUtil
;
import
cn.iocoder.common.framework.util.ServiceExceptionUtil
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.order.api.CartService
;
import
cn.iocoder.mall.order.api.OrderService
;
import
cn.iocoder.mall.order.api.bo.CalcOrderPriceBO
;
import
cn.iocoder.mall.order.api.bo.CartItemBO
;
import
cn.iocoder.mall.order.api.bo.OrderCreateBO
;
import
cn.iocoder.mall.order.api.bo.OrderPageBO
;
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
;
...
...
@@ -19,7 +23,10 @@ import io.swagger.annotations.Api;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 订单API(users)
...
...
@@ -52,6 +59,31 @@ public class UsersOrderController {
return
orderService
.
createOrder
(
orderCreateDTO
);
}
@PostMapping
(
"create_order_from_cart"
)
public
CommonResult
<
OrderCreateBO
>
createOrderFromCart
(
@RequestParam
(
"userAddressId"
)
Integer
userAddressId
,
@RequestParam
(
value
=
"remark"
,
required
=
false
)
String
remark
,
HttpServletRequest
request
)
{
Integer
userId
=
UserSecurityContextHolder
.
getContext
().
getUserId
();
// 获得购物车中选中的商品
List
<
CartItemBO
>
cartItems
=
cartService
.
list
(
userId
,
true
).
getData
();
if
(
cartItems
.
isEmpty
())
{
return
ServiceExceptionUtil
.
error
(
OrderErrorCodeEnum
.
ORDER_CREATE_CART_IS_EMPTY
.
getCode
());
}
// 创建 OrderCreateDTO 对象
OrderCreateDTO
orderCreateDTO
=
OrderConvertAPP
.
INSTANCE
.
createOrderCreateDTO
(
userId
,
userAddressId
,
remark
,
HttpUtil
.
getIp
(
request
),
cartItems
);
// 创建订单
CommonResult
<
OrderCreateBO
>
createResult
=
orderService
.
createOrder
(
orderCreateDTO
);
if
(
createResult
.
isError
())
{
return
CommonResult
.
error
(
createResult
);
}
// 清空购物车 // TODO 芋艿,需要标记删除的原因,即结果为创建为某个订单。
cartService
.
deleteList
(
userId
,
cartItems
.
stream
().
map
(
CartItemBO:
:
getSkuId
).
collect
(
Collectors
.
toList
()));
// 返回结果
return
createResult
;
}
@GetMapping
(
"confirm_create_order"
)
public
CommonResult
<
UsersOrderConfirmCreateVO
>
getConfirmCreateOrder
(
@RequestParam
(
"skuId"
)
Integer
skuId
,
@RequestParam
(
"quantity"
)
Integer
quantity
)
{
...
...
This diff is collapsed.
Click to expand it.
order/order-application/src/main/java/cn/iocoder/mall/order/application/convert/OrderConvertAPP.java
浏览文件 @
38b2613a
package
cn
.
iocoder
.
mall
.
order
.
application
.
convert
;
import
cn.iocoder.mall.order.api.dto.OrderCreateDTO
;
import
cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO
;
import
cn.iocoder.mall.order.api.dto.OrderLogisticsUpdateDTO
;
import
cn.iocoder.mall.order.api.dto.OrderQueryDTO
;
import
cn.iocoder.mall.order.api.bo.CartItemBO
;
import
cn.iocoder.mall.order.api.dto.*
;
import
cn.iocoder.mall.order.application.po.admin.OrderItemUpdatePO
;
import
cn.iocoder.mall.order.application.po.admin.OrderLogisticsPO
;
import
cn.iocoder.mall.order.application.po.admin.OrderPageQueryPO
;
...
...
@@ -12,6 +10,8 @@ import org.mapstruct.Mapper;
import
org.mapstruct.Mappings
;
import
org.mapstruct.factory.Mappers
;
import
java.util.List
;
/**
* application 订单 convert
*
...
...
@@ -36,4 +36,19 @@ public interface OrderConvertAPP {
@Mappings
({})
OrderCreateDTO
convert
(
OrderCreatePO
orderCreatePO
);
@Mappings
({})
List
<
OrderCreateItemDTO
>
convert
(
List
<
CartItemBO
>
cartItems
);
default
OrderCreateDTO
createOrderCreateDTO
(
Integer
userId
,
Integer
userAddressId
,
String
remark
,
String
ip
,
List
<
CartItemBO
>
cartItems
)
{
return
new
OrderCreateDTO
()
.
setUserId
(
userId
)
.
setUserAddressId
(
userAddressId
)
.
setRemark
(
remark
)
.
setIp
(
ip
)
.
setOrderItems
(
this
.
convert
(
cartItems
));
}
}
This diff is collapsed.
Click to expand it.
order/order-service-api/src/main/java/cn/iocoder/mall/order/api/CartService.java
浏览文件 @
38b2613a
...
...
@@ -53,7 +53,7 @@ public interface CartService {
*
* @return 是否成功
*/
CommonResult
<
Boolean
>
delete
(
Integer
userId
,
List
<
Integer
>
skuIds
);
CommonResult
<
Boolean
>
delete
List
(
Integer
userId
,
List
<
Integer
>
skuIds
);
/**
* 清空购物车
...
...
This diff is collapsed.
Click to expand it.
order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/CartItemStatusEnum.java
浏览文件 @
38b2613a
...
...
@@ -6,7 +6,7 @@ public enum CartItemStatusEnum {
ENABLE
(
1
,
"正常"
),
DELETE_BY_MANUAL
(
2
,
"主动删除"
),
DELETE_BY_
(
3
,
"下单删除"
),
DELETE_BY_
ORDER
(
3
,
"下单删除"
),
;
public
static
final
int
[]
ARRAYS
=
Arrays
.
stream
(
values
()).
mapToInt
(
CartItemStatusEnum:
:
getValue
).
toArray
();
...
...
This diff is collapsed.
Click to expand it.
order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java
浏览文件 @
38b2613a
...
...
@@ -24,6 +24,7 @@ public enum OrderErrorCodeEnum {
ORDER_GET_PAY_FAIL
(
1008000010
,
"调用pay失败!"
),
ORDER_NOT_USER_ORDER
(
1008000011
,
"不是该用户的订单!"
),
ORDER_UNABLE_CONFIRM_ORDER
(
1008000012
,
"状态不对不能确认订单!"
),
ORDER_CREATE_CART_IS_EMPTY
(
1008000013
,
"购物车无选中的商品,无法创建订单"
),
// order item
ORDER_ITEM_ONLY_ONE
(
1008000200
,
"订单Item只有一个!"
),
...
...
This diff is collapsed.
Click to expand it.
order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/CartMapper.java
浏览文件 @
38b2613a
...
...
@@ -38,8 +38,9 @@ public interface CartMapper {
int
updateQuantity
(
@Param
(
"id"
)
Integer
id
,
@Param
(
"quantityIncr"
)
Integer
quantityIncr
);
int
updateListSelected
(
@Param
(
"userId"
)
Integer
userId
,
@Param
(
"skuIds"
)
Collection
<
Integer
>
skuIds
,
@Param
(
"selected"
)
Boolean
selected
);
int
updateListByUserIdAndSkuId
(
@Param
(
"userId"
)
Integer
userId
,
@Param
(
"skuIds"
)
Collection
<
Integer
>
skuIds
,
@Param
(
"selected"
)
Boolean
selected
,
@Param
(
"status"
)
Integer
status
);
}
This diff is collapsed.
Click to expand it.
order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java
浏览文件 @
38b2613a
...
...
@@ -116,14 +116,17 @@ public class CartServiceImpl implements CartService {
@Override
public
CommonResult
<
Boolean
>
updateSelected
(
Integer
userId
,
Collection
<
Integer
>
skuIds
,
Boolean
selected
)
{
// 更新 CartItemDO 们
cartMapper
.
updateList
Selected
(
userId
,
skuIds
,
selected
);
cartMapper
.
updateList
ByUserIdAndSkuId
(
userId
,
skuIds
,
selected
,
null
);
// 返回成功
return
CommonResult
.
success
(
true
);
}
@Override
public
CommonResult
<
Boolean
>
delete
(
Integer
userId
,
List
<
Integer
>
skuIds
)
{
return
null
;
public
CommonResult
<
Boolean
>
deleteList
(
Integer
userId
,
List
<
Integer
>
skuIds
)
{
// 更新 CartItemDO 们
cartMapper
.
updateListByUserIdAndSkuId
(
userId
,
skuIds
,
null
,
CartItemStatusEnum
.
DELETE_BY_MANUAL
.
getValue
());
// 返回成功
return
CommonResult
.
success
(
true
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
order/order-service-impl/src/main/resources/mapper/CartMapper.xml
浏览文件 @
38b2613a
...
...
@@ -108,9 +108,16 @@
WHERE id = #{id}
</update>
<update
id=
"updateList
Selecte
d"
>
<update
id=
"updateList
ByUserIdAndSkuI
d"
>
UPDATE cart_item
SET selected = #{selected}
<set>
<if
test=
"selected != null"
>
selected = #{selected},
</if>
<if
test=
"status != null"
>
status = #{status},
</if>
</set>
WHERE user_id = #{userId}
AND sku_id IN
<foreach
item=
"skuId"
collection=
"skuIds"
separator=
","
open=
"("
close=
")"
index=
""
>
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论