1.线下退单

2.销售同步保存库存记录
This commit is contained in:
2024-07-17 16:43:11 +08:00
parent 56d66097c7
commit b27b364848
9 changed files with 171 additions and 82 deletions

View File

@@ -17,11 +17,9 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.thirdpay.resp.*;
import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService;
import com.chaozhanggui.system.cashierservice.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -538,6 +536,12 @@ public class PayService {
producer.printMechine(orderId);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId);
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
return Result.success(CodeEnum.SUCCESS);
}
@@ -623,6 +627,12 @@ public class PayService {
producer.printMechine(orderId);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId);
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
return Result.success(CodeEnum.SUCCESS);
}
@@ -671,6 +681,12 @@ public class PayService {
producer.printMechine(orderId);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId);
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
return Result.success(CodeEnum.SUCCESS);
}
@@ -718,11 +734,17 @@ public class PayService {
producer.printMechine(orderId);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId);
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
return Result.success(CodeEnum.SUCCESS);
}
@Transactional(rollbackFor = Exception.class)
public Result returnOrder(List<TbOrderDetail> list, String token,String pwd) {
public Result returnOrder(List<TbOrderDetail> list, String token, String pwd, boolean isOnline) {
if (ObjectUtil.isEmpty(list) || list.size() <= 0) {
return Result.fail(CodeEnum.PARAM);
}
@@ -839,86 +861,88 @@ public class PayService {
"table", "return", merchantId, shopId,
"", (byte) 1, day, masterId, "refund", payAmount, orderInfo.getPayType(), orderInfo.getTableName());
if ("scanCode".equals(payType) || "wx_lite".equals(payType)) {
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(merchantId));
MsgException.checkNull(thirdApply, "支付参数配置错误");
// 线上退款
if (isOnline) {
if ("scanCode".equals(payType) || "wx_lite".equals(payType)) {
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(merchantId));
MsgException.checkNull(thirdApply, "支付参数配置错误");
if ("ysk".equals(thirdPayType)) {
ReturnOrderReq req = new ReturnOrderReq();
req.setAppId(thirdApply.getAppId());
req.setTimestamp(System.currentTimeMillis());
req.setOrderNumber(orderInfo.getPayOrderNo());
req.setAmount(String.format("%.2f", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
req.setMercRefundNo(orderInfo.getOrderNo());
req.setRefundReason("退货");
req.setPayPassword(thirdApply.getPayPassword());
Map<String, Object> map = BeanUtil.transBean2Map(req);
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
log.info("merchantOrderReturn req:{}", JSONUtil.toJsonStr(req));
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/returnOrder"), req, String.class);
log.info("merchantOrderReturn:{}", response.getBody());
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
JSONObject object = JSONObject.parseObject(response.getBody());
if (!object.get("code").equals("0")) {
MsgException.check(true, "退款渠道调用失败");
}
// newOrderInfo.setPayOrderNo(object.getJSONObject("data").getString("refundOrderNumber"));
}
} else {
TbOrderPayment payment= tbOrderPaymentMapper.selectByOrderId(orderId+"");
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {
if (!"SUCCESS".equals(publicResp.getObjData().getState())&&!publicResp.getObjData().getState().equals("ING")) {
if ("ysk".equals(thirdPayType)) {
ReturnOrderReq req = new ReturnOrderReq();
req.setAppId(thirdApply.getAppId());
req.setTimestamp(System.currentTimeMillis());
req.setOrderNumber(orderInfo.getPayOrderNo());
req.setAmount(String.format("%.2f", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
req.setMercRefundNo(orderInfo.getOrderNo());
req.setRefundReason("退货");
req.setPayPassword(thirdApply.getPayPassword());
Map<String, Object> map = BeanUtil.transBean2Map(req);
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
log.info("merchantOrderReturn req:{}", JSONUtil.toJsonStr(req));
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/returnOrder"), req, String.class);
log.info("merchantOrderReturn:{}", response.getBody());
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
JSONObject object = JSONObject.parseObject(response.getBody());
if (!object.get("code").equals("0")) {
MsgException.check(true, "退款渠道调用失败");
}
} else {
MsgException.check(true, "退款渠道调用失败");
// newOrderInfo.setPayOrderNo(object.getJSONObject("data").getString("refundOrderNumber"));
}
} else {
TbOrderPayment payment= tbOrderPaymentMapper.selectByOrderId(orderId+"");
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {
if (!"SUCCESS".equals(publicResp.getObjData().getState())&&!publicResp.getObjData().getState().equals("ING")) {
MsgException.check(true, "退款渠道调用失败");
}
} else {
MsgException.check(true, "退款渠道调用失败");
}
}
}
}else if("deposit".equals(payType)){
TbShopUser user= tbShopUserMapper.selectByUserIdAndShopId(orderInfo.getUserId(),orderInfo.getShopId());
if(ObjectUtil.isNull(user)||ObjectUtil.isEmpty(user)){
user=tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
}
if(ObjectUtil.isNull(user)||ObjectUtil.isEmpty(user)){
return Result.fail(ACCOUNTEIXST);
}
if(!user.getShopId().equals(orderInfo.getShopId())){
return Result.fail(ACCOUNTEIXST);
}
newOrderInfo.setMemberId(orderInfo.getMemberId());
newOrderInfo.setUserId(orderInfo.getUserId());
user.setAmount(user.getAmount().add( newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
user.setConsumeAmount(user.getConsumeAmount().subtract( newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
user.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKeySelective(user);
TbShopUserFlow flow = new TbShopUserFlow();
flow.setShopUserId(user.getId());
flow.setBizCode("accountReturnPay");
flow.setBizName("会员储值卡退款");
flow.setType("+");
flow.setAmount(newOrderInfo.getOrderAmount());
flow.setBalance(user.getAmount());
flow.setCreateTime(new Date());
tbShopUserFlowMapper.insert(flow);
}
}else if("deposit".equals(payType)){
TbShopUser user= tbShopUserMapper.selectByUserIdAndShopId(orderInfo.getUserId(),orderInfo.getShopId());
if(ObjectUtil.isNull(user)||ObjectUtil.isEmpty(user)){
user=tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
}
if(ObjectUtil.isNull(user)||ObjectUtil.isEmpty(user)){
return Result.fail(ACCOUNTEIXST);
}
if(!user.getShopId().equals(orderInfo.getShopId())){
return Result.fail(ACCOUNTEIXST);
}
newOrderInfo.setMemberId(orderInfo.getMemberId());
newOrderInfo.setUserId(orderInfo.getUserId());
user.setAmount(user.getAmount().add( newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
user.setConsumeAmount(user.getConsumeAmount().subtract( newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
user.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKeySelective(user);
TbShopUserFlow flow = new TbShopUserFlow();
flow.setShopUserId(user.getId());
flow.setBizCode("accountReturnPay");
flow.setBizName("会员储值卡退款");
flow.setType("+");
flow.setAmount(newOrderInfo.getOrderAmount());
flow.setBalance(user.getAmount());
flow.setCreateTime(new Date());
tbShopUserFlowMapper.insert(flow);
}
//判断是否修改主单状态
BigDecimal returnAmount = tbOrderDetailMapper.selectByOrderId(orderId.toString());
if (N.egt(returnAmount.add(payAmount), orderAmount)) {

View File

@@ -1,6 +1,10 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
@@ -14,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
@@ -97,9 +102,9 @@ public class ProductService {
List<TbProductWithBLOBs> tbProductWithBLOBs=null;
PageHelperUtil.startPage(page,pageSize);
if(ObjectUtil.isEmpty(categoryId)){
tbProductWithBLOBs=tbProductMapper.selectByShopId(shopId,commdityName);
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndCheckGrounding(shopId,commdityName);
}else {
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndShopType(shopId,categoryId,commdityName);
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndShopTypeCheckGrounding(shopId,categoryId,commdityName);
}
String day = DateUtils.getDay();
@@ -118,6 +123,11 @@ public class ProductService {
skuResult=new TbProductSkuResult();
}
it.setProductSkuResult(skuResult);
// 查询sku信息
List<TbProductSku> skuWithBLOBs = tbProductSkuMapper.selectByProductCheckGrounding(it.getId());
it.setSkuList(skuWithBLOBs);
});
}
PageInfo pageInfo=new PageInfo(tbProductWithBLOBs);