退款接口
This commit is contained in:
parent
a3c31a8d59
commit
7768b2faf3
@ -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<String, String> 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<String, String> 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);
|
||||
|
@ -74,6 +74,14 @@ public class AllOrderInfo extends BaseEntity implements Serializable {
|
||||
* 订单描述
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 退款原因
|
||||
*/
|
||||
private String reasonRefund;
|
||||
/**
|
||||
* 退款订单
|
||||
*/
|
||||
private String refOrderNo;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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<AllOrderInfoMapper,AllO
|
||||
|
||||
@Resource
|
||||
private FyPayService fyPayService;
|
||||
@Resource
|
||||
CashierOrderService cashierOrderService;
|
||||
@Resource
|
||||
|
||||
LJGoodsService ljGoodsService;
|
||||
@Resource
|
||||
LJOrderService ljOrderService;
|
||||
@Resource
|
||||
StockTrackService service;
|
||||
|
||||
OrderGoodsService orderGoodsService;
|
||||
@Resource
|
||||
OilTankService oilTankService;
|
||||
@Resource
|
||||
OilOrderService oilOrderService;
|
||||
@Resource
|
||||
OilTrackingService oilTrackingService;
|
||||
@Override
|
||||
public int refund(Map<String, String> map) {
|
||||
Map<String, String> 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<String, String> getMerchantConfig(AllOrderInfo allOrderInfo){
|
||||
Map<String, String> 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<OilOrder> 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<OrderGoodsVo> orderGoodsVos = orderGoodsService.selectOrderGoods(ljOrder.getId());
|
||||
// 处理库存
|
||||
for (OrderGoodsVo orderGoodsVo : orderGoodsVos) {
|
||||
LJGoodsDto goods = new LJGoodsDto();
|
||||
goods.setId(orderGoodsVo.getOrderId());
|
||||
goods.setNumberOfChanges(ljOrder.getGoodsNum());
|
||||
ljGoodsService.editGoodsInventory(goods);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
|
@ -390,6 +390,17 @@
|
||||
<update id="cleanData">
|
||||
update oil_tank set stored_quantity = 0.00 ,total_price = 0.00, discounted_price = 0.00 where id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="accumulate">
|
||||
update oil_tank set
|
||||
stored_quantity = stored_quantity + #{storedQuantity} ,
|
||||
total_price = total_price + #{totalPrice},
|
||||
update_time = NOW(),
|
||||
discounted_price = #{discountedPrice}
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="accumulate">
|
||||
update oil_tank set
|
||||
stored_quantity = stored_quantity + #{storedQuantity} ,
|
||||
@ -432,5 +443,6 @@
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user