|
|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ylx.common.constant.HttpStatus;
|
|
|
import com.ylx.common.constant.MassageConstants;
|
|
|
import com.ylx.common.core.domain.R;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
@@ -86,6 +87,11 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String createProductOrder(ProductOrderCreateRequest request) {
|
|
|
+ // 当前登录用户信息
|
|
|
+ WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
+ // 设置用户ID
|
|
|
+ request.setOpenId(wxLoginUser.getCOpenid());
|
|
|
+
|
|
|
// 1. 参数校验
|
|
|
validateRequest(request);
|
|
|
|
|
|
@@ -124,16 +130,13 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
|
|
|
if (request == null) {
|
|
|
throw new ServiceException("订单请求不能为空");
|
|
|
}
|
|
|
- if (request.getOpenId() == null || request.getOpenId().trim().isEmpty()) {
|
|
|
- throw new ServiceException("用户ID不能为空");
|
|
|
- }
|
|
|
- if (request.getUserName() == null) {
|
|
|
+ if (StringUtils.isBlank(request.getUserName())) {
|
|
|
throw new ServiceException("用户姓名不能为空");
|
|
|
}
|
|
|
- if (request.getUserPhone() == null) {
|
|
|
+ if (StringUtils.isBlank(request.getUserPhone())) {
|
|
|
throw new ServiceException("用户电话不能为空");
|
|
|
}
|
|
|
- if (request.getUserAddress() == null) {
|
|
|
+ if (StringUtils.isBlank(request.getUserAddress())) {
|
|
|
throw new ServiceException("用户地址不能为空");
|
|
|
}
|
|
|
if (request.getProductId() == null) {
|
|
|
@@ -148,6 +151,18 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
|
|
|
if (request.getSkuId() == null) {
|
|
|
throw new ServiceException("SKU ID不能为空");
|
|
|
}
|
|
|
+
|
|
|
+ // 校验SKU是否存在
|
|
|
+ ProductSku sku = productSkuMapper.selectById(request.getSkuId());
|
|
|
+ if (sku == null) {
|
|
|
+ throw new ServiceException("skuId不存在");
|
|
|
+ }
|
|
|
+ //校验skuId是否正确
|
|
|
+ if (!sku.getProductId().equals(request.getProductId())) {
|
|
|
+ throw new ServiceException("skuId不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验购买数量是否大于0
|
|
|
if (request.getQuantity() == null || request.getQuantity() <= 0) {
|
|
|
throw new ServiceException("购买数量必须大于0");
|
|
|
}
|
|
|
@@ -497,8 +512,14 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
|
|
|
*/
|
|
|
@Override
|
|
|
public R<?> cancelOrder(ProductOrderCancelRequest request) {
|
|
|
+ // 当前登录用户信息
|
|
|
+ WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
+ if (wxLoginUser == null) {
|
|
|
+ throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
|
|
|
+ }
|
|
|
+
|
|
|
String orderNo = request.getOrderNo();
|
|
|
- String openId = request.getOpenId();
|
|
|
+ String openId = wxLoginUser.getCOpenid();
|
|
|
String cancelReason = request.getCancelReason();
|
|
|
log.info("取消商品订单,订单号:{},openId:{},取消原因:{}", orderNo, openId, cancelReason);
|
|
|
|