1.代客下单 扫码支付,储值卡扫码支付
This commit is contained in:
parent
44329cc64e
commit
0b645bd695
|
|
@ -20,7 +20,7 @@ public class TbPayController {
|
|||
public ResponseEntity<?> scanPay(
|
||||
@RequestBody @Validated ScanPayDTO scanPayDTO
|
||||
) {
|
||||
payService.scanPay(scanPayDTO);
|
||||
// payService.scanPay(scanPayDTO);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@ public class PayDTO {
|
|||
@Max(1)
|
||||
private Double discount;
|
||||
private Integer vipUserId;
|
||||
private String code;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_activate")
|
||||
public class TbActivate {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "shop_id")
|
||||
private Integer shopId;
|
||||
|
||||
@Column(name = "min_num")
|
||||
private Integer minNum;
|
||||
|
||||
@Column(name = "max_num")
|
||||
private Integer maxNum;
|
||||
|
||||
@Column(name = "handsel_num", precision = 10, scale = 2)
|
||||
private BigDecimal handselNum;
|
||||
|
||||
@Size(max = 20)
|
||||
@Column(name = "handsel_type", length = 20)
|
||||
private String handselType;
|
||||
|
||||
@Size(max = 20)
|
||||
@Column(name = "is_del", length = 20)
|
||||
private String isDel;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "is_user")
|
||||
private String isUser;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.pojo.TbUserInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface MpUserInfoMapper extends BaseMapper<TbUserInfo> {
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivate;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_activate】的数据库操作Mapper
|
||||
* @createDate 2024-09-03 14:08:30
|
||||
* @Entity cn.ysk.cashier.mybatis.pojo.TbActivatetb
|
||||
*/
|
||||
public interface TbActivateMapper extends BaseMapper<TbActivate> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopUser;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivate;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_activate】的数据库操作Service
|
||||
* @createDate 2024-09-03 14:08:30
|
||||
*/
|
||||
public interface TbActivateService extends IService<TbActivate> {
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopUser;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivate;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateService;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_activate】的数据库操作Service实现
|
||||
* @createDate 2024-09-03 14:08:30
|
||||
*/
|
||||
@Service
|
||||
public class TbActivateServiceImpl extends ServiceImpl<TbActivateMapper, TbActivate>
|
||||
implements TbActivateService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopUser;
|
||||
import cn.ysk.cashier.mybatis.service.TbMShopUserService;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbMShopUserMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ import org.springframework.stereotype.Service;
|
|||
*/
|
||||
@Service
|
||||
public class TbMShopUserServiceImpl extends ServiceImpl<TbMShopUserMapper, TbShopUser>
|
||||
implements TbMShopUserService{
|
||||
implements TbMShopUserService {
|
||||
|
||||
private final TbMShopUserMapper shopUserMapper;
|
||||
|
||||
|
|
|
|||
|
|
@ -151,6 +151,9 @@ public class TbShopUser implements Serializable {
|
|||
@Column(name = "`mini_open_id`")
|
||||
@ApiModelProperty(value = "小程序openId")
|
||||
private String miniOpenId;
|
||||
@Column(name = "`dynamic_code`")
|
||||
private String dynamicCode;
|
||||
|
||||
|
||||
public void copy(TbShopUser source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
|
|
|
|||
|
|
@ -4,12 +4,17 @@ import cn.ysk.cashier.dto.ScanPayDTO;
|
|||
import cn.ysk.cashier.dto.shoptable.PayDTO;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface TbPayService {
|
||||
void scanPay(ScanPayDTO scanPayDTO);
|
||||
TbOrderInfo scanPay(PayDTO payDTO);
|
||||
|
||||
TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId);
|
||||
|
||||
TbOrderInfo cashPay(PayDTO payDTO);
|
||||
|
||||
TbOrderInfo memberAccountPay(String memberId, String shopId, String accountCode, Integer orderId, Double discount) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.ysk.cashier.dto.ScanPayDTO;
|
||||
import cn.ysk.cashier.dto.shoptable.PayDTO;
|
||||
import cn.ysk.cashier.enums.TableStateEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopUser;
|
||||
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
import cn.ysk.cashier.mybatis.service.TbOrderPaymentService;
|
||||
import cn.ysk.cashier.mybatis.vo.pay.MainScanReq;
|
||||
import cn.ysk.cashier.mybatis.vo.pay.MainScanResp;
|
||||
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.pojo.shop.TbShopTable;
|
||||
import cn.ysk.cashier.pojo.shop.*;
|
||||
import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||
import cn.ysk.cashier.service.TbPayService;
|
||||
import cn.ysk.cashier.thirdpay.constants.SignTypeEnum;
|
||||
import cn.ysk.cashier.thirdpay.req.PublicParam;
|
||||
import cn.ysk.cashier.thirdpay.resp.PublicResp;
|
||||
import cn.ysk.cashier.thirdpay.service.ThirdPayService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
|
|
@ -37,6 +34,8 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
|
@ -44,13 +43,16 @@ import java.sql.Timestamp;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.ysk.cashier.thirdpay.service.ThirdPayService.sortFields;
|
||||
import static cn.ysk.cashier.thirdpay.service.ThirdPayService.sortFieldsAndPrint;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TbPayServiceImpl implements TbPayService {
|
||||
|
||||
private final TbShopInfoRepository tbShopInfoRepository;
|
||||
private final TbMerchantAccountMapper tbMerchantAccountMapper;
|
||||
private final TbMShopUserMapper tbMShopUserMapper;
|
||||
private final TbShopPayTypeMapper tbShopPayTypeMapper;
|
||||
private final TbMemberInMapper tbMemberInMapper;
|
||||
private final TbActivateMapper tbActivateMapper;
|
||||
@Value("${gateway.url}")
|
||||
private String gateWayUrl;
|
||||
@Value("${client.backUrl}")
|
||||
|
|
@ -75,10 +77,11 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
private final RestTemplate restTemplate;
|
||||
private final MpOrderPaymentMapper mpOrderPaymentMapper;
|
||||
private final ThirdPayService thirdPayService;
|
||||
private final MpUserInfoMapper mpUserInfoMapper;
|
||||
|
||||
|
||||
|
||||
public TbPayServiceImpl(TbOrderInfoMapper orderInfoMapper, TbCashierCartMapper cashierCartMapper, TbMerchantThirdApplyRepository merchantThirdApplyRepository, TbOrderPaymentService orderPaymentService, TbShopPayTypeMapper shopPayTypeMapper, TbOrderDetailMapper orderDetailMapper, RabbitTemplate rabbitTemplate, RabbitMsgUtils rabbitMsgUtils, MpShopTableMapper mpShopTableMapper, RestTemplate restTemplate, MpOrderPaymentMapper mpOrderPaymentMapper, ThirdPayService thirdPayService, TbMShopUserMapper shopUserMapper, TbShopUserFlowMapper shopUserFlowMapper) {
|
||||
public TbPayServiceImpl(TbOrderInfoMapper orderInfoMapper, TbCashierCartMapper cashierCartMapper, TbMerchantThirdApplyRepository merchantThirdApplyRepository, TbOrderPaymentService orderPaymentService, TbShopPayTypeMapper shopPayTypeMapper, TbOrderDetailMapper orderDetailMapper, RabbitTemplate rabbitTemplate, RabbitMsgUtils rabbitMsgUtils, MpShopTableMapper mpShopTableMapper, RestTemplate restTemplate, MpOrderPaymentMapper mpOrderPaymentMapper, ThirdPayService thirdPayService, TbMShopUserMapper shopUserMapper, TbShopUserFlowMapper shopUserFlowMapper, TbShopInfoRepository tbShopInfoRepository, TbMerchantAccountMapper tbMerchantAccountMapper, TbMShopUserMapper tbMShopUserMapper, TbShopPayTypeMapper tbShopPayTypeMapper, TbMemberInMapper tbMemberInMapper, MpUserInfoMapper mpUserInfoMapper, TbActivateMapper tbActivateMapper) {
|
||||
this.orderInfoMapper = orderInfoMapper;
|
||||
this.cashierCartMapper = cashierCartMapper;
|
||||
this.merchantThirdApplyRepository = merchantThirdApplyRepository;
|
||||
|
|
@ -93,10 +96,17 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
this.thirdPayService = thirdPayService;
|
||||
this.shopUserMapper = shopUserMapper;
|
||||
this.shopUserFlowMapper = shopUserFlowMapper;
|
||||
this.tbShopInfoRepository = tbShopInfoRepository;
|
||||
this.tbMerchantAccountMapper = tbMerchantAccountMapper;
|
||||
this.tbMShopUserMapper = tbMShopUserMapper;
|
||||
this.tbShopPayTypeMapper = tbShopPayTypeMapper;
|
||||
this.tbMemberInMapper = tbMemberInMapper;
|
||||
this.mpUserInfoMapper = mpUserInfoMapper;
|
||||
this.tbActivateMapper = tbActivateMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanPay(ScanPayDTO scanPayDTO) {
|
||||
public TbOrderInfo scanPay(PayDTO scanPayDTO) {
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.in(TbOrderInfo::getStatus, "unpaid", "paying")
|
||||
.eq(TbOrderInfo::getId, scanPayDTO.getOrderId())
|
||||
|
|
@ -133,7 +143,7 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
String payType;
|
||||
String payName;
|
||||
String qpay;
|
||||
String payTypeCode = scanPayDTO.getAuthCode().substring(0, 2);// 判断收款码
|
||||
String payTypeCode = scanPayDTO.getCode().substring(0, 2);// 判断收款码
|
||||
|
||||
if(Integer.parseInt(payTypeCode) >=25 && Integer.parseInt(payTypeCode) <= 30){
|
||||
payType = "aliPay";
|
||||
|
|
@ -174,10 +184,10 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
payment.setShopId(orderInfo.getShopId());
|
||||
payment.setOrderId(orderInfo.getId().toString());
|
||||
payment.setCreatedAt(System.currentTimeMillis());
|
||||
payment.setAuthCode(scanPayDTO.getAuthCode());
|
||||
payment.setAuthCode(scanPayDTO.getCode());
|
||||
orderPaymentService.save(payment);
|
||||
} else {
|
||||
payment.setAuthCode(scanPayDTO.getAuthCode());
|
||||
payment.setAuthCode(scanPayDTO.getCode());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
orderPaymentService.updateById(payment);
|
||||
}
|
||||
|
|
@ -189,143 +199,123 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
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);
|
||||
// rabbitMsgUtils.printTicket(scanPayDTO.getOrderId().toString());
|
||||
//
|
||||
//
|
||||
// } else {
|
||||
// String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
|
||||
// if (ObjectUtil.isNotNull(status) && "7".equals(status)) {
|
||||
//
|
||||
// orderInfo.setStatus("paying");
|
||||
if ("ysk".equals(thirdPayType)) {
|
||||
|
||||
ScanPayReq scanPayReq = new ScanPayReq();
|
||||
scanPayReq.setAppId(thirdApply.getAppId());
|
||||
scanPayReq.setTimestamp(System.currentTimeMillis());
|
||||
scanPayReq.setAuthCode(scanPayDTO.getCode());
|
||||
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()));
|
||||
|
||||
|
||||
|
||||
} 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());
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
|
||||
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
mpOrderPaymentMapper.updateById(payment);
|
||||
|
||||
}
|
||||
// orderInfo.setStatus("fail");
|
||||
// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
// orderInfoMapper.updateById(orderInfo);
|
||||
//
|
||||
// payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
// payment.setUpdatedAt(System.currentTimeMillis());
|
||||
// mpOrderPaymentMapper.updateById(payment);
|
||||
//
|
||||
//
|
||||
// // 修改台桌状态
|
||||
// mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
// .eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
// .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
// rabbitMsgUtils.printTicket(scanPayDTO.getOrderId().toString());
|
||||
// }
|
||||
//// orderInfo.setStatus("fail");
|
||||
//// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
//// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// } 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,
|
||||
// BigDecimal.valueOf(payment.getAmount()).setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(),
|
||||
// payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null,
|
||||
// scanPayDTO.getAuthCode(), 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());
|
||||
// orderPaymentService.updateById(payment);
|
||||
//
|
||||
// //处理支付成功的订单
|
||||
// orderInfo.setStatus("closed");
|
||||
// orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
||||
// orderInfoMapper.updateById(orderInfo);
|
||||
//
|
||||
// //更新购物车状态
|
||||
// int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
// .eq(TbCashierCart::getOrderId, orderInfo.getId())
|
||||
// .set(TbCashierCart::getStatus, "final"));
|
||||
// log.info("更新购物车:{}", cartCount);
|
||||
//
|
||||
// //更新子单状态
|
||||
// orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
// .eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
// .set(TbOrderDetail::getStatus, "closed"));
|
||||
//
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("token", null);
|
||||
// jsonObject.put("type", "create");
|
||||
// jsonObject.put("orderId", scanPayDTO.getOrderId());
|
||||
//
|
||||
//
|
||||
// // 修改台桌状态
|
||||
// mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
// .eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
// .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
// } else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||
// orderInfo.setStatus("paying");
|
||||
// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
// orderInfoMapper.updateById(orderInfo);
|
||||
//
|
||||
// payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
// payment.setUpdatedAt(System.currentTimeMillis());
|
||||
// orderPaymentService.updateById(payment);
|
||||
//
|
||||
// rabbitMsgUtils.printTicket(scanPayDTO.getOrderId().toString());
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
}
|
||||
}
|
||||
} 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,
|
||||
BigDecimal.valueOf(payment.getAmount()).setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(),
|
||||
payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null,
|
||||
scanPayDTO.getCode(), 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());
|
||||
orderPaymentService.updateById(payment);
|
||||
|
||||
//处理支付成功的订单
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
||||
.set(TbCashierCart::getStatus, "final"));
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
//更新子单状态
|
||||
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.set(TbOrderDetail::getStatus, "closed"));
|
||||
|
||||
|
||||
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
|
||||
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
orderPaymentService.updateById(payment);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return orderInfo;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -342,6 +332,10 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
throw new BadRequestException("订单非未支付状态");
|
||||
}
|
||||
|
||||
if (vipUserId != null) {
|
||||
orderInfo.setUserId(String.valueOf(vipUserId));
|
||||
}
|
||||
|
||||
|
||||
// 扣减会员余额
|
||||
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
|
||||
|
|
@ -352,7 +346,7 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
throw new BadRequestException("用户不存在或已被禁用");
|
||||
}
|
||||
|
||||
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.UP);
|
||||
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.HALF_UP);
|
||||
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), finalAmount);
|
||||
if (flag < 1) {
|
||||
throw new BadRequestException("余额不足或扣除余额失败");
|
||||
|
|
@ -372,6 +366,8 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
orderInfo.setPayType("cash");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
orderInfo.setDiscountRatio(BigDecimal.valueOf(discount));
|
||||
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(finalAmount));
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
//更新购物车状态
|
||||
int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
|
|
@ -412,10 +408,13 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||
// }
|
||||
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount()).setScale(2, RoundingMode.UP)));
|
||||
BigDecimal payMount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount()).setScale(2, RoundingMode.HALF_UP));
|
||||
orderInfo.setPayAmount(payMount);
|
||||
orderInfo.setPayType("cash");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
||||
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(payMount));
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
|
|
@ -429,6 +428,99 @@ public class TbPayServiceImpl implements TbPayService {
|
|||
orderDetailMapper.update(orderDetail, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, payDTO.getOrderId()));
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
public TbOrderInfo memberAccountPay(String memberId, String shopId, String accountCode, Integer orderId, Double discount) throws Exception {
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, orderId)
|
||||
.eq(TbOrderInfo::getShopId, shopId));
|
||||
|
||||
if (orderInfo == null) {
|
||||
throw new BadRequestException("订单不存在或已支付");
|
||||
}
|
||||
|
||||
if (!"unpaid".equals(orderInfo.getStatus()) && !"pending".equals(orderInfo.getStatus())) {
|
||||
throw new BadRequestException("此订单不处于未支付状态");
|
||||
}
|
||||
|
||||
BigDecimal payMount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount).setScale(2, RoundingMode.HALF_UP));
|
||||
|
||||
long count = tbShopPayTypeMapper.selectCount(new LambdaQueryWrapper<TbShopPayType>()
|
||||
.eq(TbShopPayType::getShopId, shopId)
|
||||
.eq(TbShopPayType::getIsDisplay, 1)
|
||||
.eq(TbShopPayType::getPayType, "deposit"));
|
||||
if (count < 1) {
|
||||
throw new BadRequestException("未知支付方式");
|
||||
}
|
||||
|
||||
|
||||
TbShopUser user = null;
|
||||
|
||||
if (ObjectUtil.isNotEmpty(memberId)) {
|
||||
user = shopUserMapper.selectById(Integer.valueOf(memberId));
|
||||
}
|
||||
|
||||
|
||||
if (ObjectUtil.isNotEmpty(accountCode)) {
|
||||
|
||||
if (!accountCode.startsWith("46")) {
|
||||
throw new BadRequestException("无效二维码");
|
||||
}
|
||||
|
||||
user = shopUserMapper.selectOne(new LambdaQueryWrapper<TbShopUser>()
|
||||
.eq(TbShopUser::getShopId, shopId)
|
||||
.eq(TbShopUser::getDynamicCode, accountCode));
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
}
|
||||
|
||||
shopUserMapper.update(null, new LambdaUpdateWrapper<TbShopUser>()
|
||||
.eq(TbShopUser::getId, user.getId())
|
||||
.apply(StrUtil.format("amount-{}>=0", payMount.doubleValue()))
|
||||
.setSql(StrUtil.format("amount=amount-{}", payMount.doubleValue()))
|
||||
.setSql(StrUtil.format("consume_amount=consume_amount+{}", payMount.doubleValue()))
|
||||
.setSql(StrUtil.format("consume_number=consume_number+1"))
|
||||
.set(TbShopUser::getUpdatedAt, DateUtil.current() / 1000)
|
||||
);
|
||||
|
||||
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(user.getId());
|
||||
flow.setBizCode("accountPay");
|
||||
flow.setBizName("余额支付");
|
||||
flow.setType("-");
|
||||
flow.setAmount(payMount);
|
||||
flow.setBalance(user.getAmount());
|
||||
flow.setCreateTime(DateUtil.date().toTimestamp());
|
||||
flow.setIsReturn("0");
|
||||
shopUserFlowMapper.insert(flow);
|
||||
|
||||
|
||||
orderInfo.setPayAmount(payMount);
|
||||
orderInfo.setUserId(user.getUserId());
|
||||
orderInfo.setMemberId(user.getId().toString());
|
||||
orderInfo.setPayType("deposit");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
//更新购物车状态
|
||||
int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getId, orderId)
|
||||
.set(TbCashierCart::getStatus, "final"));
|
||||
|
||||
|
||||
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderId)
|
||||
.set(TbOrderDetail::getStatus, "closed"));
|
||||
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1242,6 +1242,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
case "cash":
|
||||
orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
||||
break;
|
||||
case "scanPay":
|
||||
orderInfo = tbPayServiceImpl.scanPay(payDTO);
|
||||
break;
|
||||
case "accountPay":
|
||||
try {
|
||||
orderInfo = tbPayServiceImpl.memberAccountPay("", String.valueOf(payDTO.getShopId()), payDTO.getCode(), payDTO.getOrderId(), payDTO.getDiscount());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException("未知支付方式");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.ysk.cashier.mybatis.mapper.TbActivateMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="cn.ysk.cashier.mybatis.pojo.TbActivatetb">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="shop_id" column="shop_id" jdbcType="INTEGER"/>
|
||||
<result property="min_num" column="min_num" jdbcType="INTEGER"/>
|
||||
<result property="max_num" column="max_num" jdbcType="INTEGER"/>
|
||||
<result property="handsel_num" column="handsel_num" jdbcType="DECIMAL"/>
|
||||
<result property="handsel_type" column="handsel_type" jdbcType="VARCHAR"/>
|
||||
<result property="is_del" column="is_del" jdbcType="VARCHAR"/>
|
||||
<result property="is_user" column="is_user" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,shop_id,min_num,
|
||||
max_num,handsel_num,handsel_type,
|
||||
is_del,is_user
|
||||
</sql>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue