1. 定时自动押金抵扣

2. 去掉分页合理化
3. 去掉取消锁单
4. 押金抵扣,如果有outtradeNo则关闭订单
This commit is contained in:
邱贞招 2024-08-28 16:47:44 +08:00
parent fe1f04a37a
commit b6272765cb
16 changed files with 285 additions and 54 deletions

View File

@ -1016,11 +1016,12 @@ public class AppVerifyController extends BaseController
@PostMapping("/order/unlockOrder")
public AjaxResult unlockOrder(String orderNo)
{
logger.info("【取消锁单】:{}", orderNo);
EtOrder etOrder = new EtOrder();
etOrder.setLocking("0");
etOrder.setOrderNo(orderNo);
return toAjax(etOrderService.updateEtOrderByOrderNo(etOrder));
// logger.info("【取消锁单】:{}", orderNo);
// EtOrder etOrder = new EtOrder();
// etOrder.setLocking("0");
// etOrder.setOrderNo(orderNo);
// return toAjax(etOrderService.updateEtOrderByOrderNo(etOrder));
return success();
}
/**
@ -1130,14 +1131,14 @@ public class AppVerifyController extends BaseController
*/
@Log(title = "换车关锁", businessType = BusinessType.CHANGELOCK)
@PostMapping("/changeVehicle/lock")
public AjaxResult changeVehicleLock(String orderNo,String changeReason,String isBluetooth,String lon,String lat,String voltage)
public AjaxResult changeVehicleLock(String orderNo,String changeReason,String isBluetooth,String lon,String lat,String voltage,String newSn)
{
if (StrUtil.isBlank(orderNo)){
logger.info("没有orderNo参数【orderNo={}】",orderNo);
return error("请传orderNo号参数"+"【orderNo="+orderNo+"");
}
logger.info("【换车关锁请求】orderNo={}",orderNo);
Boolean aBoolean = etOrderService.changeVehicleLock(orderNo,changeReason,isBluetooth,lon,lat,voltage);
Boolean aBoolean = etOrderService.changeVehicleLock(orderNo,changeReason,isBluetooth,lon,lat,voltage,newSn);
return success(aBoolean);
}

View File

@ -4,7 +4,7 @@ import com.ruoyi.common.utils.StringUtils;
/**
* 分页数据
*
*
* @author ruoyi
*/
public class PageDomain
@ -22,7 +22,7 @@ public class PageDomain
private String isAsc = "asc";
/** 分页参数合理化 */
private Boolean reasonable = true;
private Boolean reasonable = false;
public String getOrderBy()
{

View File

@ -21,8 +21,8 @@ public class PageUtils extends PageHelper
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
Boolean reasonable = pageDomain.getReasonable();
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
// Boolean reasonable = pageDomain.getReasonable();
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(false);
}
/**

View File

@ -119,7 +119,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
"/appCaptcha",
"/appCodeLogin",
"/app/**",
// "/appVerify/**",
"/appVerify/**",
"/common/upload",
"/common/receive",
"/payment/callback/**",

View File

@ -307,4 +307,9 @@ public interface EtOrderMapper
// * 判断当前是否有正在骑行中的订单
// */
// int getCurrentOrderNum(String sn);
/**
* 7天前未支付的订单
*/
List<EtOrder> selectToBePaidEtOrderList();
}

View File

@ -1,6 +1,8 @@
package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.EtOrder;
import com.ruoyi.system.domain.EtRefund;
/**
@ -82,4 +84,12 @@ public interface EtRefundMapper
* @return 退款订单
*/
EtRefund selectEtRefundByRefundNo(String refundNo);
/**
* 判断是否用户是否还有未退款的押金
*
* @param userId 用户id
* @return 结果
*/
List<EtOrder> checkUserDeposit(Long userId);
}

View File

