parent
ffe39b3113
commit
2186cd5a04
|
|
@ -72,8 +72,8 @@ public class TbPlaceController {
|
|||
|
||||
@PutMapping("/returnCart")
|
||||
@ApiOperation("代客下单 清空购物车 /shop/table")
|
||||
public ResponseEntity<Object> returnOrder(@Validated @RequestBody ReturnOrderDTO removeCartDTO) {
|
||||
tbShopTableService.returnCart(removeCartDTO);
|
||||
public ResponseEntity<Object> returnOrder(@Validated @RequestBody ReturnCartDTO ReturnCartDTO) {
|
||||
tbShopTableService.returnCart(ReturnCartDTO);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +148,11 @@ public class TbPlaceController {
|
|||
return ResponseEntity.ok(tbShopTableService.pay(payDTO));
|
||||
}
|
||||
|
||||
@PostMapping("/returnOrder")
|
||||
public ResponseEntity<?> returnOrder(ReturnOrderDTO returnOrderDTO) {
|
||||
return ResponseEntity.ok(tbShopTableService.returnOrder(returnOrderDTO));
|
||||
}
|
||||
|
||||
@PutMapping("/choseTable")
|
||||
@ApiOperation("代客下单 选择台桌")
|
||||
public ResponseEntity<Object> choseTable(
|
||||
|
|
|
|||
|
|
@ -2,14 +2,31 @@ package cn.ysk.cashier.dto.shoptable;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ReturnOrderDTO {
|
||||
|
||||
@Data
|
||||
public static class OrderDetail{
|
||||
@NotNull
|
||||
private Integer id;
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer num;
|
||||
}
|
||||
@NotNull
|
||||
private Integer cartId;
|
||||
private Integer orderId;
|
||||
@NotNull
|
||||
private Integer shopId;
|
||||
@NotNull
|
||||
private Long tableId;
|
||||
private String shopId;
|
||||
@NotEmpty
|
||||
private String note;
|
||||
@NotEmpty
|
||||
private String pwd;
|
||||
@Valid
|
||||
private List<OrderDetail> orderDetails;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopArea;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface MpMerchantThirdApplyMapper extends BaseMapper<TbMerchantThirdApply> {
|
||||
}
|
||||
|
|
@ -39,6 +39,9 @@ public interface TbMShopUserMapper extends BaseMapper<TbShopUser> {
|
|||
|
||||
@Update("update tb_shop_user set amount=amount-#{orderAmount}, consume_amount=consume_amount+#{orderAmount} where id=#{vipUserId} and amount-#{orderAmount} >= 0")
|
||||
long decrBalance(@Param("vipUserId") Integer vipUserId, @Param("orderAmount") BigDecimal orderAmount);
|
||||
|
||||
@Update("update tb_shop_user set amount=amount+#{returnAmount}, consume_amount=consume_amount-#{returnAmount}, updated_at=#{current} where id=#{userId}")
|
||||
void incrBalance(@Param("userId") Integer userId, @Param("shopId") Integer shopId, @Param("returnAmount") BigDecimal returnAmount, @Param("current") long current);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface PayService {
|
||||
void returnOrder(Integer shopId, TbOrderInfo orderInfo, TbOrderInfo returnOrderInfo);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.model.ReturnOrderReq;
|
||||
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
||||
import cn.ysk.cashier.mybatis.mapper.MpMerchantThirdApplyMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.MpOrderPaymentMapper;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
||||
import cn.ysk.cashier.service.PayService;
|
||||
import cn.ysk.cashier.thirdpay.constants.SignTypeEnum;
|
||||
import cn.ysk.cashier.thirdpay.req.OrderRefundReq;
|
||||
import cn.ysk.cashier.thirdpay.req.PublicParam;
|
||||
import cn.ysk.cashier.thirdpay.resp.OrderReturnResp;
|
||||
import cn.ysk.cashier.thirdpay.resp.PublicResp;
|
||||
import cn.ysk.cashier.thirdpay.service.ThirdPayService;
|
||||
import cn.ysk.cashier.utils.DateUtils;
|
||||
import cn.ysk.cashier.utils.MD5Util;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PayServiceImpl implements PayService {
|
||||
|
||||
private final MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper;
|
||||
private final MpOrderPaymentMapper mpOrderPaymentMapper;
|
||||
private final ThirdPayService thirdPayService;
|
||||
@Value("${thirdPay.payType}")
|
||||
private String thirdPayType;
|
||||
@Value("${gateway.url}")
|
||||
private String gateWayUrl;
|
||||
@Value("${thirdPay.url}")
|
||||
private String url;
|
||||
@Value("${thirdPay.callBack}")
|
||||
private String callBack;
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public PayServiceImpl(MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper, RestTemplate restTemplate, MpOrderPaymentMapper mpOrderPaymentMapper, ThirdPayService thirdPayService) {
|
||||
this.mpMerchantThirdApplyMapper = mpMerchantThirdApplyMapper;
|
||||
this.restTemplate = restTemplate;
|
||||
this.mpOrderPaymentMapper = mpOrderPaymentMapper;
|
||||
this.thirdPayService = thirdPayService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款
|
||||
* @param shopId 店铺id
|
||||
*/
|
||||
@Override
|
||||
public void returnOrder(Integer shopId, TbOrderInfo orderInfo, TbOrderInfo returnOrderInfo) {
|
||||
TbMerchantThirdApply thirdApply = mpMerchantThirdApplyMapper.selectOne(new LambdaQueryWrapper<TbMerchantThirdApply>()
|
||||
.eq(TbMerchantThirdApply::getShopId, shopId));
|
||||
if (thirdApply == null) {
|
||||
throw new BadRequestException("支付参数未配置");
|
||||
}
|
||||
|
||||
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", returnOrderInfo.getRefundAmount().setScale(2, RoundingMode.DOWN)));
|
||||
req.setMercRefundNo(orderInfo.getOrderNo());
|
||||
req.setRefundReason(StrUtil.isBlank(returnOrderInfo.getPayRemark()) ? "退货" : returnOrderInfo.getPayRemark());
|
||||
req.setPayPassword(thirdApply.getPayPassword());
|
||||
Map<String, Object> map = BeanUtil.beanToMap(req);
|
||||
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||
log.info("银收客退款请求报文: {}", JSONUtil.toJsonStr(req));
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/returnOrder"), req, String.class);
|
||||
log.info("银收客退款响应报文:{}", response.getBody());
|
||||
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||
if (!"0".equals(object.getString("code"))) {
|
||||
throw new BadRequestException("退款渠道调用失败");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TbOrderPayment payment = mpOrderPaymentMapper.selectOne(new LambdaQueryWrapper<TbOrderPayment>()
|
||||
.eq(TbOrderPayment::getShopId, shopId)
|
||||
.eq(TbOrderPayment::getOrderId, orderInfo.getId()));
|
||||
log.info("福商通退款请求报文: {} {} {}", shopId, orderInfo, returnOrderInfo);
|
||||
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(),
|
||||
returnOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款",
|
||||
returnOrderInfo.getRefundAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
|
||||
log.info("福商通退款响应报文: {}", publicResp);
|
||||
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||
if ("000000".equals(publicResp.getCode())) {
|
||||
if (!"SUCCESS".equals(publicResp.getObjData().getState()) && !publicResp.getObjData().getState().equals("ING")) {
|
||||
throw new BadRequestException("退款渠道调用失败");
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException("退款渠道调用失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -10,10 +10,9 @@ import cn.ysk.cashier.exception.BadRequestException;
|
|||
import cn.ysk.cashier.mapper.order.TbOrderInfoMapper;
|
||||
import cn.ysk.cashier.mapper.product.TbProductMapper;
|
||||
import cn.ysk.cashier.mapper.product.TbProductSkuMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateProduct;
|
||||
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
||||
import cn.ysk.cashier.mybatis.entity.*;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbMShopUserMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateInRecordService;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateOutRecordService;
|
||||
import cn.ysk.cashier.mybatis.service.TbOrderPaymentService;
|
||||
|
|
@ -23,6 +22,7 @@ import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
|||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import cn.ysk.cashier.repository.TbShopPayTypeRepository;
|
||||
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
||||
|
|
@ -38,6 +38,7 @@ import cn.ysk.cashier.utils.*;
|
|||
import cn.ysk.cashier.vo.TbOrderInfoVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.conditions.update.UpdateWrapper;
|
||||
|
|
@ -58,6 +59,7 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -90,6 +92,9 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
private final TbActivateInRecordService inRecordService;
|
||||
private final TbActivateOutRecordService outRecordService;
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final TbMShopUserMapper tbMShopUserMapper;
|
||||
private final TbShopUserFlowMapper tbShopUserFlowMapper;
|
||||
private final RabbitMsgUtils rabbitMsgUtils;
|
||||
|
||||
@Value("${thirdPay.url}")
|
||||
private String url;
|
||||
|
|
@ -536,4 +541,36 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depositReturn(Integer userId, Integer shopId, BigDecimal returnAmount) {
|
||||
TbShopUser user = tbMShopUserMapper.selectOne(new LambdaQueryWrapper<TbShopUser>()
|
||||
.eq(TbShopUser::getShopId, shopId)
|
||||
.eq(TbShopUser::getId, userId));
|
||||
if (user == null) {
|
||||
throw new BadRequestException("用户信息不存在");
|
||||
}
|
||||
tbMShopUserMapper.incrBalance(userId, shopId, returnAmount, cn.hutool.core.date.DateUtil.current());
|
||||
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(user.getId());
|
||||
flow.setBizCode("accountReturnPay");
|
||||
flow.setBizName("会员储值卡退款");
|
||||
flow.setType("+");
|
||||
flow.setAmount(returnAmount);
|
||||
flow.setBalance(user.getAmount());
|
||||
flow.setCreateTime(cn.hutool.core.date.DateUtil.date().toTimestamp());
|
||||
flow.setIsReturn("0");
|
||||
tbShopUserFlowMapper.insert(flow);
|
||||
|
||||
JSONObject baObj = new JSONObject();
|
||||
baObj.put("userId", user.getUserId());
|
||||
baObj.put("shopId", user.getShopId());
|
||||
baObj.put("amount", returnAmount);
|
||||
baObj.put("balance", user.getAmount());
|
||||
baObj.put("type", "退款");
|
||||
baObj.put("time", flow.getCreateTime());
|
||||
// rabbitMsgUtils.
|
||||
// producer.balance(baObj.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
|||
import cn.ysk.cashier.dto.shoptable.*;
|
||||
import cn.ysk.cashier.enums.*;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
|
||||
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
|
||||
|
|
@ -23,15 +23,14 @@ import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
|||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
import cn.ysk.cashier.pojo.product.TbProductSku;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopArea;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||
import cn.ysk.cashier.pojo.shop.*;
|
||||
import cn.ysk.cashier.repository.TbShopPayTypeRepository;
|
||||
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||
import cn.ysk.cashier.service.PayService;
|
||||
import cn.ysk.cashier.service.impl.TbPayServiceImpl;
|
||||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.PendingCountVO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
|
@ -48,6 +47,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -95,6 +95,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
private final MpShopTableMapper mpShopTableMapper;
|
||||
private final TbShopPayTypeMapper tbShopPayTypeMapper;
|
||||
private final MpShopTableService mpShopTableService;
|
||||
@Value("${thirdPay.payType}")
|
||||
private String thirdPayType;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -110,6 +112,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
private final MpShopInfoMapper mpShopInfoMapper;
|
||||
private final MpOrderDetailService mpOrderDetailService;
|
||||
private final MpCashierCartService mpCashierCartService;
|
||||
private final MpMerchantThirdApplyMapper mpMerchantThirdApplyMapper;
|
||||
private final PayService payService;
|
||||
private final TbOrderInfoService orderInfoService;
|
||||
|
||||
private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO) {
|
||||
// 获取当前台桌最新订单,先付款模式不获取
|
||||
|
|
@ -220,8 +225,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
itemMap.put("tableId", date.getQrcode());
|
||||
}
|
||||
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(criteria.getShopId(), date.getQrcode());
|
||||
TbOrderInfo orderInfo = getCurrentOrder(shopEatTypeInfoDTO);
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (StrUtil.isNotBlank(date.getQrcode())) {
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(criteria.getShopId(), date.getQrcode());
|
||||
orderInfo = getCurrentOrder(shopEatTypeInfoDTO);
|
||||
}
|
||||
|
||||
itemMap.put("orderId", orderInfo == null ? null : orderInfo.getId());
|
||||
itemMap.put("useType", orderInfo == null ? null : orderInfo.getUseType());
|
||||
infoList.add(itemMap);
|
||||
|
|
@ -587,7 +596,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void returnCart(ReturnOrderDTO removeCartDTO) {
|
||||
public void returnCart(ReturnCartDTO removeCartDTO) {
|
||||
// 会员点单
|
||||
TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, removeCartDTO.getShopId())
|
||||
|
|
@ -934,11 +943,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
}
|
||||
|
||||
public String generateOrderNumber() {
|
||||
public String generateOrderNumber(String prefix) {
|
||||
String date = DateUtils.getSdfTimes();
|
||||
Random random = new Random();
|
||||
int randomNum = random.nextInt(900) + 100;
|
||||
return "DDPL" + date + randomNum;
|
||||
return StrUtil.isBlank(prefix) ? "DDPL" : prefix + date + randomNum;
|
||||
}
|
||||
|
||||
public synchronized void addGlobalCode(String day, String clientType, String shopId) {
|
||||
|
|
@ -1183,7 +1192,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderInfoMapper.updateById(orderInfo);
|
||||
} else {
|
||||
isFirst = true;
|
||||
String orderNo = generateOrderNumber();
|
||||
String orderNo = generateOrderNumber(null);
|
||||
orderInfo = new TbOrderInfo();
|
||||
orderInfo.setOrderNo(orderNo);
|
||||
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
||||
|
|
@ -1838,7 +1847,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
if (cashierCarts.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (OrderUseTypeEnum.TAKEOUT.getValue().equals(choseModelDTO.getUseType()) ) {
|
||||
if (OrderUseTypeEnum.TAKEOUT.getValue().equals(choseModelDTO.getUseType())) {
|
||||
ArrayList<Integer> productIds = new ArrayList<>();
|
||||
cashierCarts.forEach(item -> {
|
||||
productIds.add(Integer.valueOf(item.getProductId()));
|
||||
|
|
@ -1872,7 +1881,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
|
||||
return mpCashierCartService.updateBatchById(cashierCarts);
|
||||
}else {
|
||||
} else {
|
||||
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.in(TbCashierCart::getId, choseModelDTO.getCartIds())
|
||||
.eq(TbCashierCart::getShopId, choseModelDTO.getShopId())
|
||||
|
|
@ -1886,6 +1895,193 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.set(TbOrderDetail::getPackAmount, BigDecimal.ZERO));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TbOrderInfo updateReturnOrderInfo(ReturnOrderDTO returnOrderDTO, TbOrderInfo oldOrderInfo, boolean isOnline) {
|
||||
ArrayList<Integer> detailIds = new ArrayList<>();
|
||||
HashMap<String, Integer> returnNumMap = new HashMap<>();
|
||||
returnOrderDTO.getOrderDetails().forEach(item -> {
|
||||
detailIds.add(item.getId());
|
||||
returnNumMap.put(item.getId().toString(), item.getNum());
|
||||
});
|
||||
List<TbOrderDetail> detailList = orderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getShopId, returnOrderDTO.getShopId())
|
||||
.eq(TbOrderDetail::getStatus, "closed")
|
||||
.eq(TbOrderDetail::getOrderId, returnOrderDTO.getOrderId())
|
||||
.in(TbOrderDetail::getId, detailIds));
|
||||
if (detailIds.size() != returnOrderDTO.getOrderDetails().size()) {
|
||||
throw new BadRequestException("订单明细数量不一致");
|
||||
}
|
||||
|
||||
BigDecimal returnAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||
|
||||
List<TbOrderDetail> returnDetail = new ArrayList<>();
|
||||
|
||||
for (TbOrderDetail orderDetail : detailList) {
|
||||
Integer returnNum = returnNumMap.get(orderDetail.getId().toString());
|
||||
returnAmount = returnAmount.add(orderDetail.getPriceAmount()
|
||||
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
|
||||
.multiply(BigDecimal.valueOf(returnNum)));
|
||||
saleAmount = saleAmount.add(orderDetail.getPrice());
|
||||
packAMount = packAMount.add(orderDetail.getPackAmount()
|
||||
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
|
||||
.multiply(BigDecimal.valueOf(returnNum)));
|
||||
|
||||
orderDetail.setRefundNumber(returnNum);
|
||||
orderDetail.setStatus("refunding");
|
||||
}
|
||||
|
||||
String orderNo = generateOrderNumber(isOnline ? "XXRO" : "RO");
|
||||
TbOrderInfo returnOrder = BeanUtil.copyProperties(oldOrderInfo, TbOrderInfo.class);
|
||||
returnOrder.setId(null);
|
||||
returnOrder.setOrderNo(orderNo);
|
||||
returnOrder.setRefundAmount(returnAmount);
|
||||
returnOrder.setOrderType("refunding");
|
||||
returnOrder.setUpdatedAt(null);
|
||||
returnOrder.setSystemTime(DateUtil.current());
|
||||
returnOrder.setCreatedAt(DateUtil.current());
|
||||
returnOrder.setPayOrderNo(null);
|
||||
returnOrder.setSource(oldOrderInfo.getId());
|
||||
orderInfoMapper.insert(returnOrder);
|
||||
|
||||
return returnOrder;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object returnOrder(ReturnOrderDTO returnOrderDTO) {
|
||||
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, returnOrderDTO.getOrderId())
|
||||
.eq(TbOrderInfo::getStatus, "closed"));
|
||||
if (orderInfo == null) {
|
||||
throw new BadRequestException("订单非完单状态");
|
||||
}
|
||||
|
||||
TbShopInfo shopInfo = mpShopInfoMapper.selectById(orderInfo.getShopId());
|
||||
if (shopInfo == null) {
|
||||
throw new BadRequestException("店铺信息不存在");
|
||||
}
|
||||
|
||||
if ("1".equals(shopInfo.getIsReturn())) {
|
||||
// TODO 密码校验
|
||||
}
|
||||
|
||||
TbOrderInfo returnOrderInfo = updateReturnOrderInfo(returnOrderDTO, orderInfo, true);
|
||||
|
||||
String merchantId = orderInfo.getMerchantId();
|
||||
String shopId = orderInfo.getShopId();
|
||||
String day = DateUtils.getDay();
|
||||
String masterId = orderInfo.getMasterId();
|
||||
String payType = orderInfo.getPayType();
|
||||
BigDecimal orderAmount = orderInfo.getPayAmount();
|
||||
|
||||
|
||||
BigDecimal returnAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||
BigDecimal feeAmount = BigDecimal.ZERO;
|
||||
BigDecimal payAmount = BigDecimal.ZERO;
|
||||
|
||||
// // 线上退款
|
||||
// if ("scanCode".equals(payType) || "wx_lite".equals(payType)) {
|
||||
// payService.returnOrder(Integer.valueOf(shopId), orderInfo, returnOrderInfo);
|
||||
//
|
||||
// // 储值卡支付退款
|
||||
// } else if ("deposit".equals(payType)) {
|
||||
// orderInfoService.depositReturn();
|
||||
//
|
||||
//
|
||||
// }
|
||||
// //添加退单数据
|
||||
//
|
||||
// //更新子单表
|
||||
// if (ObjectUtil.isNotEmpty(detailPos) && detailPos.size() > 0) {
|
||||
// tbOrderDetailMapper.updateBatchOrderDetail(detailPos);
|
||||
// }
|
||||
//
|
||||
// //添加子表信息
|
||||
// if (ObjectUtil.isNotEmpty(returnDetail) && returnDetail.size() > 0) {
|
||||
// tbOrderDetailMapper.batchInsert(returnDetail, newOrderInfo.getId().toString());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("token", token);
|
||||
// jsonObject.put("type", "return");
|
||||
// jsonObject.put("orderId", 0);
|
||||
// jsonObject.put("amount", newOrderInfo.getPayAmount());
|
||||
//// jsonObject.put("data",new ReturnWTZInfo(orderId+"",newOrderInfo.getPayAmount(),details));
|
||||
// producer.putOrderCollect(jsonObject.toJSONString());
|
||||
//
|
||||
//
|
||||
// producer.printMechine(newOrderInfo.getId().toString());
|
||||
//
|
||||
//
|
||||
// //修改耗材数据
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("orderId", newOrderInfo.getId());
|
||||
// jsonObject1.put("type", "delete");
|
||||
// producer.cons(jsonObject1.toString());
|
||||
//
|
||||
// // 更新商品库存
|
||||
// for (TbOrderDetail detail : returnDetail) {
|
||||
// detail = tbOrderDetailMapper.selectByPrimaryKey(detail.getId());
|
||||
//
|
||||
// TbProductSku productSku = productSkuMapper.selectByPrimaryKey(detail.getProductSkuId());
|
||||
// TbProductWithBLOBs product = productMapper.selectByPrimaryKey(detail.getProductId());
|
||||
//
|
||||
// TbProductStockDetail tbProductStockDetail = new TbProductStockDetail();
|
||||
// tbProductStockDetail.setCreatedAt(System.currentTimeMillis());
|
||||
// tbProductStockDetail.setUpdatedAt(System.currentTimeMillis());
|
||||
// tbProductStockDetail.setShopId(detail.getShopId().toString());
|
||||
// tbProductStockDetail.setSourcePath("NORMAL");
|
||||
// tbProductStockDetail.setType("退单");
|
||||
// tbProductStockDetail.setSubType((byte) 1);
|
||||
// tbProductStockDetail.setRemark("退单: " + detail.getOrderId());
|
||||
// tbProductStockDetail.setOrderId(String.valueOf(detail.getOrderId()));
|
||||
//
|
||||
// if (ObjectUtil.isNotEmpty(product)) {
|
||||
// TbShopUnit shopUnit = shopUnitMapper.selectByPrimaryKey(Integer.valueOf(product.getUnitId()));
|
||||
//
|
||||
// tbProductStockDetail.setProductName(product.getName());
|
||||
// tbProductStockDetail.setIsStock(product.getIsStock());
|
||||
// tbProductStockDetail.setStockSnap(product.getSelectSpec());
|
||||
// tbProductStockDetail.setUnitName(shopUnit.getName());
|
||||
// tbProductStockDetail.setProductId(product.getId().toString());
|
||||
//
|
||||
// if (product.getIsDistribute() == 1) {
|
||||
//// redisUtil.seckill(RedisCst.PRODUCT + shopId.toString() + ":product" + product.getId().toString(), String.valueOf(detail.getReturnNum() + product.getStockNumber().intValue()));
|
||||
// productMapper.updateStockById(product.getId(), detail.getReturnNum() * -1);
|
||||
//
|
||||
// tbProductStockDetail.setLeftNumber(product.getStockNumber());
|
||||
// tbProductStockDetail.setStockNumber(Double.valueOf(detail.getReturnNum()));
|
||||
// } else {
|
||||
// if (ObjectUtil.isNotEmpty(productSku)) {
|
||||
//// redisUtil.seckill(RedisCst.PRODUCT + shopId.toString() + ":" + productSku.getId().toString(), String.valueOf(detail.getReturnNum() + productSku.getStockNumber().intValue()));
|
||||
// productSkuMapper.updateByskuIdSub(productSku.getId(), detail.getReturnNum() * -1);
|
||||
//
|
||||
// tbProductStockDetail.setSkuId(productSku.getId().toString());
|
||||
// tbProductStockDetail.setLeftNumber(productSku.getStockNumber().intValue());
|
||||
// tbProductStockDetail.setStockNumber(Double.valueOf(detail.getReturnNum()));
|
||||
// }
|
||||
// }
|
||||
// productSkuMapper.decrRealSalesNumber(productSku.getId(), detail.getReturnNum());
|
||||
// }
|
||||
//
|
||||
// productStockDetailMapper.insert(tbProductStockDetail);
|
||||
// }
|
||||
// redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
|
||||
//
|
||||
// // 修改台桌状态
|
||||
// mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
// .eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
// .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
//
|
||||
//
|
||||
// return Result.success(CodeEnum.SUCCESS);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.springframework.data.domain.Pageable;
|
|||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -90,4 +91,10 @@ public interface TbOrderInfoService {
|
|||
* @throws IOException /
|
||||
*/
|
||||
void download(List<TbOrderInfoDto> all, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
|
||||
/**
|
||||
* 储值卡退款
|
||||
*/
|
||||
void depositReturn(Integer userId, Integer shopId, BigDecimal returnAmount);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public interface TbShopTableService {
|
|||
|
||||
void removeCart(RemoveCartDTO removeCartDTO);
|
||||
|
||||
void returnCart(ReturnOrderDTO removeCartDTO);
|
||||
void returnCart(ReturnCartDTO returnCartDTO);
|
||||
|
||||
void clearCart(ClearCartDTO clearCartDTO);
|
||||
|
||||
|
|
@ -137,4 +137,6 @@ public interface TbShopTableService {
|
|||
Object printDishes(BaseTableDTO baseTableDTO);
|
||||
|
||||
Object choseModel(ChoseModelDTO choseModelDTO);
|
||||
|
||||
Object returnOrder(ReturnOrderDTO returnOrderDTO);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue