1.线下退单

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

View File

@ -215,11 +215,13 @@ public class PayController {
public Result returnOrder(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType,
@RequestBody List<TbOrderDetail> list
@RequestBody List<TbOrderDetail> list,
@RequestParam("pwd") String pwd,
@RequestParam(defaultValue = "true") boolean isOnline
){
return payService.returnOrder(list,token,null);
return payService.returnOrder(list,token,null, isOnline);
}

View File

@ -29,10 +29,12 @@ public interface TbProductMapper {
List<TbProductWithBLOBs> selectByShopId(@Param("shopId") String shopId,@Param("commdityName") String commdityName);
List<TbProductWithBLOBs> selectByShopIdAndCheckGrounding(@Param("shopId") String shopId,@Param("commdityName") String commdityName);
List<TbProductWithBLOBs> selectByShopIdAndShopType(@Param("shopId") String shopId, @Param("categoryId") String categoryId,@Param("commdityName") String commdityName);
List<TbProductWithBLOBs> selectByShopIdAndShopTypeCheckGrounding(@Param("shopId") String shopId, @Param("categoryId") String categoryId,@Param("commdityName") String commdityName);

View File

@ -5,6 +5,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbProductSkuWithBLOBs;
import com.chaozhanggui.system.cashierservice.entity.po.ProductSkuPo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
@ -49,4 +50,7 @@ public interface TbProductSkuMapper {
@Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id} ")
int decrStockUnCheck(String id, int num);
@Select("select * from tb_product_sku where is_grounding=1 and product_id=#{id}")
List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id);
}

View File

@ -1,6 +1,7 @@
package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.List;
public class TbProductWithBLOBs extends TbProduct implements Serializable {
private String images;
@ -15,8 +16,18 @@ public class TbProductWithBLOBs extends TbProduct implements Serializable {
private String selectSpec;
private List<?> skuList;
private static final long serialVersionUID = 1L;
public List<?> getSkuList() {
return skuList;
}
public void setSkuList(List<?> skuList) {
this.skuList = skuList;
}
public String getImages() {
return images;
}
@ -64,4 +75,4 @@ public class TbProductWithBLOBs extends TbProduct implements Serializable {
public void setSelectSpec(String selectSpec) {
this.selectSpec = selectSpec == null ? null : selectSpec.trim();
}
}
}

View File

@ -45,4 +45,6 @@ public interface RabbitConstants {
public static final String CONS_MSG_COLLECT_ROUTINGKEY_PUT = "cons_msg_collect_routingkey_put";
String EXCHANGE_STOCK_RECORD = "exchange.stock.record";
String ROUTING_STOCK_RECORD_SALE = "routing.stock.record.sale";
}

View File

@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
@ -12,7 +13,7 @@ import java.util.UUID;
@Component
public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private RabbitTemplate rabbitTemplate;
@ -22,7 +23,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
this.rabbitTemplate = rabbitTemplate;
rabbitTemplate.setConfirmCallback(this); //rabbitTemplate如果为单例的话那回调就是最后设置的内容
}
public void putOrderCollect(String content) {
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, content, correlationId);
@ -61,4 +62,13 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
}
}
}
private <T> void sendMsg(String exchange, String routingKey, T data, String note) {
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
logger.info("开始发送{}mq消息, msgId: {}, exchange: {}, routingKey: {}, data: {}", correlationId.getId(), note, exchange, routingKey, data);
rabbitTemplate.convertAndSend(exchange, routingKey, JSONObject.toJSONString(data), correlationId);
}
public <T> void sendStockSaleMsg(T data) {
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, data, "商品售出增加库存记录");
}
}

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);

View File

@ -902,6 +902,17 @@
</if>
order by `sort` asc
</select>
<select id="selectByShopIdAndCheckGrounding" resultMap="ResultMapWithBLOBs">
select a.* from tb_product as a
left join tb_product_sku as b on a.id = b.product_id
where a.shop_id=#{shopId} and a.status=1 and a.is_show_cash = 1 and a.type_enum in ('normal','sku','currentPrice','weight')
<if test="commdityName != null and commdityName!='' ">
and a.name like CONCAT('%',#{commdityName},'%')
</if>
and b.is_grounding=1 GROUP BY a.id ORDER BY a.`sort`
</select>
<select id="selectByShopIdAndShopType" resultMap="ResultMapWithBLOBs">
@ -916,6 +927,19 @@
</select>
<select id="selectByShopIdAndShopTypeCheckGrounding" resultMap="ResultMapWithBLOBs">
select a.* from tb_product as a
left join tb_product_sku as b on a.id = b.product_id
where a.shop_id=#{shopId} and a.status=1 and a.category_id=#{categoryId} and a.is_show_cash = 1 and a.type_enum in ('normal','sku','currentPrice','weight')
<if test="commdityName != null and commdityName!='' ">
and a.name like CONCAT('%',#{commdityName},'%')
</if>
and b.is_grounding=1 GROUP BY a.id ORDER BY a.`sort`
</select>
<select id="countOrderByshopIdAndProductId" resultType="INTEGER">
SELECT
IFNULL(sum( number ) ,0)