@ -227,7 +227,7 @@ public interface IEtOrderService
/**
* 换车关锁
*/
Boolean changeVehicleLock(String orderNo,String changeReason,String isBluetooth,String lon,String lat,String voltage);
Boolean changeVehicleLock(String orderNo,String changeReason,String isBluetooth,String lon,String lat,String voltage,String newSn);
/**
* 换车开锁

View File

@ -1,6 +1,8 @@
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.EtOrder;
import com.ruoyi.system.domain.EtRefund;
/**
@ -90,4 +92,12 @@ public interface IEtRefundService
* @return 结果
*/
public int updateEtRefundByRefundNo(EtRefund etRefund);
/**
* 判断是否用户是否还有未退款的押金
*
* @param userId 用户id
* @return 结果
*/
List<EtOrder> checkUserDeposit(Long userId);
}

View File

@ -50,6 +50,13 @@ public interface IWxPayService {
*/
Transaction queryOrderByOutTradeNo(String outTradeNo);
/**
* 关闭订单
* @param outTradeNo 商户订单号
* @return 订单信息
*/
boolean closeOrder(String outTradeNo,SysDept sysDept);
/**
* 根据订单号查询订单支付结果
* @param orderNo 订单号

View File

@ -1047,7 +1047,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
@Override
public String getInOperationDevice(String timeStart, String timeEnd,String areaId) {
if(ObjectUtil.isNotEmpty(timeStart)&&ObjectUtil.isNotEmpty(timeEnd)){
QueryWrapper<AsDevice> wrapper = new QueryWrapper<AsDevice>().in("status", "1", "2", "3", "4");
QueryWrapper<AsDevice> wrapper = new QueryWrapper<AsDevice>().in("status", "1", "2", "3", "4","6");
wrapper.eq("area_id", areaId);
return asDeviceMapper.selectCount(wrapper)+"";
}
@ -1327,7 +1327,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
String token = Token.getToken();
Boolean execute = transactionTemplate.execute(e -> {
/** 2.发送命令*/
sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY1,"重启设备",null,null);
sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_REBOOT,"重启设备",null,null);
return Boolean.TRUE;
});
if(!execute)throw new ServiceException("重启设备失败");
@ -2316,7 +2316,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
List<EtParkingArea> parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea);
if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){
log.info("运营区【{}】没有禁行区,",areaId);
throw new ServiceException("运营区【{}】没有禁行区"+areaId.toString());
// throw new ServiceException("运营区【{}】没有禁行区"+areaId.toString());
}
for (EtParkingArea etParkingArea : parkingAreas) {
if(etParkingArea.getType().equals(ServiceConstants.PARKING_AREA_TYPE_BANNED_RIDING)){
@ -2349,7 +2349,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
List<EtParkingArea> parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea);
if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){
log.info("运营区【{}】没有禁行区,",areaId);
throw new ServiceException("运营区【{}】没有禁行区"+areaId.toString());
// throw new ServiceException("运营区【{}】没有禁行区"+areaId.toString());
}
for (EtParkingArea etParkingArea : parkingAreas) {
if(etParkingArea.getType().equals(ServiceConstants.PARKING_AREA_TYPE_BANNED_RIDING)){
@ -2578,7 +2578,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
for (EtLocationLog log : etLocationLogs) {
double longitude = Double.parseDouble(log.getLongitude());
double latitude = Double.parseDouble(log.getLatitude());
coordinatesList.add(new double[]{longitude, latitude});
if(longitude != 0.0 && latitude != 0.0){
coordinatesList.add(new double[]{longitude, latitude});
}
}
StringBuilder trajectoryStr = new StringBuilder();
int size = coordinatesList.size();
@ -2702,6 +2704,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
for (Datapoint datapoint:datapointList) {
if(datapoint.getId().equals(IotConstants.ONENET_LOCATION)){
String string = JSON.toJSONString(datapoint.getValue());
String at = datapoint.getAt();
if(StrUtil.isNotBlank(string)){
LocationVo locationVo = JSONObject.parseObject(string, LocationVo.class);
log.info("【手动更新】: locationVo---【{}】" , JSON.toJSONString(locationVo));
@ -2709,14 +2712,18 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP);
BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP);
log.info("转换后的GCJ02经纬度" + lon + "---" + lat);
/** 计算电量和里程后更新设备*/
int i = updateDevice(locationVo, device, lon, lat);
if(i > 0){
log.info("【手动更新】===>更新设备成功");
return true;
if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){
/** 计算电量和里程后更新设备*/
int i = updateDevice(at,locationVo, device, lon, lat);
if(i > 0){
log.info("【手动更新】===>更新设备成功");
return true;
}else{
log.info("【手动更新】===>更新设备失败");
return false;
}
}else{
log.info("【手动更新】===>更新设备失败");
return false;
noLocationUpdateDevice(at,locationVo,device);
}
}
}
@ -2730,7 +2737,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
/** 计算电量和里程后更新设备*/
public int updateDevice(LocationVo locationVo, AsDevice device, BigDecimal lon, BigDecimal lat) {
public int updateDevice(String at,LocationVo locationVo, AsDevice device, BigDecimal lon, BigDecimal lat) {
device.setLatitude(lat.toString());
device.setLongitude(lon.toString());
Integer bat = locationVo.getBat();
@ -2748,8 +2755,8 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString());
}
device.setLastTime(DateUtils.getNowDate());
device.setLastLocationTime(DateUtils.getNowDate());
device.setLastTime(DateUtils.parseDate(at));
device.setLastLocationTime(DateUtils.parseDate(at));
device.setGps("1");
// 信号强度
device.setSignalStrength(locationVo.getCsq());
@ -2759,6 +2766,34 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
return i;
}
/** 无定位更新设备 */
private void noLocationUpdateDevice(String at,LocationVo locationVo, AsDevice device) {
Integer bat = locationVo.getBat();
BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10));
log.info("保存电压:" + divide);
device.setVoltage(divide.toString());//电压
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
// 根据电压计算续航里程
if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){
remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
}
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString());
}
device.setLastTime(DateUtils.parseDate(at));
device.setGps("0");
device.setSignalStrength(locationVo.getCsq());
device.setSatellites(0);
device.setQuality(locationVo.getQ());
int i = updateLocation(device);
if(i>0){
log.info("未获取到定位===============保存电压等数值成功===========>" + device.getSn());
}
}
/**

View File

@ -22,6 +22,7 @@ import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.*;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.Refund;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@ -436,6 +437,36 @@ public class EtOrderServiceImpl implements IEtOrderService
if(!ServiceConstants.ORDER_STATUS_RIDING_END.equals(order.getStatus())){
throw new ServiceException("押金抵扣失败,订单非待支付状态,订单状态:"+order.getStatus());
}
// 押金抵扣时判断是否有outtradeno
if(StrUtil.isNotBlank(order.getOutTradeNo())){
String outTradeNo = order.getOutTradeNo();
log.info("【押金抵扣】订单【{}】,有outTradeNo = 【{}】", order.getOrderNo(),outTradeNo);
// 如果原来有outtradeno去查询一次查询是否支付过
Transaction transaction = wxPayService.queryOrderByOutTradeNo(outTradeNo);
if (Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) {
// 订单已支付
order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
order.setPayTime(DateUtils.getNowDate());
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
order.setPayType(ServiceConstants.PAY_TYPE_WX);
order.setMark("主动查询-骑行支付");
try {
int updateEtOrder = etOrderMapper.updateEtOrder(order);
if (updateEtOrder == 0) {
// 抛出自定义异常来标识订单更新失败
throw new ServiceException("押金抵扣失败,更新骑行订单失败");
}
} finally {
// 无论订单更新是否成功一定抛出异常来终止后续操作
throw new ServiceException("订单已支付,请勿操作");
}
}else{
SysDept dept = wxPayService.getDeptObjByAreaId(order.getAreaId());
// 没有支付则关闭订单
boolean b = wxPayService.closeOrder(outTradeNo, dept);
log.info("【押金抵扣】订单【{}】,有outTradeNo = 【{}】,查询订单未支付,关闭订单:{}", order.getOrderNo(),outTradeNo,b);
}
}
EtOrder depositOrder = getDepositOrder(order.getUserId());
BigDecimal deposit = depositOrder.getTotalFee();
BigDecimal ridingFee = order.getTotalFee();
@ -1205,13 +1236,12 @@ public class EtOrderServiceImpl implements IEtOrderService
String totalRefund = etOrderMapper.getTotalRefund(timeStart, timeEnd, areaId);//已退款
income.setTotalPaid(totalPaid);//已支付
//handlingFee 手续费 = 0.0054 * 已支付金额
SysDept sysDept = wxPayService.getDeptObjByAreaId(Long.parseLong(areaId));
String handlingCharge = sysDept.getHandlingCharge();
BigDecimal divide = new BigDecimal(handlingCharge).divide(new BigDecimal(1000), 4, RoundingMode.HALF_UP);
BigDecimal handlingFee = new BigDecimal(totalPaid).multiply(divide);
income.setHandlingFee(handlingFee.setScale(2, RoundingMode.HALF_UP).toString());
BigDecimal handlingFee = etCapitalFlowMapper.getHandlingFee(timeStart, timeEnd, null, Long.parseLong(areaId));//手续费,扣除掉退款部分的
BigDecimal platformServiceFee = etCapitalFlowMapper.getServiceFee(timeStart, timeEnd, null,Long.parseLong(areaId));//平台服务费 ,扣除掉退款部分的
income.setHandlingFee(handlingFee.toString());
// 总营收 = 已支付 - 已退款 - 手续费
income.setTotalIncome(new BigDecimal(totalPaid).subtract(new BigDecimal(totalRefund)).subtract(handlingFee).setScale(2, RoundingMode.HALF_UP).toString());//总收入 etOrderMapper.getTotalIncome(timeStart,timeEnd,areaId)
income.setTotalIncome(new BigDecimal(totalPaid).subtract(new BigDecimal(totalRefund)).subtract(handlingFee).subtract(platformServiceFee).toString());//总收入
income.setTotalRefund(totalRefund);//已退款
income.setTotalFee(new BigDecimal(totalUnpaid).add(new BigDecimal(totalPaid)).toString());// 订单总金额 = 已支付+待支付
income.setTotalRidingFee(etOrderMapper.getTotalRidingFee(timeStart,timeEnd,areaId));//骑行已支付
@ -1771,7 +1801,7 @@ public class EtOrderServiceImpl implements IEtOrderService
@Override
@Transactional
@SneakyThrows
public Boolean changeVehicleLock(String orderNo,String changeReason,String isBluetooth,String lon,String lat,String voltage) {
public Boolean changeVehicleLock(String orderNo,String changeReason,String isBluetooth,String lon,String lat,String voltage,String newSn) {
EtOrder order = etOrderMapper.selectEtOrderByOrderNo(orderNo);
if(!ServiceConstants.ORDER_STATUS_RIDING.equals(order.getStatus())){
throw new ServiceException("该订单状态非骑行中");
@ -1819,7 +1849,7 @@ public class EtOrderServiceImpl implements IEtOrderService
usedSn = sn;
}
order.setUsedSn(usedSn);
order.setSn("");
order.setSn(newSn);
order.setChangeReason(changeReason);
int i = etOrderMapper.updateEtOrderByOrderNo(order);
if(i==0){
@ -1865,8 +1895,8 @@ public class EtOrderServiceImpl implements IEtOrderService
if(!"true".equals(isBluetooth)){
ResponseVo responseVo = asDeviceService.sendCommandWithResp(newDevice.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "换车开锁",orderNo);
if(responseVo.getCode()!=0){
log.info("还车关锁】远程关锁失败");
throw new ServiceException("远程关锁失败");
log.info("换车开锁】远程关锁失败");
throw new ServiceException("换车开锁失败");
}
}else{
newDevice.setLongitude(lon);
@ -1891,15 +1921,15 @@ public class EtOrderServiceImpl implements IEtOrderService
if(i>0){
log.info("管理员开锁,更新设备状态成功");
}
order.setSn(newSn);
int i2 = etOrderMapper.updateEtOrderByOrderNo(order);
if(i2==0){
log.info("【换车开锁】更新订单sn失败");
throw new ServiceException("【换车开锁】更新订单sn失败");
}
return Boolean.TRUE;
});
if(!execute)throw new ServiceException("换车开锁失败");
order.setSn(newSn);
int i = etOrderMapper.updateEtOrderByOrderNo(order);
if(i==0){
log.info("【换车开锁】更新订单sn失败");
throw new ServiceException("【换车开锁】更新订单sn失败");
}
return Boolean.TRUE;
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.EtOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.EtRefundMapper;
@ -142,4 +143,15 @@ public class EtRefundServiceImpl implements IEtRefundService
public int updateEtRefundByRefundNo(EtRefund etRefund) {
return etRefundMapper.updateEtRefundByRefundNo(etRefund);
}
/**
* 判断是否用户是否还有未退款的押金
*
* @param userId 用户id
* @return 结果
*/
@Override
public List<EtOrder> checkUserDeposit(Long userId) {
return etRefundMapper.checkUserDeposit(userId);
}
}

