1.代客下单 会员点单 取消点单
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.dto.ScanPayDTO;
|
||||
|
||||
public interface TbPayService {
|
||||
void scanPay(ScanPayDTO scanPayDTO);
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.ysk.cashier.dto.ScanPayDTO;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbOrderInfoMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopPayTypeMapper;
|
||||
import cn.ysk.cashier.mybatis.service.TbOrderPaymentService;
|
||||
import cn.ysk.cashier.mybatis.vo.pay.ScanPayReq;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
||||
import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
||||
import cn.ysk.cashier.service.TbPayService;
|
||||
import cn.ysk.cashier.utils.BeanUtil;
|
||||
import cn.ysk.cashier.utils.MD5Util;
|
||||
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TbPayServiceImpl implements TbPayService {
|
||||
|
||||
// @Value("${gateway.url}")
|
||||
// private String gateWayUrl;
|
||||
// @Value("${client.backUrl}")
|
||||
// private String backUrl;
|
||||
// @Value("${thirdPay.payType}")
|
||||
// private String thirdPayType;
|
||||
// @Value("${thirdPay.url}")
|
||||
// private String url;
|
||||
// @Value("${thirdPay.callBack}")
|
||||
// private String callBack;
|
||||
|
||||
private final TbOrderInfoMapper orderInfoMapper;
|
||||
private final TbCashierCartMapper cashierCartMapper;
|
||||
private final TbMerchantThirdApplyRepository merchantThirdApplyRepository;
|
||||
private final TbOrderPaymentService orderPaymentService;
|
||||
private final TbShopPayTypeMapper shopPayTypeMapper;
|
||||
private final TbOrderDetailMapper orderDetailMapper;
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final RabbitMsgUtils rabbitMsgUtils;
|
||||
|
||||
|
||||
public TbPayServiceImpl(TbOrderInfoMapper orderInfoMapper, TbCashierCartMapper cashierCartMapper, TbMerchantThirdApplyRepository merchantThirdApplyRepository, TbOrderPaymentService orderPaymentService, TbShopPayTypeMapper shopPayTypeMapper, TbOrderDetailMapper orderDetailMapper,RabbitTemplate rabbitTemplate, RabbitMsgUtils rabbitMsgUtils) {
|
||||
this.orderInfoMapper = orderInfoMapper;
|
||||
this.cashierCartMapper = cashierCartMapper;
|
||||
this.merchantThirdApplyRepository = merchantThirdApplyRepository;
|
||||
this.orderPaymentService = orderPaymentService;
|
||||
this.shopPayTypeMapper = shopPayTypeMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
this.rabbitMsgUtils = rabbitMsgUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanPay(ScanPayDTO scanPayDTO) {
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.in(TbOrderInfo::getStatus, "unpaid", "paying")
|
||||
.eq(TbOrderInfo::getId, scanPayDTO.getOrderId())
|
||||
.eq(TbOrderInfo::getShopId, scanPayDTO.getShopId()));
|
||||
|
||||
if (orderInfo == null) {
|
||||
throw new BadRequestException("订单不存在或已支付");
|
||||
}
|
||||
|
||||
|
||||
if (ObjectUtil.isNull(orderInfo.getMerchantId()) || ObjectUtil.isEmpty(orderInfo.getMerchantId())) {
|
||||
throw new BadRequestException("订单商户id为空");
|
||||
}
|
||||
|
||||
|
||||
List<TbCashierCart> cashierCarts = cashierCartMapper.selectList(new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, scanPayDTO.getShopId())
|
||||
.eq(TbCashierCart::getOrderId, scanPayDTO.getOrderId()));
|
||||
if (cashierCarts.isEmpty()) {
|
||||
throw new BadRequestException("购物车为空");
|
||||
}
|
||||
|
||||
StringBuilder body = new StringBuilder();
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
body.append(cashierCart.getName());
|
||||
}
|
||||
|
||||
|
||||
TbMerchantThirdApply thirdApply = merchantThirdApplyRepository.getById(Integer.valueOf(orderInfo.getMerchantId()));
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
throw new BadRequestException("三方支付信息不存在");
|
||||
}
|
||||
|
||||
String payType;
|
||||
String payName;
|
||||
String qpay;
|
||||
String payTypeCode = scanPayDTO.getAuthCode().substring(0, 2);// 判断收款码
|
||||
|
||||
if(Integer.parseInt(payTypeCode) >=25 && Integer.parseInt(payTypeCode) <= 30){
|
||||
payType = "aliPay";
|
||||
payName = "支付宝支付";
|
||||
qpay = "scanCode";
|
||||
}else if(Integer.parseInt(payTypeCode) >=10 &&Integer.parseInt(payTypeCode) <=19){
|
||||
payType = "wechatPay";
|
||||
payName = "微信支付";
|
||||
qpay = "scanCode";
|
||||
}else if("62".equals(payTypeCode)){
|
||||
throw new BadRequestException("错误码");
|
||||
}else if("01".equals(payTypeCode)){
|
||||
throw new BadRequestException("错误码");
|
||||
}else {
|
||||
throw new BadRequestException("错误码");
|
||||
}
|
||||
|
||||
long count = shopPayTypeMapper.selectCount(new LambdaUpdateWrapper<TbShopPayType>()
|
||||
.eq(TbShopPayType::getShopId, scanPayDTO.getShopId())
|
||||
.eq(TbShopPayType::getIsDisplay, 1)
|
||||
.eq(TbShopPayType::getPayType, qpay));
|
||||
if (count < 1) {
|
||||
throw new BadRequestException("未到找支付方式");
|
||||
}
|
||||
|
||||
TbOrderPayment payment = orderPaymentService.getById(scanPayDTO.getOrderId());
|
||||
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||
payment = new TbOrderPayment();
|
||||
payment.setPayTypeId("ysk");
|
||||
payment.setAmount(orderInfo.getOrderAmount().doubleValue());
|
||||
payment.setPaidAmount(orderInfo.getPayAmount().doubleValue());
|
||||
payment.setHasRefundAmount((double) 0);
|
||||
payment.setPayName(payName);
|
||||
payment.setPayType(payType);
|
||||
payment.setReceived(payment.getAmount());
|
||||
payment.setChangeFee((double) 0);
|
||||
payment.setMemberId(orderInfo.getMemberId());
|
||||
payment.setShopId(orderInfo.getShopId());
|
||||
payment.setOrderId(orderInfo.getId().toString());
|
||||
payment.setCreatedAt(System.currentTimeMillis());
|
||||
payment.setAuthCode(scanPayDTO.getAuthCode());
|
||||
orderPaymentService.save(payment);
|
||||
} else {
|
||||
payment.setAuthCode(scanPayDTO.getAuthCode());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
orderPaymentService.updateById(payment);
|
||||
}
|
||||
|
||||
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfo.setPayType(qpay);
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfoMapper.update(orderInfo, new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, scanPayDTO.getOrderId()));
|
||||
|
||||
// if ("ysk".equals(thirdPayType)) {
|
||||
//
|
||||
// ScanPayReq scanPayReq = new ScanPayReq();
|
||||
// scanPayReq.setAppId(thirdApply.getAppId());
|
||||
// scanPayReq.setTimestamp(System.currentTimeMillis());
|
||||
// scanPayReq.setAuthCode(scanPayDTO.getAuthCode());
|
||||
// scanPayReq.setNotifyUrl(backUrl);
|
||||
// scanPayReq.setConsumeFee(BigDecimal.valueOf(payment.getAmount()).setScale(2, RoundingMode.DOWN).toPlainString());
|
||||
//
|
||||
// Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
||||
// scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||
//
|
||||
//
|
||||
// ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
|
||||
// if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||
// JSONObject object = JSONObject.parseObject(response.getBody());
|
||||
// if (object.get("code").equals("0")) {
|
||||
// payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
// payment.setUpdatedAt(System.currentTimeMillis());
|
||||
// orderPaymentService.saveOrUpdate(payment);
|
||||
//
|
||||
// //处理支付成功的订单
|
||||
// orderInfo.setStatus("closed");
|
||||
// orderInfo.setPayOrderNo(object.getJSONObject("data").get("orderNumber").toString());
|
||||
// orderInfoMapper.update(orderInfo, new LambdaQueryWrapper<TbOrderInfo>()
|
||||
// .eq(TbOrderInfo::getId, scanPayDTO.getOrderId()));
|
||||
//
|
||||
// //更新购物车状态
|
||||
// TbCashierCart cashierCart = new TbCashierCart();
|
||||
// cashierCart.setStatus("final");
|
||||
// int cartCount = cashierCartMapper.update(cashierCart, new LambdaQueryWrapper<TbCashierCart>()
|
||||
// .eq(TbCashierCart::getOrderId, scanPayDTO.getOrderId()));
|
||||
// log.info("更新购物车:{}", cartCount);
|
||||
//
|
||||
// //更新子单状态
|
||||
// TbOrderDetail orderDetail = new TbOrderDetail();
|
||||
// orderDetail.setStatus("closed");
|
||||
// orderDetailMapper.update(orderDetail, new LambdaQueryWrapper<TbOrderDetail>()
|
||||
// .eq(TbOrderDetail::getOrderId, scanPayDTO.getOrderId()));
|
||||
//
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("type", "create");
|
||||
// jsonObject.put("orderId", scanPayDTO.getOrderId());
|
||||
//
|
||||
// rabbitMsgUtils.sendOrderCollectMsg(jsonObject);
|
||||
//
|
||||
//
|
||||
// producer.printMechine(orderId);
|
||||
//
|
||||
// return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
|
||||
// } else {
|
||||
// String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
|
||||
// if (ObjectUtil.isNotNull(status) && "7".equals(status)) {
|
||||
//
|
||||
// orderInfo.setStatus("paying");
|
||||
// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
//
|
||||
// payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
// payment.setUpdatedAt(System.currentTimeMillis());
|
||||
// tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
// return Result.success(CodeEnum.PAYING);
|
||||
// }
|
||||
//// orderInfo.setStatus("fail");
|
||||
//// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
//// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
//
|
||||
// return Result.fail(object.getString("msg"));
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
//
|
||||
// String reqbody = "";
|
||||
//
|
||||
// if (body.length() > 15) {
|
||||
// reqbody = body.substring(0, 6).concat("....").concat(body.substring(body.length() - 6, body.length()));
|
||||
// } else {
|
||||
// reqbody = body.toString();
|
||||
// }
|
||||
//
|
||||
// PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), reqbody, reqbody, payment.getAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, authCode, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken());
|
||||
// if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||
// if ("000000".equals(publicResp.getCode())) {
|
||||
// MainScanResp mainScanResp = publicResp.getObjData();
|
||||
// if ("TRADE_SUCCESS".equals(mainScanResp.getState())) {
|
||||
// payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
// payment.setUpdatedAt(System.currentTimeMillis());
|
||||
// tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
//
|
||||
// //处理支付成功的订单
|
||||
// orderInfo.setStatus("closed");
|
||||
// orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
||||
// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
//
|
||||
// //更新购物车状态
|
||||
// int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
// log.info("更新购物车:{}", cartCount);
|
||||
//
|
||||
// //更新子单状态
|
||||
// tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
||||
//
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("token", token);
|
||||
// jsonObject.put("type", "create");
|
||||
// jsonObject.put("orderId", orderId);
|
||||
//
|
||||
// producer.putOrderCollect(jsonObject.toJSONString());
|
||||
//
|
||||
// producer.printMechine(orderId);
|
||||
//
|
||||
// return Result.success(CodeEnum.SUCCESS, mainScanResp);
|
||||
// } else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||
// orderInfo.setStatus("paying");
|
||||
// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
//
|
||||
// payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
// payment.setUpdatedAt(System.currentTimeMillis());
|
||||
// tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
// return Result.success(CodeEnum.PAYING);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -669,7 +669,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper<TbMerchantAccount>().eq(TbMerchantAccount::getAccount, account));
|
||||
String day = DateUtils.getDay();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String key = "SHOP:CODE:USER:pc" + ":" + shopId + ":" + day + ":" + tableId + ":" + (vipUserId == null ? "" : vipUserId);
|
||||
String key = "SHOP:CODE:USER:pc" + ":" + shopId + ":" + day + ":" + tableId;
|
||||
String userCode = redisTemplate.opsForValue().get(key);
|
||||
|
||||
if (StringUtils.isEmpty(userCode) || "null".equals(userCode) || "#null".equals(userCode)) {
|
||||
@@ -809,8 +809,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
cashierCartMapper.updateById(cashierCart);
|
||||
}
|
||||
if (isFirst) {
|
||||
redisTemplate.delete("SHOP:CODE:USER:pc:" + createOrderDTO.getShopId() + ":"
|
||||
+ day + ":" + createOrderDTO.getTableId() + ":" + (createOrderDTO.getVipUserId() == null ? "" : createOrderDTO.getVipUserId()));
|
||||
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + createOrderDTO.getTableId();
|
||||
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
// 推送耗材信息
|
||||
|
||||
Reference in New Issue
Block a user