- 添加订单 info

pull/1/head
sin 2019-04-14 18:15:53 +08:00
parent 204452c9d0
commit 0ca854587e
18 changed files with 362 additions and 22 deletions

View File

@ -4,6 +4,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.order.api.OrderLogisticsService;
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
@Api(description = "订单物流信息")
public class OrderLogisticsController {
@Autowired
@Reference(validation = "true")
private OrderLogisticsService orderLogisticsService;
@GetMapping("logistics_info")

View File

@ -3,12 +3,12 @@ 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.admin.api.DataDictService;
import cn.iocoder.mall.admin.api.bo.DataDictBO;
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.bo.*;
import cn.iocoder.mall.order.api.constant.DictKeysConstants;
import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO;
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
@ -20,6 +20,7 @@ import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -43,8 +44,11 @@ public class UsersOrderController {
private OrderService orderService;
@Reference(validation = "true")
private CartService cartService;
@Reference(validation = "true")
private DataDictService dataDictService;
@GetMapping("order_page")
@ApiOperation("订单分页")
public CommonResult<OrderPageBO> getOrderPage(@Validated OrderQueryDTO orderQueryDTO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
orderQueryDTO.setUserId(userId);
@ -52,6 +56,7 @@ public class UsersOrderController {
}
@PostMapping("create_order")
@ApiOperation("创建订单")
public CommonResult<OrderCreateBO> createOrder(@RequestBody @Validated OrderCreatePO orderCreatePO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
OrderCreateDTO orderCreateDTO = OrderConvertAPP.INSTANCE.convert(orderCreatePO);
@ -60,6 +65,7 @@ public class UsersOrderController {
}
@PostMapping("create_order_from_cart")
@ApiOperation("创建订单购物车")
public CommonResult<OrderCreateBO> createOrderFromCart(@RequestParam("userAddressId") Integer userAddressId,
@RequestParam(value = "remark", required = false) String remark,
HttpServletRequest request) {
@ -85,6 +91,7 @@ public class UsersOrderController {
}
@GetMapping("confirm_create_order")
@ApiOperation("确认创建订单")
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam("skuId") Integer skuId,
@RequestParam("quantity") Integer quantity) {
// 创建 CalcOrderPriceDTO 对象,并执行价格计算
@ -99,9 +106,22 @@ public class UsersOrderController {
}
@PostMapping("confirm_receiving")
@ApiOperation("确认收货")
public CommonResult confirmReceiving(@RequestParam("orderId") Integer orderId) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return orderService.confirmReceiving(userId, orderId);
}
@GetMapping("info")
@ApiOperation("订单详情")
public CommonResult<OrderInfoBO> orderInfo(@RequestParam("orderId") Integer orderId) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
CommonResult<OrderInfoBO> commonResult = orderService.info(userId, orderId);
OrderInfoBO orderInfoBO = commonResult.getData();
CommonResult<DataDictBO> dictResult = dataDictService
.getDataDict(DictKeysConstants.ORDER_STATUS_KEY, orderInfoBO.getStatus());
orderInfoBO.setStatusText(dictResult.getData().getDisplayName());
return commonResult;
}
}

View File

@ -38,6 +38,15 @@ public interface OrderService {
*/
CommonResult<OrderRecipientBO> getOrderRecipientBO(Integer orderId);
/**
* info
*
* @param userId
* @param orderId
* @return
*/
CommonResult<OrderInfoBO> info(Integer userId, Integer orderId);
/**
* -
*

View File

@ -0,0 +1,148 @@
package cn.iocoder.mall.order.api.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* info
*
* @author Sin
* @time 2019-04-14 15:36
*/
@Data
@Accessors(chain = true)
public class OrderInfoBO implements Serializable {
/**
*
*/
private String orderNo;
/**
* ()
*/
private Integer price;
/**
*
*/
private Integer payAmount;
/**
* ()
*/
private Integer logisticsPrice;
/**
*
*/
private Date paymentTime;
/**
*
*/
private Date deliveryTime;
/**
*
*/
private Date receiverTime;
/**
* -> status =
*/
private Date closingTime;
/**
* 退
*
* - 1
* - 2
* - 3退
* - 4 + 退
*/
private Integer hasReturnExchange;
/**
* ()
*
* - 1
* - 2
* - 3
* - 4
* - 5
*/
private Integer status;
/**
*
*/
private String statusText;
/**
*
*/
private String remark;
///
/// 其他信息
/**
*
*/
private Recipient recipient;
/**
*
*/
private LogisticsDetail latestLogisticsDetail;
@Data
@Accessors(chain = true)
public static class Recipient {
/**
*
*/
private Integer id;
/**
* id
*/
private Integer orderId;
/**
*
*/
private String areaNo;
/**
*
*/
private String name;
/**
*
*/
private String mobile;
/**
*
*
* - 1
*/
private Integer type;
/**
*
*/
private String address;
}
@Data
@Accessors(chain = true)
public static class LogisticsDetail {
/**
* id
*/
private Integer id;
/**
* id
*/
private Integer orderLogisticsId;
/**
*
*/
private Date logisticsTime;
/**
*
*/
private String logisticsInformation;
}
}

View File

@ -0,0 +1,15 @@
package cn.iocoder.mall.order.api.constant;
/**
* keys
*
* @author Sin
* @time 2019-04-14 17:46
*/
public class DictKeysConstants {
/**
* - status
*/
public static final String ORDER_STATUS_KEY = "order_status";
}

View File

@ -12,11 +12,28 @@ import java.util.List;
*/
public interface OrderCommon {
/**
*
*
*
* @param items
* @return
*/
Integer calculatedPrice(List<OrderItemDO> items);
/**
*
*
* @param items
* @return
*/
Integer calculatedAmount(List<OrderItemDO> items);
/**
*
*
* @param items
* @return
*/
Integer calculatedLogisticsPrice(List<OrderItemDO> items);
}

View File

@ -16,6 +16,18 @@ import java.util.concurrent.atomic.AtomicInteger;
@Component
public class OrderCommonImpl implements OrderCommon {
@Override
public Integer calculatedPrice(List<OrderItemDO> items) {
if (CollectionUtils.isEmpty(items)) {
return 0;
}
AtomicInteger totalPrice = new AtomicInteger(0);
items.forEach(orderItemDO -> {
totalPrice.addAndGet(orderItemDO.getPrice() * orderItemDO.getQuantity());
});
return totalPrice.get();
}
@Override
public Integer calculatedAmount(List<OrderItemDO> items) {
if (CollectionUtils.isEmpty(items)) {
@ -27,4 +39,16 @@ public class OrderCommonImpl implements OrderCommon {
});
return totalAmount.get();
}
@Override
public Integer calculatedLogisticsPrice(List<OrderItemDO> items) {
if (CollectionUtils.isEmpty(items)) {
return 0;
}
AtomicInteger totalAmount = new AtomicInteger(0);
items.forEach(orderItemDO -> {
totalAmount.addAndGet(orderItemDO.getLogisticsPrice());
});
return totalAmount.get();
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.order.biz.convert;
import cn.iocoder.mall.order.api.bo.OrderBO;
import cn.iocoder.mall.order.api.bo.OrderInfoBO;
import cn.iocoder.mall.order.biz.dataobject.OrderDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
@ -21,4 +22,7 @@ public interface OrderConvert {
@Mappings({})
List<OrderBO> convertPageBO(List<OrderDO> orderDOList);
@Mappings({})
OrderInfoBO convert(OrderDO orderDO);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.order.biz.convert;
import cn.iocoder.mall.order.api.bo.OrderInfoBO;
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO;
import org.mapstruct.Mapper;
@ -21,4 +22,7 @@ public interface OrderLogisticsDetailConvert {
@Mappings({})
List<OrderLogisticsInfoBO.LogisticsDetail> convertLogisticsDetail(List<OrderLogisticsDetailDO> orderLogisticsDOList);
@Mappings({})
OrderInfoBO.LogisticsDetail convertLogisticsDetail(OrderLogisticsDetailDO orderLogisticsDetailDO);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.order.biz.convert;
import cn.iocoder.mall.order.api.bo.OrderInfoBO;
import cn.iocoder.mall.order.api.bo.OrderRecipientBO;
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO;
@ -32,4 +33,7 @@ public interface OrderRecipientConvert {
@Mappings({})
List<OrderRecipientBO> convert(List<OrderRecipientDO> orderRecipientDOList);
@Mappings({})
OrderInfoBO.Recipient convertOrderInfoRecipient(OrderRecipientDO orderRecipientDO);
}

View File

@ -43,4 +43,14 @@ public interface OrderLogisticsDetailMapper {
List<OrderLogisticsDetailDO> selectByOrderLogisticsIds(
@Param("orderLogisticsIds") Collection<Integer> orderLogisticsIds
);
/**
* -
*
* @param orderLogisticsIds
* @return
*/
OrderLogisticsDetailDO selectLatest(
@Param("orderLogisticsIds") Collection<Integer> orderLogisticsIds
);
}

View File

@ -28,6 +28,14 @@ public class OrderDO extends DeletableDO {
*
*/
private String orderNo;
/**
* ()
*/
private Integer price;
/**
* ()
*/
private Integer logisticsPrice;
/**
*
*/

View File

@ -56,6 +56,10 @@ public class OrderItemDO extends DeletableDO {
*
*/
private Integer payAmount;
/**
* ()
*/
private Integer logisticsPrice;
///
/// 时间信息

View File

@ -5,7 +5,6 @@ import cn.iocoder.common.framework.util.DateUtil;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.order.api.OrderLogisticsService;
import cn.iocoder.mall.order.api.bo.OrderLogisticsBO;
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert;
@ -34,6 +33,7 @@ import java.util.stream.Collectors;
* @time 2019-04-12 21:32
*/
@Service
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
public class OrderLogisticsServiceImpl implements OrderLogisticsService {
@Autowired
@ -63,7 +63,9 @@ public class OrderLogisticsServiceImpl implements OrderLogisticsService {
// 获取物流 信息
Set<Integer> orderLogisticsIds = orderItemDOList.stream()
.map(o -> o.getOrderLogisticsId()).collect(Collectors.toSet());
.filter(o -> o.getOrderLogisticsId() != null)
.map(o -> o.getOrderLogisticsId())
.collect(Collectors.toSet());
List<OrderLogisticsDO> orderLogisticsDOList = orderLogisticsMapper.selectByIds(orderLogisticsIds);

View File

@ -19,6 +19,7 @@ import java.util.Date;
* @time 2019-03-30 15:35
*/
@Service
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
public class OrderReturnServiceImpl implements OrderReturnService {
@Autowired

View File

@ -12,10 +12,7 @@ import cn.iocoder.mall.order.api.dto.*;
import cn.iocoder.mall.order.biz.OrderCommon;
import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum;
import cn.iocoder.mall.order.biz.constants.OrderRecipientTypeEnum;
import cn.iocoder.mall.order.biz.convert.OrderConvert;
import cn.iocoder.mall.order.biz.convert.OrderItemConvert;
import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert;
import cn.iocoder.mall.order.biz.convert.OrderRecipientConvert;
import cn.iocoder.mall.order.biz.convert.*;
import cn.iocoder.mall.order.biz.dao.*;
import cn.iocoder.mall.order.biz.dataobject.*;
import cn.iocoder.mall.pay.api.PayTransactionService;
@ -55,6 +52,8 @@ public class OrderServiceImpl implements OrderService {
@Autowired
private OrderLogisticsMapper orderLogisticsMapper;
@Autowired
private OrderLogisticsDetailMapper orderLogisticsDetailMapper;
@Autowired
private OrderRecipientMapper orderRecipientMapper;
@Autowired
private OrderCancelMapper orderCancelMapper;
@ -152,6 +151,41 @@ public class OrderServiceImpl implements OrderService {
return CommonResult.success(orderRecipientBO);
}
@Override
public CommonResult<OrderInfoBO> info(Integer userId, Integer orderId) {
OrderDO orderDO = orderMapper.selectById(orderId);
if (orderDO == null) {
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_EXISTENT.getCode());
}
List<OrderItemDO> itemDOList = orderItemMapper
.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue());
Set<Integer> orderLogisticsIds = itemDOList.stream()
.filter(o -> o.getOrderLogisticsId() != null)
.map(o -> o.getOrderLogisticsId())
.collect(Collectors.toSet());
// 收件人信息
OrderRecipientDO orderRecipientDO = orderRecipientMapper.selectByOrderId(orderId);
// 订单物流信息
OrderLogisticsDetailDO orderLogisticsDetailDO = null;
if (!CollectionUtils.isEmpty(orderLogisticsIds)) {
orderLogisticsDetailDO = orderLogisticsDetailMapper.selectLatest(orderLogisticsIds);
}
// convert 信息
OrderInfoBO.LogisticsDetail logisticsDetail
= OrderLogisticsDetailConvert.INSTANCE.convertLogisticsDetail(orderLogisticsDetailDO);
OrderInfoBO.Recipient recipient = OrderRecipientConvert.INSTANCE.convertOrderInfoRecipient(orderRecipientDO);
OrderInfoBO orderInfoBO = OrderConvert.INSTANCE.convert(orderDO);
orderInfoBO.setRecipient(recipient);
orderInfoBO.setLatestLogisticsDetail(logisticsDetail);
return CommonResult.success(orderInfoBO);
}
@Override
@Transactional
public CommonResult<OrderCreateBO> createOrder(OrderCreateDTO orderCreateDTO) {
@ -196,6 +230,7 @@ public class OrderServiceImpl implements OrderService {
orderItemDO.setSkuImage(Optional.ofNullable(productSkuDetailBO.getSpu().getPicUrls().get(0)).get());
orderItemDO.setSkuName(productSkuDetailBO.getSpu().getName());
orderItemDO.setPrice(productSkuDetailBO.getPrice());
orderItemDO.setLogisticsPrice(0);
int payAmount = orderItemDO.getQuantity() * orderItemDO.getPrice();
orderItemDO.setPayAmount(payAmount);
@ -206,10 +241,14 @@ public class OrderServiceImpl implements OrderService {
// TODO: 2019-04-11 Sin 订单号需要生成规则
String orderNo = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
Integer totalAmount = orderCommon.calculatedAmount(orderItemDOList);
Integer totalPrice = orderCommon.calculatedPrice(orderItemDOList);
Integer totalLogisticsPrice = orderCommon.calculatedLogisticsPrice(orderItemDOList);
OrderDO orderDO = new OrderDO()
.setUserId(userId)
.setOrderNo(orderNo)
.setPrice(totalPrice)
.setPayAmount(totalAmount)
.setLogisticsPrice(totalLogisticsPrice)
.setClosingTime(null)
.setDeliveryTime(null)
.setPaymentTime(null)
@ -223,7 +262,9 @@ public class OrderServiceImpl implements OrderService {
orderMapper.insert(orderDO);
// 收件人信息
CommonResult<UserAddressBO> userAddressResult = userAddressService.getAddress(userId, orderCreateDTO.getUserAddressId());
CommonResult<UserAddressBO> userAddressResult
= userAddressService.getAddress(userId, orderCreateDTO.getUserAddressId());
if (userAddressResult.isError()) {
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_USER_ADDRESS_FAIL.getCode());
}
@ -310,9 +351,16 @@ public class OrderServiceImpl implements OrderService {
orderItemMapper.updateById(new OrderItemDO().setId(orderItemId).setPayAmount(payAmount));
// 再重新计算订单金额
List<OrderItemDO> orderItemDOList = orderItemMapper.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue());
Integer orderPayAmount = orderCommon.calculatedAmount(orderItemDOList);
orderMapper.updateById(new OrderDO().setId(orderId).setPayAmount(orderPayAmount));
List<OrderItemDO> orderItemDOList = orderItemMapper
.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue());
Integer price = orderCommon.calculatedPrice(orderItemDOList);
Integer amount = orderCommon.calculatedAmount(orderItemDOList);
orderMapper.updateById(
new OrderDO()
.setId(orderId)
.setPrice(price)
.setPayAmount(amount)
);
return CommonResult.success(null);
}

View File

@ -46,4 +46,19 @@
#{orderLogisticsId}
</foreach>
</select>
<!--
查询 - 最新的物流信息
-->
<select id="selectLatest" resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
SELECT
<include refid="FIELDS"/>
FROM order_logistics_detail
WHERE order_logistics_id IN
<foreach collection="orderLogisticsIds" item="orderLogisticsId" separator="," open="(" close=")">
#{orderLogisticsId}
</foreach>
ORDER BY create_time DESC
LIMIT 0, 1
</select>
</mapper>

View File

@ -3,8 +3,8 @@
<mapper namespace="cn.iocoder.mall.order.biz.dao.OrderMapper">
<sql id="FIELDS">
id, user_id, order_no, pay_amount, payment_time,
delivery_time, receiver_time, closing_time,
id, user_id, order_no, price, pay_amount, logistics_price,
payment_time, delivery_time, receiver_time, closing_time,
has_return_exchange,
status, remark, create_time, update_time, `deleted`
</sql>
@ -14,13 +14,13 @@
-->
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO `order` (
user_id, order_no, pay_amount, payment_time,
delivery_time, receiver_time, closing_time,
user_id, order_no, price, pay_amount, logistics_price,
payment_time, delivery_time, receiver_time, closing_time,
has_return_exchange,
status, remark, create_time, update_time, `deleted`
) VALUES (
#{userId}, #{orderNo}, #{payAmount}, #{paymentTime},
#{deliveryTime}, #{receiverTime}, #{closingTime},
#{userId}, #{orderNo}, #{price}, #{payAmount}, #{logisticsPrice},
#{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime},
#{hasReturnExchange},
#{status}, #{remark}, #{createTime}, #{updateTime}, #{deleted}
)
@ -34,9 +34,15 @@
<if test="orderNo != null">
, order_no = #{orderNo}
</if>
<if test="price != null">
, price = #{price}
</if>
<if test="payAmount != null">
, pay_amount = #{payAmount}
</if>
<if test="logisticsPrice != null">
, logistics_price = #{logisticsPrice}
</if>
<if test="paymentTime != null">
, payment_time = #{paymentTime}