| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.sinata.common.enums.EnumMemberGrade; |
| | | import com.sinata.common.enums.EnumPayType; |
| | | import com.sinata.common.enums.EnumUserBankDetailDoneType; |
| | |
| | | |
| | | @Override |
| | | public Object createOrder(List<BodyMallOrder> list) { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | try { |
| | | log.info("createOrder:{}", objectMapper.writeValueAsString(list)); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // 持久化数据组 |
| | | List<MallOrder> orderList = new ArrayList<>(); |
| | | List<MallOrderDetail> orderDetailList = new ArrayList<>(); |
| | |
| | | order.setIdCard(body.getIdCard()); |
| | | order.setNumber(body.getNumber()); |
| | | order.setState(EnumMallOrderState.WAIT_PAY.index); |
| | | if (Objects.isNull(order.getCityCode())) { |
| | | AreaCity city = areaCityMapper.getCityByMerchantId(body.getMerchantId()); |
| | | Optional.ofNullable(city).ifPresent(c ->order.setCityCode(c.getCityCode())); |
| | | } |
| | | // 生成订单编号 |
| | | String generateOrderNo = dailyIncrementIdGenerator.generateId(); |
| | | order.setOrderNo(generateOrderNo); |
| | |
| | | if(skuVo.getStock() < boSku.getGoodsNum()) { |
| | | return ApiUtils.returnNG(null, "商品:" + skuVo.getGoodsName() + ",库存不足"); |
| | | } |
| | | log.info("商品:{},减去库存:{}",skuVo,boSku.getGoodsNum()); |
| | | // 减去库存 |
| | | goodsSkuService.updateStock(skuVo.getSkuId(), -boSku.getGoodsNum()); |
| | | goodsSkuService.updateStock(skuVo.getId(), -1 * boSku.getGoodsNum()); |
| | | |
| | | // 商品价格 |
| | | BigDecimal sellCost; |
| | |
| | | // 美天销售价 |
| | | sellCost = skuVo.getPriceSale(); |
| | | } else { |
| | | if (user != null && user.getMemberGradeId() != EnumMemberGrade.G_1.index) { |
| | | if (user != null && user.getMemberGradeId() != EnumMemberGrade.G_1.index && EnumMemberGrade.G_2.index != user.getMemberGradeId()) { |
| | | // 会员价 |
| | | sellCost = skuVo.getPriceMember(); |
| | | } else { |
| | |
| | | // 销售价 |
| | | sellCost = skuVo.getPriceMerchant(); |
| | | } |
| | | |
| | | // 查询套餐规格组ID |
| | | MallGroupSpec mallGroupSpec = mallGroupSpecService.getById(skuVo.getSpecIds()); |
| | | List<GroupSpecGoodsSkuJsonVo> groupSpecGoodsSkuJsonVoList = JSONUtil.parseArray(mallGroupSpec.getGoodsSkuJson()).toList(GroupSpecGoodsSkuJsonVo.class); |
| | |
| | | .select(MallOrderDetail::getSkuId, MallOrderDetail::getGoodsNum) |
| | | .eq(MallOrderDetail::getOrderNo, orderNo); |
| | | List<MallOrderDetail> orderDetails = orderDetailService.list(orderDetailLambdaQueryWrapper); |
| | | log.info("-----------------------开始退回库存--------------------"); |
| | | log.info("orderDetails:{}", JSON.toJSONString(orderDetails)); |
| | | for (MallOrderDetail od : orderDetails) { |
| | | // 增加库存 |
| | | goodsSkuService.updateStock(od.getSkuId(), od.getGoodsNum()); |
| | | } |
| | | |
| | | log.info("-----------------------退回库存结束--------------------"); |
| | | if (order.getCouponId() != null && order.getCouponId() != 0) { |
| | | // 退还优惠券 |
| | | myCouponService.updateUseCoupon(order.getUserId(), order.getCouponId(), 0); |