From 2f4b9816caa150a948ba6fabe3e4025f4667a236 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Fri, 02 Feb 2024 11:11:09 +0800
Subject: [PATCH] 购物车使用优惠卷
---
src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java | 3 +
src/main/java/cc/mrbird/febs/mall/service/MallInvoiceService.java | 2
src/main/java/cc/mrbird/febs/mall/controller/ApiMallOrderController.java | 6 ++
src/main/java/cc/mrbird/febs/mall/service/IApiMallOrderInfoService.java | 2
src/main/java/cc/mrbird/febs/mall/dto/ApiChooseCouponDto.java | 18 ++++++
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java | 40 ++++++++++---
src/main/java/cc/mrbird/febs/mall/vo/ApiCouponAmountMapVo.java | 16 +++++
src/main/java/cc/mrbird/febs/mall/controller/AdminMallOrderController.java | 11 +++
src/main/java/cc/mrbird/febs/mall/vo/OrderItemVo.java | 3 +
src/main/java/cc/mrbird/febs/mall/service/impl/MallInvoiceServiceImpl.java | 24 ++++++++
src/main/resources/templates/febs/views/modules/order/invoiceList.html | 15 ++++
11 files changed, 129 insertions(+), 11 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/AdminMallOrderController.java b/src/main/java/cc/mrbird/febs/mall/controller/AdminMallOrderController.java
index cff652b..7973074 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/AdminMallOrderController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/AdminMallOrderController.java
@@ -704,4 +704,15 @@
return mallInvoiceService.updateInvoiceDetail(id);
}
+ /**
+ * 发票列表-更新订单状态
+ * @param id
+ * @return
+ */
+ @GetMapping("updateOrderDetail/{id}")
+ @ControllerEndpoint(operation = "发票列表-更新订单状态", exceptionMessage = "操作失败")
+ public FebsResponse updateOrderDetail(@NotNull(message = "{required}") @PathVariable Long id) {
+ return mallInvoiceService.updateOrderDetail(id);
+ }
+
}
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallOrderController.java b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallOrderController.java
index 5975313..bdb6196 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallOrderController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallOrderController.java
@@ -39,6 +39,12 @@
return mallOrderInfoService.createOrderVerify(apiCreateOrderVerifyDto);
}
+ @ApiOperation(value = "选择优惠卷", notes = "选择优惠卷")
+ @PostMapping(value = "/chooseCoupon")
+ public FebsResponse chooseCoupon(@RequestBody ApiChooseCouponDto chooseCouponDto) {
+ return mallOrderInfoService.chooseCoupon(chooseCouponDto);
+ }
+
@ApiOperation(value = "创建订单", notes = "创建订单")
@PostMapping(value = "/createOrder")
public FebsResponse createOrder(@RequestBody AddOrderDto addOrderDto) {
diff --git a/src/main/java/cc/mrbird/febs/mall/dto/ApiChooseCouponDto.java b/src/main/java/cc/mrbird/febs/mall/dto/ApiChooseCouponDto.java
new file mode 100644
index 0000000..f5b92ed
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/mall/dto/ApiChooseCouponDto.java
@@ -0,0 +1,18 @@
+package cc.mrbird.febs.mall.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.List;
+
+@Data
+@ApiModel(value = "ApiChooseCouponDto", description = "参数接收类")
+public class ApiChooseCouponDto {
+
+ @ApiModelProperty(value = "会员优惠卷ID")
+ private Long memberCouponId;
+
+ @ApiModelProperty(value = "商品明细")
+ private List<AddOrderItemDto> items;
+
+}
diff --git a/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java b/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java
index 3bdbce5..29c9ed8 100644
--- a/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java
+++ b/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java
@@ -55,4 +55,7 @@
@TableField(exist = false)
private String unit;
+
+ @TableField(exist = false)
+ private BigDecimal itemAmount;
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IApiMallOrderInfoService.java b/src/main/java/cc/mrbird/febs/mall/service/IApiMallOrderInfoService.java
index 5632b26..1036672 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IApiMallOrderInfoService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IApiMallOrderInfoService.java
@@ -44,4 +44,6 @@
FebsResponse cancelRefundOrder(Long id);
FebsResponse createOrderVerify(ApiCreateOrderVerifyDto apiCreateOrderVerifyDto);
+
+ FebsResponse chooseCoupon(ApiChooseCouponDto chooseCouponDto);
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/MallInvoiceService.java b/src/main/java/cc/mrbird/febs/mall/service/MallInvoiceService.java
index 4be679a..e13ef1f 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/MallInvoiceService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/MallInvoiceService.java
@@ -28,4 +28,6 @@
FebsResponse addInvoiceUrl(MallInvoice mallInvoice);
FebsResponse updateInvoiceDetail(Long id);
+
+ FebsResponse updateOrderDetail(Long id);
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
index 924fbef..1b46a1c 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -13,10 +13,7 @@
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.*;
-import cc.mrbird.febs.mall.vo.ApiLeaderListVo;
-import cc.mrbird.febs.mall.vo.OrderDetailVo;
-import cc.mrbird.febs.mall.vo.OrderListVo;
-import cc.mrbird.febs.mall.vo.OrderRefundVo;
+import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.pay.model.BrandWCPayRequestData;
import cc.mrbird.febs.pay.model.OrderStateDto;
import cc.mrbird.febs.pay.service.IPayService;
@@ -219,11 +216,13 @@
//是否使用优惠卷
if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
Long memberCouponId = addOrderDto.getMemberCouponId();
- BigDecimal skuCouponAmount = couponAmountMap.get(item.getSkuId());//使用折扣卷后的应该支付的钱
- if(skuCouponAmount.compareTo(BigDecimal.ZERO) > 0){
- amount = skuCouponAmount;
+ if(ObjectUtil.isNotEmpty(couponAmountMap.get(item.getSkuId()))){
+ BigDecimal skuCouponAmount = couponAmountMap.get(item.getSkuId());//使用折扣卷后的应该支付的钱
+ if(skuCouponAmount.compareTo(BigDecimal.ZERO) > 0){
+ amount = skuCouponAmount;
+ }
+ orderItem.setMemberCouponId(memberCouponId);
}
- orderItem.setMemberCouponId(memberCouponId);
}
orderItem.setAmount(amount);
orderItem.setCnt(item.getCnt());
@@ -352,14 +351,14 @@
skuMapPercent.put(keySkuId,divide);
Integer type = mallGoodsCoupon.getType();
if(MallGoodsCoupon.TYPE_ONE == type){
- BigDecimal bigDecimal = realAmount.multiply(divide).setScale(2, BigDecimal.ROUND_DOWN);//每个SKU的减免金额(比例*减免金额)
+ BigDecimal bigDecimal = realAmount.multiply(divide).setScale(0, BigDecimal.ROUND_DOWN);//每个SKU的减免金额(比例*减免金额)
BigDecimal skuRealAmount = valueSkuAmount.subtract(bigDecimal.compareTo(BigDecimal.ZERO) > 0 ? bigDecimal : BigDecimal.ZERO);//实际支付金额
couponAmountMap.put(keySkuId,skuRealAmount);
}
if(MallGoodsCoupon.TYPE_TWO == type){
BigDecimal divideTime = totalAmount.divide(costAmount, 0, BigDecimal.ROUND_DOWN);//累计减免次数
BigDecimal multiply = divideTime.multiply(realAmount);//实际减免金额
- BigDecimal bigDecimal = multiply.multiply(divide).setScale(2, BigDecimal.ROUND_DOWN);//每个SKU的减免金额(比例*实际减免金额)
+ BigDecimal bigDecimal = multiply.multiply(divide).setScale(0, BigDecimal.ROUND_DOWN);//每个SKU的减免金额(比例*实际减免金额)
BigDecimal skuRealAmount = valueSkuAmount.subtract(bigDecimal.compareTo(BigDecimal.ZERO) > 0 ? bigDecimal : BigDecimal.ZERO);//实际支付金额
couponAmountMap.put(keySkuId,skuRealAmount);
}
@@ -612,6 +611,12 @@
// if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
if (ObjectUtil.isNull(orderInfo)) {
throw new FebsException("订单不存在");
+ }
+ List<MallOrderItem> items = orderInfo.getItems();
+ if(CollUtil.isNotEmpty(items)){
+ for(MallOrderItem mallOrderItem : items){
+ mallOrderItem.setItemAmount(mallOrderItemMapper.selectById(mallOrderItem.getId()).getAmount());
+ }
}
OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo);
@@ -1035,4 +1040,19 @@
return new FebsResponse().success();
}
+ @Override
+ public FebsResponse chooseCoupon(ApiChooseCouponDto chooseCouponDto) {
+ Map<Long, BigDecimal> couponAmountMap = getCouponAmountMap(chooseCouponDto.getMemberCouponId(), chooseCouponDto.getItems());
+ ArrayList<ApiCouponAmountMapVo> objects = new ArrayList<>();
+ for (Map.Entry<Long,BigDecimal> entry : couponAmountMap.entrySet()) {
+ Long keySkuId = entry.getKey();
+ BigDecimal valueSkuAmount = entry.getValue();
+ ApiCouponAmountMapVo apiCouponAmountMapVo = new ApiCouponAmountMapVo();
+ apiCouponAmountMapVo.setId(keySkuId);
+ apiCouponAmountMapVo.setAmount(valueSkuAmount);
+ objects.add(apiCouponAmountMapVo);
+ }
+ return new FebsResponse().success().data(objects);
+ }
+
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallInvoiceServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallInvoiceServiceImpl.java
index 1739659..ae2b541 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallInvoiceServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallInvoiceServiceImpl.java
@@ -157,4 +157,28 @@
}
return new FebsResponse().success();
}
+
+ @Override
+ @Transactional
+ public FebsResponse updateOrderDetail(Long id) {
+ MallInvoice mallInvoice = this.baseMapper.selectById(id);
+ String fapiaoApplyId = mallInvoice.getFapiaoApplyId();
+ MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectBypayOrderNo(fapiaoApplyId);
+ if(OrderStatusEnum.FINISH.getValue() != mallOrderInfo.getStatus()){
+ return new FebsResponse().fail().message("当前订单还未完成。");
+ }
+ /**
+ * fapiao_apply_id
+ * 发票申请单号,唯一标识一次开票行为。微信支付场景下,为微信支付订单号;非微信支付场景下,为调用【获取抬头填写链接】接口时指定的发票申请单号
+ * 对应订单信息的pay_order_no支付订单号
+ */
+ mallInvoice.setStatus(mallOrderInfo.getStatus());
+ this.baseMapper.updateById(mallInvoice);
+ /**
+ * 更新订单为已开票
+ */
+ mallOrderInfo.setIsInvoice(1);
+ mallOrderInfoMapper.updateById(mallOrderInfo);
+ return new FebsResponse().success();
+ }
}
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/ApiCouponAmountMapVo.java b/src/main/java/cc/mrbird/febs/mall/vo/ApiCouponAmountMapVo.java
new file mode 100644
index 0000000..3f36cb7
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/mall/vo/ApiCouponAmountMapVo.java
@@ -0,0 +1,16 @@
+package cc.mrbird.febs.mall.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+@ApiModel(value = "ApiCouponAmountMapVo", description = "信息返回类")
+public class ApiCouponAmountMapVo {
+ @ApiModelProperty(value = "SKUID")
+ private Long id;
+ @ApiModelProperty(value = "优惠后金额")
+ private BigDecimal amount;
+}
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/OrderItemVo.java b/src/main/java/cc/mrbird/febs/mall/vo/OrderItemVo.java
index fb4061a..d7a0c3d 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/OrderItemVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/OrderItemVo.java
@@ -53,4 +53,7 @@
@ApiModelProperty(value = "1:正常 2:退款中3:已退")
private Integer state;
+
+ @ApiModelProperty(value = "支付金额")
+ private BigDecimal itemAmount;
}
diff --git a/src/main/resources/templates/febs/views/modules/order/invoiceList.html b/src/main/resources/templates/febs/views/modules/order/invoiceList.html
index 5a19dee..595a776 100644
--- a/src/main/resources/templates/febs/views/modules/order/invoiceList.html
+++ b/src/main/resources/templates/febs/views/modules/order/invoiceList.html
@@ -127,7 +127,19 @@
updateInvoiceDetail(data.id);
});
}
+ if (layEvent === 'updateOrderDetail') {
+ febs.modal.confirm('更新', '是否更新订单状态信息?', function () {
+ updateOrderDetail(data.id);
+ });
+ }
});
+
+ function updateOrderDetail(id) {
+ febs.get(ctx + 'admin/order/updateOrderDetail/' + id, null, function () {
+ febs.alert.success('操作成功');
+ $query.click();
+ });
+ }
function updateInvoiceDetail(id) {
febs.get(ctx + 'admin/order/updateInvoiceDetail/' + id, null, function () {
@@ -212,9 +224,10 @@
templet: function (d) {
if(d.status === 4){
return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="seeInvoiceDetail" shiro:hasPermission="user:update">开票信息</button>' +
+ '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateOrderDetail" shiro:hasPermission="user:update">更新订单状态</button>'+
'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateInvoiceDetail" shiro:hasPermission="user:update">更新抬头</button>'
}else{
- return ''
+ return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateOrderDetail" shiro:hasPermission="user:update">更新订单状态</button>'
}
},minWidth: 300,align:'center', fixed:'right'}
]]
--
Gitblit v1.9.1