diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardAfterSaleCarEntity.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardAfterSaleCarEntity.java index 6fb403f0c..28a55d8fc 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardAfterSaleCarEntity.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardAfterSaleCarEntity.java @@ -63,6 +63,12 @@ public class HardAfterSaleCarEntity extends Model { @Schema(description = "商品价格") private Long productPrice; + /** + * 商品性质(字典) + */ + @Schema(description = "商品性质(字典)") + private String productNature; + /** * 数量 */ diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java index fc55a87d3..4908c3de3 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java @@ -3,12 +3,14 @@ package com.bsd.pjcloud.hard.controller.hard; import cn.hutool.core.util.ObjectUtil; import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.idempotent.annotation.Idempotent; +import com.bsd.pjcloud.hard.api.constant.HardProductNatureEnum; import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; import com.bsd.pjcloud.hard.api.dto.async.SyncOfflineReqVo; import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto; import com.bsd.pjcloud.hard.api.dto.hard.HardBindDto; import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto; import com.bsd.pjcloud.hard.api.dto.order.HardChartLatitudeVo; +import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; import com.bsd.pjcloud.hard.api.vo.HardInvoiceVo; import com.bsd.pjcloud.hard.api.vo.manager.HardManagerVo; import com.bsd.pjcloud.hard.api.vo.android.HardAdUserVo; @@ -23,6 +25,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.*; +import java.math.BigDecimal; import java.util.List; @RestController @@ -68,6 +71,17 @@ public class HardApiController { @Operation(summary = "创建订单") @Idempotent(expireTime = 10, info = "正在创建订单中,请勿重复操作") public R createOrder(@Valid @RequestBody HardCreateOrderDto dto) { + // 处理商品类型 + if (ObjectUtil.isNotEmpty(dto.getList())) { + for (HardCreateCarDto item : dto.getList()) { + if (ObjectUtil.isEmpty(item.getProductNature())) continue; + if (ObjectUtil.isNotEmpty(item.getProductWeight()) && item.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) { + item.setProductNature(HardProductNatureEnum.WEIGHT); + } else if (ObjectUtil.isNotEmpty(item.getProductCount())) { + item.setProductNature(HardProductNatureEnum.DEFAULT); + } + } + } return R.ok(hardwareOrderService.createOrder(dto)); } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java index 51336d73e..3a0349244 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java @@ -14,6 +14,7 @@ import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto; import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; import com.bsd.pjcloud.hard.api.dto.order.app.HardAppCreateOrderDto; +import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity; import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; import com.bsd.pjcloud.thirdparty.dto.ks.KsRecognitionCallbackDto; @@ -104,6 +105,8 @@ public interface HardOrderService extends IService { */ void fastenerInventory(HardOrderEntity order, YesNoEnum isReduce); + void fastenerInventory(HardOrderEntity order, List refundCarList, YesNoEnum isReduce); + /** * 核销硬件二维码 */ diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleCarServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleCarServiceImpl.java index d032dab6d..515ddf1dd 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleCarServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleCarServiceImpl.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.util.ArrayList; import java.util.List; /** @@ -48,6 +49,10 @@ public class HardAfterSaleCarServiceImpl extends ServiceImpl saveList = new ArrayList<>(carList).stream().map(item -> { + item.setId(null); + return item; + }).toList(); + saveBatch(saveList); } } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleServiceImpl.java index d2e6f1f02..954dd9689 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardAfterSaleServiceImpl.java @@ -20,6 +20,8 @@ import com.bsd.pjcloud.common.core.util.CollectionUtils; import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.data.datascope.DataScope; import com.bsd.pjcloud.common.security.service.PjcloudUser; +import com.bsd.pjcloud.hard.api.constant.HardProductNatureEnum; +import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum; @@ -30,10 +32,7 @@ import com.bsd.pjcloud.hard.api.constant.refund.HardSaleTypeEnum; import com.bsd.pjcloud.hard.api.dto.ali.AliRefundDto; import com.bsd.pjcloud.hard.api.dto.order.*; import com.bsd.pjcloud.hard.api.dto.wechat.WechatRefundDto; -import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleCarEntity; -import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity; -import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity; -import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.*; import com.bsd.pjcloud.hard.api.utils.HardUtil; import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo; import com.bsd.pjcloud.hard.api.vo.order.HardCarVo; @@ -230,7 +229,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl computerCarList = dto.getCarList().stream().map((item) -> { + HardCreateCarDto entity = new HardCreateCarDto(); + entity.setParentCarId(item.getParentCarId()); + entity.setProductId(item.getProductId()); + entity.setProductNature(HardProductNatureEnum.valueOfByType(item.getProductNature())); + entity.setProductCount(item.getProductCount()); + entity.setProductWeight(item.getProductWeight()); + return entity; + }).toList(); + int refundPrice = hardCarService.computerCarTotalPrice(HardTypeEnum.valueOfByType(order.getSysType()), HardOrderTypeEnum.valueOfByType(order.getOrderType()), computerCarList); + saveObj.setType(HardSaleTypeEnum.AFTER_SALE.getType()); saveObj.setStatus(HardSaleStatusEnum.COMPLETE.getStatus()); saveObj.setNo(refundCode); saveObj.setOrderId(order.getId()); - saveObj.setRefundPrice(order.getPayPrice()); + saveObj.setRefundPrice(refundPrice); saveObj.setUserId(order.getUserId()); saveObj.setAuditUserId(user.getId()); saveObj.setAuditTime(LocalDateTime.now()); @@ -562,7 +574,15 @@ public class HardAfterSaleServiceImpl extends ServiceImpl carList = dto.getCarList().stream().map((item) -> + HardCarEntity.builder() + .productId(item.getProductId()) + .productCount(item.getProductCount()) + .productWeight(item.getProductWeight()) + .productNature(item.getProductName()) + .build() + ).toList(); + hardOrderService.fastenerInventory(order, carList, YesNoEnum.NO); return true; } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java index cfe417b73..9daab3696 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java @@ -259,7 +259,9 @@ public class HardCarServiceImpl extends ServiceImpl refundCarList, YesNoEnum isReduce) { HardTypeEnum hardTypeEnum = HardTypeEnum.valueOfByType(order.getSysType()); HardOrderTypeEnum orderTypeEnum = HardOrderTypeEnum.valueOfByType(order.getOrderType()); if (!ObjectUtil.isAllNotEmpty(hardTypeEnum, orderTypeEnum)) return; @@ -867,6 +873,13 @@ public class HardOrderServiceImpl extends ServiceImpl ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null); + if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) { + item.setIncrCount(refundCarTarget.getProductCount() * base); + } + } return item; }).toList(); dto.setItems(list); @@ -889,15 +902,31 @@ public class HardOrderServiceImpl extends ServiceImpl ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null); + if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) { + prouctCount = refundCarTarget.getProductCount(); + } + } + double count = BigDecimal.valueOf(prouctCount).multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue(); item.setIncrCount(count); } else if (ObjectUtil.isNotEmpty(v.getProductWeight()) && v.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) { // 按重量 - double weight = v.getProductWeight().multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue(); + BigDecimal productWeight = v.getProductWeight(); + // 如果退款购物车数组里有,就用退款购物车的数量 + if (ObjectUtil.isNotEmpty(refundCarList)) { + HardCarEntity refundCarTarget = refundCarList.stream().filter(i -> ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null); + if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) { + productWeight = refundCarTarget.getProductWeight(); + } + } + double weight = productWeight.multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue(); item.setIncrCount(weight); } return item; - }).toList(); + }).filter(v -> ObjectUtil.isNotEmpty(v.getIncrCount()) && v.getIncrCount() > 0).toList(); dto.setItems(list); R updateSkuStockRes = supermarketSpuService.updateSpuStock(dto); if (updateSkuStockRes.getCode() != 0) { @@ -916,6 +945,13 @@ public class HardOrderServiceImpl extends ServiceImpl ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null); + if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) { + entity.setIncrCount(refundCarTarget.getProductCount()); + } + } return entity; }).toList(); // 查询订单流程 diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardAfterSaleCarMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardAfterSaleCarMapper.xml index df7bfff24..4859c1a72 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardAfterSaleCarMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardAfterSaleCarMapper.xml @@ -9,6 +9,7 @@ a.product_id, a.product_name, a.product_pic, + a.product_nature, a.product_price, a.product_count, a.product_weight, @@ -41,7 +42,8 @@ a.product_id, a.product_name, a.product_pic, - sum(a.product_price) as productPrice, + a.product_nature, + a.product_price, sum(a.product_count) as productCount, sum(a.product_weight) as productWeight, sum(a.total_price) as totalPrice,