From 7768b2faf3092cfff6d5fcf242d8b1f33110a032 Mon Sep 17 00:00:00 2001 From: wangh <9483> Date: Tue, 16 Jan 2024 09:38:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E6=AC=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fuyou/service/impl/FyPayServiceImpl.java | 16 +- .../business/order/entity/AllOrderInfo.java | 8 + .../service/impl/AllOrderInfoServiceImpl.java | 170 ++++++++++++++++-- .../mapper/OilTankMapper.java | 2 + .../mapper/xml/OilTankMapper.xml | 12 ++ .../service/OilTankService.java | 11 ++ .../service/impl/OilTankServiceImpl.java | 16 +- .../service/impl/OilTrackingServiceImpl.java | 2 +- .../cashier/orderComponents/order_Vip.vue | 1 + 9 files changed, 213 insertions(+), 25 deletions(-) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java index 0df132d7a..9ced80dd1 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java @@ -76,7 +76,7 @@ public class FyPayServiceImpl implements FyPayService { // 请求报文 String reqBody = Message.requestMsg(map); // 响应报文 - String rspXml = Message.responseMsg(reqBody,Const.fuiou_31_url); + String rspXml = Message.responseMsg(reqBody,Const.fuiou_24_url); //响应报文验签 Map resMap = Utils.xmlStr2Map(rspXml); @@ -513,11 +513,12 @@ public class FyPayServiceImpl implements FyPayService { String orderNo = map1.get("orderNo"); String refundOrderNo = map1.get("refundOrderNo"); String payType = map1.get("payType"); - String allAmount = map1.get("allAmount"); + String totalAmt = map1.get("totalAmt"); + String refundAmt = map1.get("refundAmt"); String insCd = map1.get("insCd"); String mchntCd = map1.get("mchntCd"); Map map = Builder.buildFuiou24(); - map.put("version", "1.0"); + map.put("version", "1"); map.put("ins_cd", insCd); map.put("mchnt_cd", mchntCd); map.put("term_id", "88888888"); @@ -525,10 +526,13 @@ public class FyPayServiceImpl implements FyPayService { map.put("random_str", "orderNo"); map.put("order_type",payType); map.put("refund_order_no", refundOrderNo); - map.put("refund_amt", allAmount); - map.put("total_amt", allAmount); - + map.put("refund_amt", refundAmt); + map.put("total_amt", totalAmt); + String publicKey = map1.get("publicKey"); + String privateKey = map1.get("privateKey"); + Const.INS_PUBLIC_KEY = publicKey; + Const.INS_PRIVATE_KEY = privateKey; // 请求报文 String reqBody = Message.requestMsg(map); diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/AllOrderInfo.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/AllOrderInfo.java index f58f18604..bfc520593 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/AllOrderInfo.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/AllOrderInfo.java @@ -74,6 +74,14 @@ public class AllOrderInfo extends BaseEntity implements Serializable { * 订单描述 */ private String content; + /** + * 退款原因 + */ + private String reasonRefund; + /** + * 退款订单 + */ + private String refOrderNo; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/AllOrderInfoServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/AllOrderInfoServiceImpl.java index 80c46f7a4..4cb1657bf 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/AllOrderInfoServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/AllOrderInfoServiceImpl.java @@ -1,7 +1,9 @@ package com.fuint.business.order.service.impl; import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -9,16 +11,30 @@ import com.fuint.api.fuyou.entity.Const; import com.fuint.api.fuyou.entity.MerchantConfig; import com.fuint.api.fuyou.service.FyPayService; import com.fuint.api.fuyou.service.MerchantConfigService; +import com.fuint.business.convenienceSore.dto.LJGoodsDto; +import com.fuint.business.convenienceSore.entity.StockStatistic; +import com.fuint.business.convenienceSore.entity.StockTrack; +import com.fuint.business.convenienceSore.service.LJGoodsService; +import com.fuint.business.convenienceSore.service.StockTrackService; import com.fuint.business.order.entity.AllOrderInfo; +import com.fuint.business.order.entity.CashierOrder; +import com.fuint.business.order.entity.LJOrder; +import com.fuint.business.order.entity.OilOrder; import com.fuint.business.order.mapper.AllOrderInfoMapper; -import com.fuint.business.order.service.AllOrderInfoService; -import com.fuint.business.order.service.OilOrderService; +import com.fuint.business.order.service.*; import com.fuint.business.order.vo.AllOrderInfoVo; +import com.fuint.business.order.vo.OrderGoodsVo; +import com.fuint.business.petrolStationManagement.entity.OilTracking; +import com.fuint.business.petrolStationManagement.service.OilTankService; +import com.fuint.business.petrolStationManagement.service.OilTrackingService; +import com.fuint.repository.mapper.MtOpenGiftMapper; +import com.fuint.repository.model.MtOrderGoods; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -99,37 +115,157 @@ public class AllOrderInfoServiceImpl extends ServiceImpl map) { Map refund = null; try { - - // 根据订单号查询订单 AllOrderInfo allOrderInfo = selectAllOrderInfoByOrderNo(map.get("orderNo")); - map.put("orderNo",allOrderInfo.getOrderNo()); - map.put("payType",allOrderInfo.getPayType()); - map.put("allAmount",allOrderInfo.getPayMoney().toString()); + if (ObjectUtil.isEmpty(map.get("type"))) { + throw new RuntimeException("该订单不支持退款,无退款类别!"); + }else if ("oilOrder".equals(map.get("type")) || "goodsOrder".equals(map.get("type"))) { + // 根据订单号查询订单 + if ("APPLET_CODE".equals(allOrderInfo.getPayType())) { // 储值卡不支持退款 + throw new RuntimeException("该订单不支持退款!"); + } + // 判断是否有退款金额 + if (ObjectUtil.isNotEmpty(allOrderInfo.getPayMoney()) && ObjectUtil.isNotEmpty(map.get("refundAmt"))) { + // 总金额(金钱的传值需要×100) + BigDecimal payMoneyBig = new BigDecimal(allOrderInfo.getPayMoney().toString()); + BigDecimal payMoneyBefBig = payMoneyBig.multiply(new BigDecimal("100")); + // 退款金额(暂不支持部分退款) + // BigDecimal refundAmtBig = new BigDecimal(map.get("refundAmt")); + // BigDecimal refundAmtBefBig = refundAmtBig.multiply(new BigDecimal("100")); + map.put("totalAmt",payMoneyBefBig.toString()); + map.put("refundAmt",payMoneyBefBig.toString()); - MerchantConfig merchantConfig = merchantConfigService.selectMeChByIdIsUse(allOrderInfo.getStoreId()); - // 机构号 - map.put("insCd", merchantConfig.getInsCd()); - // 商户号 - map.put("mchntCd", merchantConfig.getMchntCd()); - // 生成退款id -// map.put("refundOrderNo", "ref_" + allOrderInfo.getOrderNo()); - map.put("refundOrderNo", allOrderInfo.getOrderNo()); - + map.put("orderNo",allOrderInfo.getOrderNo()); + map.put("payType",allOrderInfo.getPayType()); + // 获取机构信息 + map.putAll(getMerchantConfig(allOrderInfo)); + }else { + throw new Exception("退款失败,无退款金额"); + } + } else { + throw new RuntimeException("该订单类型不支持退款!"); + } refund = fyPayService.refund(map); + + // 处理退款结果 + if (ObjectUtil.isNotEmpty(refund.get("result_msg"))) { + if ("SUCCESS".equals(refund.get("result_msg"))) { + // 修改该总订单的数据 + allOrderInfo.setPayType("refund"); +// allOrderInfo.setReasonRefund("refund"); +// allOrderInfo.setRefOrderNo("refund"); + baseMapper.updateById(allOrderInfo); + // 处理油品订单 + OilOrder oilOrder = oilOrderService.selectOilOrderByOrderNo(map.get("orderNo")); + // 处理商品订单 + LJOrder ljOrder = ljOrderService.selectGoodsOrder(map.get("orderNo")); + // 处理收银台订单 + CashierOrder orderNo = cashierOrderService.selectCashierOrder(map.get("orderNo")); + if (ObjectUtil.isNotEmpty(orderNo)) { + orderNo.setStatus("refund"); + cashierOrderService.updateById(orderNo); + } + if (ObjectUtil.isNotEmpty(oilOrder)) { + disposeOil(oilOrder); + } + if (ObjectUtil.isNotEmpty(ljOrder)) { + disposeGoods(ljOrder); + } + + + + }else { + throw new RuntimeException("退款失败"); + } + } } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException("退款失败"); } log.info("refund{}",refund); return 0; } + // 处理商户号 + private Map getMerchantConfig(AllOrderInfo allOrderInfo){ + Map map = new HashMap<>(); + // 商户机构查询 + MerchantConfig merchantConfig = merchantConfigService.selectMeChByIdIsUse(allOrderInfo.getStoreId()); + // 机构号 + map.put("insCd", merchantConfig.getInsCd()); + // 商户号 + map.put("mchntCd", merchantConfig.getMchntCd()); + // 生成退款id + map.put("refundOrderNo",allOrderInfo.getOrderNo() + "_ref"); + map.put("publicKey",merchantConfig.getPublicKey()); + map.put("privateKey",merchantConfig.getPrivateKey()); + return map; + } + + // 处理油品 + private void disposeOil(OilOrder oilOrder) { + // 处理订单状态 + oilOrder.setOrderStatus("refund"); + oilOrderService.updateById(oilOrder); + + // 获取所有当前订单的数据 + List oilOrders = oilOrderService.selectOilOrder(oilOrder.getOrderNo()); + // 获取油罐数据 + for (OilOrder order : oilOrders) { + // 处理库存 + oilTankService.addStoredQuantity(order.getTankId(),order.getOilNum()); + // 处理库存跟踪 + OilTracking oilTracking = new OilTracking(); + oilTracking.setDocument("油品退款"); + oilTracking.setQuantityChange(-order.getOilNum()); + oilTracking.setStoreId(order.getStoreId()); + oilTracking.setTankId(order.getTankId()); + OilTracking insert = oilTrackingService.insert(oilTracking); + } +/** + * todo + * 油品总价计算 + */ + } + // 处理商品 + private void disposeGoods(LJOrder ljOrder) { + // 处理订单状态 + ljOrder.setStatus("refund"); + ljOrderService.updateById(ljOrder); + // 获取订单的商品数据 + List orderGoodsVos = orderGoodsService.selectOrderGoods(ljOrder.getId()); + // 处理库存 + for (OrderGoodsVo orderGoodsVo : orderGoodsVos) { + LJGoodsDto goods = new LJGoodsDto(); + goods.setId(orderGoodsVo.getOrderId()); + goods.setNumberOfChanges(ljOrder.getGoodsNum()); + ljGoodsService.editGoodsInventory(goods); + } + + } + + + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/OilTankMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/OilTankMapper.java index 84b58edc3..7ac7364df 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/OilTankMapper.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/OilTankMapper.java @@ -90,6 +90,8 @@ public interface OilTankMapper { int subtractStoredQuantityByLock(@Param("tankId") Integer tankId,@Param("changeNum") Double changeNum); +// int addStoredQuantity(@Param("tankId") Integer tankId,@Param("changeNum") Double changeNum); + /** * 通过主键删除数据 * diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/xml/OilTankMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/xml/OilTankMapper.xml index 2ca7b7825..7ae8c2cec 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/xml/OilTankMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/mapper/xml/OilTankMapper.xml @@ -390,6 +390,17 @@ update oil_tank set stored_quantity = 0.00 ,total_price = 0.00, discounted_price = 0.00 where id = #{id} + + + + update oil_tank set + stored_quantity = stored_quantity + #{storedQuantity} , + total_price = total_price + #{totalPrice}, + update_time = NOW(), + discounted_price = #{discountedPrice} + where id = #{id} + + update oil_tank set stored_quantity = stored_quantity + #{storedQuantity} , @@ -432,5 +443,6 @@ + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/OilTankService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/OilTankService.java index 1800d59a8..1f9fd13d4 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/OilTankService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/OilTankService.java @@ -79,6 +79,15 @@ public interface OilTankService { public void export(HttpServletResponse response); + /** + * 增加数量 + * @param tankId + * @param changeNum + * @return + */ + boolean addStoredQuantity(Integer tankId, Double changeNum); + + /** * * @param tankId @@ -87,6 +96,8 @@ public interface OilTankService { * @return */ OilTank addStoredQuantityByLock(Integer tankId, Double changeNum, Double totalAmount); + +// OilTank addStoredQuantityByLock(Integer tankId, Double changeNum, Double totalAmount); OilTank subtractStoredQuantityByLock(Integer tankId, Double changeNum); } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTankServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTankServiceImpl.java index be27d60aa..4e421f948 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTankServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTankServiceImpl.java @@ -132,7 +132,6 @@ public class OilTankServiceImpl implements OilTankService { String lockKey = "oilTank-"+tankId; Boolean isLock = redisLock.tryLock(lockKey,500,5000, TimeUnit.MILLISECONDS); if (isLock) { - // 判断存油数量是否足够 OilTank oilTank = oilTankDao.queryById(tankId); // 计算总升数 BigDecimal changeNumBigDecimal = new BigDecimal(changeNum.toString()); @@ -151,6 +150,11 @@ public class OilTankServiceImpl implements OilTankService { // 计算单价 BigDecimal discountedPriceBigDecimal = totalPriceBigDecimal.divide(storedQuantityBigDecimal,2); discountedPrice = Double.valueOf(discountedPriceBigDecimal.toString()); + } else { + // 根据单价处理总价 + BigDecimal disPrice = new BigDecimal(oilTank.getDiscountedPrice().toString()); + BigDecimal multiply = disPrice.multiply(new BigDecimal(changeNum)); + discountedPrice = multiply.doubleValue(); } this.oilTankDao.addStoredQuantityByLock(tankId, changeNum, totalAmount, discountedPrice); @@ -185,6 +189,16 @@ public class OilTankServiceImpl implements OilTankService { return this.queryById(tankId); } + @Override + public boolean addStoredQuantity(Integer tankId, Double changeNum) { + // 计算总计 + OilTank oilTank = oilTankDao.queryById(tankId); + // 单价*油量 + BigDecimal disPrice = new BigDecimal(oilTank.getDiscountedPrice().toString()); + BigDecimal multiply = disPrice.multiply(new BigDecimal(changeNum)); + return this.oilTankDao.addStoredQuantityByLock(tankId, changeNum, multiply.doubleValue(),null) >0 ; + } + /** * 通过主键删除数据 * diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTrackingServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTrackingServiceImpl.java index fcbe0e3f9..4afdb12bf 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTrackingServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/petrolStationManagement/service/impl/OilTrackingServiceImpl.java @@ -58,7 +58,7 @@ public class OilTrackingServiceImpl implements OilTrackingService { * @return 实例对象 */ @Override - public OilTracking insert(OilTracking oilTracking) { + public OilTracking insert(OilTracking oilTracking) { this.oilTrackingDao.insert(oilTracking); return oilTracking; } diff --git a/fuintCashierWeb/src/views/cashier/orderComponents/order_Vip.vue b/fuintCashierWeb/src/views/cashier/orderComponents/order_Vip.vue index cf2d77bdd..ea0acbdc1 100644 --- a/fuintCashierWeb/src/views/cashier/orderComponents/order_Vip.vue +++ b/fuintCashierWeb/src/views/cashier/orderComponents/order_Vip.vue @@ -305,6 +305,7 @@ export default { console.log("oilOrder",this.oilOrder) let map={ orderNo: this.oilOrder.paymentNo, + // refundAmt: this.oilOrder.paymentNo, storeId: this.oilOrder.storeId, type: "oilOrder" }