|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.txz.cif.dto.UserDTO;
|
|
@@ -19,6 +20,7 @@ import dto.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -440,7 +442,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
* @param productNum 购买数量
|
|
|
* @return MyRecord
|
|
|
*/
|
|
|
- private Map<String, Object> commonValidateCombination(StoreCombination storeCombination, ProductAttrValue combinationAttrValue, Long userId, Integer productNum) {
|
|
|
+ private MyRecord commonValidateCombination(StoreCombination storeCombination, ProductAttrValue combinationAttrValue, Long userId, Integer productNum) {
|
|
|
// 判断拼团时间段
|
|
|
Date date = new Date();
|
|
|
if (date.before(storeCombination.getStartTime())) {
|
|
@@ -491,9 +493,9 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- HashMap<String, Object> map = new LinkedHashMap<>();
|
|
|
- map.put("productAttrValue", productAttrValue);
|
|
|
- return map;
|
|
|
+ MyRecord record = new MyRecord();
|
|
|
+ record.set("productAttrValue", productAttrValue);
|
|
|
+ return record;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -604,16 +606,14 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
// }
|
|
|
// }
|
|
|
// // 积分部分
|
|
|
-// BigDecimal payPrice = orderInfoVo.getProTotalFee().add(priceResponse.getFreightFee()).subtract(priceResponse.getCouponFee());
|
|
|
-// priceResponse.setUseIntegral(request.getUseIntegral());
|
|
|
-// priceResponse.setProTotalFee(orderInfoVo.getProTotalFee());
|
|
|
-// if (!request.getUseIntegral() || user.getIntegral() <= 0) {// 不使用积分
|
|
|
-// priceResponse.setDeductionPrice(BigDecimal.ZERO);
|
|
|
+ BigDecimal payPrice = orderInfoVo.getProTotalFee().add(priceResponse.getFreightFee()).subtract(priceResponse.getCouponFee());
|
|
|
+ priceResponse.setProTotalFee(orderInfoVo.getProTotalFee());
|
|
|
+ // 不使用积分
|
|
|
+ priceResponse.setDeductionPrice(BigDecimal.ZERO);
|
|
|
// priceResponse.setSurplusIntegral(user.getIntegral());
|
|
|
-// priceResponse.setPayFee(payPrice);
|
|
|
-// priceResponse.setUsedIntegral(0);
|
|
|
-// return priceResponse;
|
|
|
-// }
|
|
|
+ priceResponse.setPayFee(payPrice);
|
|
|
+ priceResponse.setUsedIntegral(0);
|
|
|
+ return priceResponse;
|
|
|
// // 使用积分
|
|
|
// // 查询积分使用比例
|
|
|
// String integralRatio = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_KEY_INTEGRAL_RATE);
|
|
@@ -636,7 +636,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
// priceResponse.setPayFee(payPrice);
|
|
|
// priceResponse.setDeductionPrice(deductionPrice);
|
|
|
// }
|
|
|
- return priceResponse;
|
|
|
+// return priceResponse;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -863,4 +863,254 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
preOrderResponse.setYuePayStatus(1);
|
|
|
return preOrderResponse;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void createOrder(CreateOrderRequest request) {
|
|
|
+ UserDTO user = userDubboServiceClient.getUser(request.getUserId());
|
|
|
+ // 通过缓存获取预下单对象
|
|
|
+ String key = "user_order:" + request.getPreOrderNo();
|
|
|
+ boolean exists = redisUtil.hasKey(key);
|
|
|
+ if (!exists) {
|
|
|
+ throw new ServiceException("预下单订单不存在");
|
|
|
+ }
|
|
|
+ String orderVoString = redisUtil.get(key).toString();
|
|
|
+ OrderInfoVO orderInfoVo = JSONObject.parseObject(orderVoString, OrderInfoVO.class);
|
|
|
+
|
|
|
+ request.setPayType("yue");
|
|
|
+ request.setShippingType(1);
|
|
|
+
|
|
|
+// if (request.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) {
|
|
|
+// // 检测支付渠道
|
|
|
+// if (StrUtil.isBlank(request.getPayChannel())) {
|
|
|
+// throw new ServiceException("支付渠道不能为空!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ // 校验商品库存
|
|
|
+ List<MyRecord> skuRecordList = validateProductStock(orderInfoVo, user);
|
|
|
+
|
|
|
+ // 校验收货信息
|
|
|
+ String verifyCode = "";
|
|
|
+ String userAddressStr = "";
|
|
|
+// if (request.getShippingType() == 1) {
|
|
|
+// // 快递配送
|
|
|
+// if (request.getAddressId() <= 0) {
|
|
|
+// throw new ServiceException("请选择收货地址");
|
|
|
+// }
|
|
|
+// UserAddress userAddress = userAddressService.findById(request.getAddressId());
|
|
|
+// if (ObjectUtil.isNull(userAddress) || userAddress.getIsDelete().equals(1)) {
|
|
|
+// throw new ServiceException("收货地址有误");
|
|
|
+// }
|
|
|
+// request.setRealName(userAddress.getRealName());
|
|
|
+// request.setPhone(userAddress.getPhone());
|
|
|
+// userAddressStr = userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getDetail();
|
|
|
+// }
|
|
|
+
|
|
|
+ // 计算订单各种价格
|
|
|
+ OrderComputedPriceRequest orderComputedPriceRequest = new OrderComputedPriceRequest();
|
|
|
+ orderComputedPriceRequest.setShippingType(request.getShippingType());
|
|
|
+ orderComputedPriceRequest.setAddressId(request.getAddressId());
|
|
|
+// orderComputedPriceRequest.setCouponId(request.getCouponId());
|
|
|
+// orderComputedPriceRequest.setUseIntegral(request.getUseIntegral());
|
|
|
+ ComputedOrderPriceResponse computedOrderPriceResponse = computedPrice(orderComputedPriceRequest, orderInfoVo, user);
|
|
|
+
|
|
|
+ // 生成订单号
|
|
|
+ String orderNo = OrderUtils.getOrderCode();
|
|
|
+
|
|
|
+ // 购买赠送的积分
|
|
|
+ List<StoreOrderInfo> storeOrderInfos = new ArrayList<>();
|
|
|
+ for (OrderInfoDetailVO detailVo : orderInfoVo.getOrderDetailList()) {
|
|
|
+ // 订单详情
|
|
|
+ StoreOrderInfo soInfo = new StoreOrderInfo();
|
|
|
+ soInfo.setProductId(detailVo.getProductId());
|
|
|
+ soInfo.setInfo(JSON.toJSON(detailVo).toString());
|
|
|
+ soInfo.setOrderNo(orderNo);
|
|
|
+ soInfo.setProductName(detailVo.getProductName());
|
|
|
+ soInfo.setAttrValueId(detailVo.getAttrValueId());
|
|
|
+ soInfo.setImage(detailVo.getImage());
|
|
|
+ soInfo.setSku(detailVo.getSku());
|
|
|
+ soInfo.setPrice(detailVo.getPrice());
|
|
|
+ soInfo.setPayNum(detailVo.getPayNum());
|
|
|
+ soInfo.setWeight(detailVo.getWeight());
|
|
|
+ soInfo.setVolume(detailVo.getVolume());
|
|
|
+ if (ObjectUtil.isNotNull(detailVo.getGiveIntegral()) && detailVo.getGiveIntegral() > 0) {
|
|
|
+ soInfo.setGiveIntegral(detailVo.getGiveIntegral());
|
|
|
+ } else {
|
|
|
+ soInfo.setGiveIntegral(0);
|
|
|
+ }
|
|
|
+ soInfo.setIsReply(0);
|
|
|
+ soInfo.setIsSub(detailVo.getIsSub());
|
|
|
+ soInfo.setProductType(detailVo.getProductType());
|
|
|
+ if (ObjectUtil.isNotNull(detailVo.getVipPrice())) {
|
|
|
+ soInfo.setVipPrice(detailVo.getVipPrice());
|
|
|
+ } else {
|
|
|
+ soInfo.setVipPrice(detailVo.getPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ storeOrderInfos.add(soInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付渠道 默认:余额支付
|
|
|
+ int isChannel = 3;
|
|
|
+ StoreOrder storeOrder = new StoreOrder();
|
|
|
+ storeOrder.setUid(user.getId());
|
|
|
+ storeOrder.setOrderId(orderNo);
|
|
|
+ storeOrder.setRealName(request.getRealName());
|
|
|
+ storeOrder.setUserPhone(request.getPhone());
|
|
|
+ storeOrder.setUserAddress(userAddressStr);
|
|
|
+ storeOrder.setTotalNum(orderInfoVo.getOrderProNum());
|
|
|
+ storeOrder.setCouponId(Optional.ofNullable(request.getCouponId()).orElse(0L));
|
|
|
+
|
|
|
+ // 订单总价
|
|
|
+ BigDecimal totalPrice = computedOrderPriceResponse.getProTotalFee().add(computedOrderPriceResponse.getFreightFee());
|
|
|
+
|
|
|
+ storeOrder.setTotalPrice(totalPrice);
|
|
|
+ storeOrder.setProTotalPrice(computedOrderPriceResponse.getProTotalFee());
|
|
|
+ storeOrder.setTotalPostage(computedOrderPriceResponse.getFreightFee());
|
|
|
+ storeOrder.setCouponPrice(computedOrderPriceResponse.getCouponFee());
|
|
|
+ storeOrder.setPayPrice(computedOrderPriceResponse.getPayFee());
|
|
|
+ storeOrder.setPayPostage(computedOrderPriceResponse.getFreightFee());
|
|
|
+ storeOrder.setDeductionPrice(computedOrderPriceResponse.getDeductionPrice());
|
|
|
+ storeOrder.setPayType(request.getPayType());
|
|
|
+// storeOrder.setUseIntegral(computedOrderPriceResponse.getUsedIntegral());
|
|
|
+// storeOrder.setGainIntegral(gainIntegral);
|
|
|
+ storeOrder.setMark(StringEscapeUtils.escapeHtml4(request.getMark()));
|
|
|
+ storeOrder.setCombinationId(orderInfoVo.getCombinationId());
|
|
|
+ storeOrder.setPinkId(orderInfoVo.getPinkId());
|
|
|
+ storeOrder.setBargainUserId(orderInfoVo.getBargainUserId());
|
|
|
+ storeOrder.setCreateTime(new Date());
|
|
|
+ storeOrder.setShippingType(request.getShippingType());
|
|
|
+ storeOrder.setIsChannel(isChannel);
|
|
|
+ storeOrder.setPaid(0);
|
|
|
+ storeOrder.setCost(BigDecimal.ZERO);
|
|
|
+ storeOrder.setType(0);
|
|
|
+
|
|
|
+// StoreCouponUser storeCouponUser = new StoreCouponUser();
|
|
|
+// // 优惠券修改
|
|
|
+// if (storeOrder.getCouponId() > 0) {
|
|
|
+// storeCouponUser = storeCouponUserService.getById(storeOrder.getCouponId());
|
|
|
+// storeCouponUser.setStatus(1);
|
|
|
+// }
|
|
|
+// StoreCouponUser finalStoreCouponUser = storeCouponUser;
|
|
|
+
|
|
|
+ // 扣减库存
|
|
|
+ // 需要根据是否活动商品,扣减不同的库存
|
|
|
+ if (storeOrder.getCombinationId() > 0) {
|
|
|
+ // 拼团扣库存
|
|
|
+ MyRecord skuRecord = skuRecordList.get(0);
|
|
|
+ // 拼团商品扣库存
|
|
|
+ storeCombinationService.operationStock(skuRecord.getInt("activityId"), skuRecord.getInt("num"), "sub");
|
|
|
+ // 拼团商品规格扣库存
|
|
|
+ productAttrValueService.operationStock(skuRecord.getInt("activityAttrValueId"), skuRecord.getInt("num"), "sub", Constants.PRODUCT_TYPE_PINGTUAN);
|
|
|
+ // 普通商品口库存
|
|
|
+ storeProductService.operationStock(skuRecord.getInt("productId"), skuRecord.getInt("num"), "sub");
|
|
|
+ // 普通商品规格扣库存
|
|
|
+ productAttrValueService.operationStock(skuRecord.getInt("attrValueId"), skuRecord.getInt("num"), "sub", Constants.PRODUCT_TYPE_NORMAL);
|
|
|
+ } else { // 普通商品
|
|
|
+ for (MyRecord skuRecord : skuRecordList) {
|
|
|
+ // 普通商品口库存
|
|
|
+ storeProductService.operationStock(skuRecord.getInt("productId"), skuRecord.getInt("num"), "sub");
|
|
|
+ // 普通商品规格扣库存
|
|
|
+ productAttrValueService.operationStock(skuRecord.getInt("attrValueId"), skuRecord.getInt("num"), "sub", Constants.PRODUCT_TYPE_NORMAL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// storeOrderService.create(storeOrder);
|
|
|
+ storeOrderInfos.forEach(info -> info.setOrderId(storeOrder.getId()));
|
|
|
+ // 优惠券修改
|
|
|
+// if (storeOrder.getCouponId() > 0) {
|
|
|
+// storeCouponUserService.updateById(finalStoreCouponUser);
|
|
|
+// }
|
|
|
+// // 保存购物车商品详情
|
|
|
+// storeOrderInfoService.saveOrderInfos(storeOrderInfos);
|
|
|
+// // 生成订单日志
|
|
|
+// storeOrderStatusService.createLog(storeOrder.getId(), Constants.ORDER_STATUS_CACHE_CREATE_ORDER, "订单生成");
|
|
|
+//
|
|
|
+// // 清除购物车数据
|
|
|
+// if (CollUtil.isNotEmpty(orderInfoVo.getCartIdList())) {
|
|
|
+// storeCartService.deleteCartByIds(orderInfoVo.getCartIdList());
|
|
|
+// }
|
|
|
+// return Boolean.TRUE;
|
|
|
+
|
|
|
+ // 删除缓存订单
|
|
|
+ if (redisUtil.hasKey(key)) {
|
|
|
+ redisUtil.del(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加入自动未支付自动取消队列
|
|
|
+// redisUtil.lPush(Constants.ORDER_AUTO_CANCEL_KEY, storeOrder.getOrderId());
|
|
|
+//
|
|
|
+ MyRecord record = new MyRecord();
|
|
|
+ record.set("orderNo", storeOrder.getOrderId());
|
|
|
+// return record;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验商品库存(生成订单)
|
|
|
+ *
|
|
|
+ * @param orderInfoVo 订单详情Vo
|
|
|
+ * @return List<MyRecord>
|
|
|
+ * skuRecord 扣减库存对象
|
|
|
+ * ——activityId 活动商品id
|
|
|
+ * ——activityAttrValueId 活动商品skuId
|
|
|
+ * ——productId 普通(主)商品id
|
|
|
+ * ——attrValueId 普通(主)商品skuId
|
|
|
+ * ——num 购买数量
|
|
|
+ */
|
|
|
+ private List<MyRecord> validateProductStock(OrderInfoVO orderInfoVo, UserDTO user) {
|
|
|
+ List<MyRecord> recordList = CollUtil.newArrayList();
|
|
|
+ if (orderInfoVo.getCombinationId() > 0) {
|
|
|
+ // 拼团部分判断
|
|
|
+ Long combinationId = orderInfoVo.getCombinationId();
|
|
|
+ OrderInfoDetailVO detailVo = orderInfoVo.getOrderDetailList().get(0);
|
|
|
+ StoreCombination storeCombination = storeCombinationService.getByIdException(combinationId);
|
|
|
+ ProductAttrValue combinationAttrValue = productAttrValueService.getByIdAndProductIdAndType(detailVo.getAttrValueId(), combinationId, Constants.PRODUCT_TYPE_PINGTUAN);
|
|
|
+ if (ObjectUtil.isNull(combinationAttrValue)) {
|
|
|
+ throw new ServiceException("拼团商品规格不存在");
|
|
|
+ }
|
|
|
+ MyRecord combinationRecord = commonValidateCombination(storeCombination, combinationAttrValue, user.getId(), detailVo.getPayNum());
|
|
|
+ ProductAttrValue productAttrValue = combinationRecord.get("productAttrValue");
|
|
|
+
|
|
|
+ MyRecord record = new MyRecord();
|
|
|
+ record.set("activityId", combinationId);
|
|
|
+ record.set("activityAttrValueId", combinationAttrValue.getId());
|
|
|
+ record.set("productId", storeCombination.getProductId());
|
|
|
+ record.set("attrValueId", productAttrValue.getId());
|
|
|
+ record.set("num", detailVo.getPayNum());
|
|
|
+ recordList.add(record);
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
+ // 普通商品
|
|
|
+ List<OrderInfoDetailVO> orderDetailList = orderInfoVo.getOrderDetailList();
|
|
|
+ orderDetailList.forEach(e -> {
|
|
|
+ // 查询商品信息
|
|
|
+ StoreProduct storeProduct = storeProductService.findById(e.getProductId());
|
|
|
+ if (ObjectUtil.isNull(storeProduct)) {
|
|
|
+ throw new ServiceException("购买的商品信息不存在");
|
|
|
+ }
|
|
|
+ if (storeProduct.getIsDelete().equals(1)) {
|
|
|
+ throw new ServiceException("购买的商品已删除");
|
|
|
+ }
|
|
|
+ if (!storeProduct.getIsShow().equals(0)) {
|
|
|
+ throw new ServiceException("购买的商品已下架");
|
|
|
+ }
|
|
|
+ if (storeProduct.getStock().equals(0) || e.getPayNum() > storeProduct.getStock()) {
|
|
|
+ throw new ServiceException("购买的商品库存不足");
|
|
|
+ }
|
|
|
+ // 查询商品规格属性值信息
|
|
|
+ ProductAttrValue attrValue = productAttrValueService.getByIdAndProductIdAndType(e.getAttrValueId(), e.getProductId(), Constants.PRODUCT_TYPE_NORMAL);
|
|
|
+ if (ObjectUtil.isNull(attrValue)) {
|
|
|
+ throw new ServiceException("购买的商品规格信息不存在");
|
|
|
+ }
|
|
|
+ if (attrValue.getStock() < e.getPayNum()) {
|
|
|
+ throw new ServiceException("购买的商品库存不足");
|
|
|
+ }
|
|
|
+ MyRecord record = new MyRecord();
|
|
|
+ record.set("productId", e.getProductId());
|
|
|
+ record.set("num", e.getPayNum());
|
|
|
+ record.set("attrValueId", e.getAttrValueId());
|
|
|
+ recordList.add(record);
|
|
|
+ });
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
}
|