View File

@ -184,6 +184,22 @@ public class WxPayService implements IWxPayService {
}
}
/**
* 关闭订单
* @param outTradeNo 商户订单号
* @return
*/
@Override
public boolean closeOrder(String outTradeNo, SysDept sysDept) {
JsapiServiceExtension jsapiServiceExtension = getJsapiServiceExtension(sysDept);
// 关闭订单
CloseOrderRequest closeOrderRequest = new CloseOrderRequest();
closeOrderRequest.setMchid(sysDept.getMerchantId());
closeOrderRequest.setOutTradeNo(outTradeNo);
jsapiServiceExtension.closeOrder(closeOrderRequest);
return true;
}
/**
* 根据订单号查询订单
* @param orderNo 商户订单号
@ -196,6 +212,9 @@ public class WxPayService implements IWxPayService {
log.info("获取到运营商对象:【{}】",JSON.toJSON(sysDept));
QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
request.setMchid(sysDept.getMerchantId());
if(StrUtil.isBlank(order.getOutTradeNo())){
return false;
}
request.setOutTradeNo(order.getOutTradeNo());
JsapiService jsapiService = getJsapiService(sysDept);
Transaction transaction = jsapiService.queryOrderByOutTradeNo(request);
@ -207,17 +226,19 @@ public class WxPayService implements IWxPayService {
order.setPayType(ServiceConstants.PAY_TYPE_WX);
log.info("【主动查询】押金支付");
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
order.setMark("押金支付");
// 更新用户余额
AsUser asUser = asUserMapper.selectUserById(order.getUserId());
asUser.setBalance(order.getTotalFee());
int updateUser = asUserMapper.updateUser(asUser);
if(updateUser==0){
log.error("【微信支付回调】更新用户押金失败");
throw new ServiceException("【微信支付回调】更新用户押金失败");
if(ServiceConstants.ORDER_TYPE_RIDING.equals(order.getType())){
order.setMark("主动查询-骑行支付");
}else{
order.setMark("押金支付");
// 更新用户余额
AsUser asUser = asUserMapper.selectUserById(order.getUserId());
asUser.setBalance(order.getTotalFee());
int updateUser = asUserMapper.updateUser(asUser);
if(updateUser==0){
log.error("【微信支付回调】更新用户押金失败");
throw new ServiceException("【微信支付回调】更新用户押金失败");
}
}
int updateEtOrder = orderService.updateEtOrder(order);
if(updateEtOrder==0){
log.error("【微信支付回调】更新订单信息失败");

View File

@ -15,6 +15,7 @@ import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.*;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.Refund;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -407,4 +408,81 @@ public class EtTask {
etLocationLogMapper.deleteLocationLogByCreateTime();
}
// 写一个定时如果车辆是骑行中没有现在骑行中的订单则关闭车辆
/**
* 自动押金抵扣
* 写一个定时任务处理所有的 7天前待支付的订单用押金抵扣如果已经退押金的直接改成结束订单
* 1. 查询所有待支付的订单根据还车时间7天前的订单
* 2. 如果订单金额是0直接结束订单修改订单状态为已支付
* 3. 查询用户是否还有未退款的押金如果有则进行押金抵扣如果没有则结束订单
*/
public void autoDeduction(){
log.info("-------------------【定时任务】自动押金抵扣-------------------");
/** 1. 查询所有待支付的订单根据还车时间7天前的订单 */
List<EtOrder> orders = etOrderMapper.selectToBePaidEtOrderList();
if(ObjectUtil.isNotNull(orders) && orders.size()>0){
for(EtOrder order:orders){
if(order.getTotalFee().compareTo(BigDecimal.ZERO) == 0){
// 结束订单修改订单状态为已支付
updateOrderPaid(order);
}else{
etOrderService.deduction(order);
// if(StrUtil.isNotBlank(order.getOutTradeNo())){
// String outTradeNo = order.getOutTradeNo();
// log.info("【自动押金抵扣】订单【{}】,有outTradeNo = 【{}】", order.getOrderNo(),outTradeNo);
// // 如果原来有outtradeno去查询一次查询是否支付过
// Transaction transaction = wxPayService.queryOrderByOutTradeNo(outTradeNo);
// if(Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) {
// // 订单已支付
// order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
// order.setPayTime(DateUtils.getNowDate());
// order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
// order.setPayType(ServiceConstants.PAY_TYPE_WX);
// order.setMark("主动查询-骑行支付");
// int updateEtOrder = etOrderMapper.updateEtOrder(order);
// if (updateEtOrder == 0) {
// throw new ServiceException("押金抵扣失败,更新骑行订单失败");
// }
// }else{
// updateOrderPaid(order);
// }
// }else{
// // 3. 查询用户是否还有未退款的押金如果有则进行押金抵扣如果没有则结束订单
// List<EtOrder> yjOrders = etRefundService.checkUserDeposit(order.getUserId());
// if(ObjectUtil.isNotNull(yjOrders) && yjOrders.size()>0){
// // 取出最后一个订单对象
// yjOrders.sort(Comparator.comparing(EtOrder::getCreateTime)); // 按create_time升序排序
// EtOrder lastOrder = yjOrders.get(yjOrders.size() - 1); // 获取最后一个订单对象
// etOrderService.deduction();
// }else{
// updateOrderPaid(order);
// }
// }
}
}
}
}
/** 更新订单为已支付*/
private void updateOrderPaid(EtOrder order) {
order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
order.setPayTime(DateUtils.getNowDate());
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
order.setPayType(ServiceConstants.PAY_TYPE_YJ);
order.setMark("超过7天系统自动押金抵扣");
order.setDepositDeduction(ServiceConstants.IS_DEPOSIT_DEDUCTION);
int updateEtOrder = etOrderMapper.updateEtOrder(order);
if(updateEtOrder == 0){
throw new ServiceException("押金抵扣失败,更新骑行订单失败");
}
}
/** 如果还有未退款的押金,如果有,则进行押金抵扣 */
private void autoDeductionHandle(EtOrder order){
// select * from et_order o
// where o.status ='4' and o.paid = '1' and o.type = 1 and o.is_test = '0'
// GROUP BY o.user_id
}
}

View File

@ -869,5 +869,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- select count(1) from et_order where sn = #{sn} and status = 2-->
<!-- </select>-->
<select id="selectToBePaidEtOrderList" resultType="com.ruoyi.system.domain.EtOrder">
<include refid="selectEtOrderVoNoRoute"/>
where status = 3 and return_time &lt;= DATE_SUB(NOW(), INTERVAL 7 DAY)
</select>
</mapper>

View File

@ -146,4 +146,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="checkUserDeposit" resultType="EtOrder">
SELECT o.order_id,
o.area_id,
o.order_no,
o.out_trade_no,
o.create_time,
o.user_id,
ref.id,
ref.refund_no
FROM et_order o
LEFT JOIN et_refund ref ON ref.order_no = o.order_no
WHERE o.status = '4'
AND o.paid = '1'
AND o.type = 2 and o.user_id = #{userId}
AND ref.id IS NULL;
</select>
</mapper>