@ -259,6 +259,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
lqw . eq ( bo . getSettlement ( ) ! = null , ProductOrder : : getSettlement , bo . getSettlement ( ) ) ;
lqw . eq ( StringUtils . isNotBlank ( bo . getStatus ( ) ) , ProductOrder : : getStatus , bo . getStatus ( ) ) ;
lqw . eq ( StringUtils . isNotBlank ( bo . getShowBusiness ( ) ) , ProductOrder : : getShowBusiness , bo . getShowBusiness ( ) ) ;
lqw . lt ( bo . getStartRefundTime ( ) ! = null , ProductOrder : : getStartRefundTime , DateUtil . offsetDay ( bo . getStartRefundTime ( ) , - 2 ) . toJdkDate ( ) ) ;
lqw . apply ( StringUtils . isNotBlank ( bo . getKeyworkds ( ) ) , "locate({0}, order_no) > 0 or locate({0}, mobile) > 0 or locate({0}, product_name) > 0 " , bo . getKeyworkds ( ) ) ;
return lqw ;
}
@ -590,6 +591,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
public void paySuccess ( Long orderId , BigDecimal cashPrice ) {
ProductOrderVo productOrderVo = queryById ( orderId ) ;
productOrderVo . setStatus ( "1" ) ;
productOrderVo . setIsPay ( "1" ) ;
productOrderVo . setPayTime ( new Date ( ) ) ;
productOrderPriceService . updateRealPriceByOrderId ( cashPrice , orderId ) ;
//修改订单数据
@ -753,7 +755,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
@Override
public Long getOrderCount ( ) {
QueryWrapper < ProductOrder > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( "status ", "1" , "2" , "4" , "5 " ) ;
queryWrapper . eq ( "is_pay ", "1" ) ;
return baseMapper . selectCount ( queryWrapper ) ;
}
@ -797,7 +799,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
@Override
public Long getOrderUserCount ( ) {
QueryWrapper < ProductOrder > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( "status ", "1" , "2" , "4" , "5 " ) ;
queryWrapper . eq ( "is_pay ", "1" ) ;
return baseMapper . selectCount ( queryWrapper ) ;
}
@ -805,7 +807,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
public Long getYesterdayOrderCount ( ) {
Date jdkDate = DateUtil . offsetDay ( new Date ( ) , - 1 ) . toJdkDate ( ) ;
QueryWrapper < ProductOrder > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . in ( "status ", "1" , "2" , "4" , "5 " ) ;
queryWrapper . eq ( "is_pay ", "1" ) ;
queryWrapper . apply ( "cast(create_time as date) = cast({0} as date)" , jdkDate ) ;
return baseMapper . selectCount ( queryWrapper ) ;
}
@ -815,7 +817,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
Date jdkDate = DateUtil . offsetDay ( new Date ( ) , - 1 ) . toJdkDate ( ) ;
QueryWrapper < ProductOrderPrice > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . select ( " sum(pay_price ) as pay_price" ) ;
queryWrapper . apply ( " order_id in ( select po.id from product_order po where po.status in ('1', '2', '4', '5', '6') and cast(po.create_time as date) = cast({0} as date) and po.del_flag = '0')" , jdkDate ) ;
queryWrapper . apply ( " order_id in ( select po.id from product_order po where po.is_pay = '1' and cast(po.create_time as date) = cast({0} as date) and po.del_flag = '0')" , jdkDate ) ;
ProductOrderPrice productOrder = productOrderPriceMapper . selectOne ( queryWrapper ) ;
return productOrder = = null ? BigDecimal . ZERO : productOrder . getPayPrice ( ) ;
}
@ -824,7 +826,7 @@ public class ProductOrderServiceImpl implements IProductOrderService {
public BigDecimal getTotalAmount ( ) {
QueryWrapper < ProductOrderPrice > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . select ( " sum(pay_price ) as pay_price" ) ;
queryWrapper . apply ( " order_id in( select po.id from product_order po where po.status in ('1', '2', '4', '5') ) " ) ;
queryWrapper . apply ( " order_id in( select po.id from product_order po where po.is_pay = '1' ) " ) ;
ProductOrderPrice productOrder = productOrderPriceMapper . selectOne ( queryWrapper ) ;
return productOrder = = null ? BigDecimal . ZERO : productOrder . getPayPrice ( ) ;
}
@ -888,17 +890,27 @@ public class ProductOrderServiceImpl implements IProductOrderService {
updateWrapper . set ( ProductOrder : : getStatus , status ) ;
ProductOrderVo productOrderVo = baseMapper . selectVoById ( id ) ;
if ( status . equals ( "4" ) ) {
updateWrapper . set ( ProductOrder : : getFinishDate , new Date ( ) ) ;
updateWrapper . set ( ProductOrder : : getSettlement , 1L ) ;
updateWrapper . eq ( ProductOrder : : getSettlement , 0L ) ;
ProductOrderPriceVo productOrderPriceVo = productOrderPriceMapper . selectVoById ( id ) ;
BigDecimal settlementCurrentPrice = productOrderPriceVo . getSettlementCurrentPrice ( ) ;
if ( productOrderVo . getSettlement ( ) = = 0L ) {
sysBusinessBalanceService . addFrozenBalance ( settlementCurrentPrice , productOrderVo . getBusinessId ( ) ,
"订单结算" , id , "order" ) ;
//订单抽成
sysBalanceRecordService . insertByBo ( new SysBalanceRecordBo ( productOrderVo . getBusinessId ( ) , "order" , productOrderPriceVo . getServicePrice ( ) , productOrderVo . getOrderNo ( ) ) ) ;
LambdaUpdateWrapper < ProductOrder > finshUW = new LambdaUpdateWrapper < > ( ) ;
finshUW . eq ( ProductOrder : : getId , id ) ;
finshUW . eq ( ProductOrder : : getSettlement , 0L ) ;
finshUW . set ( ProductOrder : : getFinishDate , new Date ( ) ) ;
finshUW . set ( ProductOrder : : getSettlement , 1L ) ;
int update = baseMapper . update ( finshUW ) ;
if ( update > 0 ) {
ProductOrderPriceVo productOrderPriceVo = productOrderPriceMapper . selectVoById ( id ) ;
BigDecimal settlementCurrentPrice = productOrderPriceVo . getSettlementCurrentPrice ( ) ;
if ( productOrderVo . getSettlement ( ) = = 0L ) {
sysBusinessBalanceService . addFrozenBalance ( settlementCurrentPrice , productOrderVo . getBusinessId ( ) ,
"订单结算" , id , "order" ) ;
//订单抽成
sysBalanceRecordService . insertByBo ( new SysBalanceRecordBo ( productOrderVo . getBusinessId ( ) , "order" , productOrderPriceVo . getServicePrice ( ) , productOrderVo . getOrderNo ( ) ) ) ;
}
}
} else if ( status . equals ( "11" ) ) {
updateWrapper . set ( ProductOrder : : getFailRefundTime , new Date ( ) ) ;
} else if ( status . equals ( "9" ) ) {
//不允许退款
updateWrapper . set ( ProductOrder : : getCanRefund , "1" ) ;
}
baseMapper . update ( updateWrapper ) ;
@ -944,18 +956,21 @@ public class ProductOrderServiceImpl implements IProductOrderService {
lqw . eq ( "sb.del_flag" , "0" ) ;
List < ProductOrderVo > productOrderVos = baseMapper . selectSettlementList ( lqw ) ;
productOrderVos . forEach ( productOrderVo - > {
log . info ( "结算订单号:{}" , productOrderVo . getId ( ) ) ;
ProductOrderPriceVo productOrderPriceVo = productOrderPriceService . queryById ( productOrderVo . getId ( ) ) ;
BigDecimal settlementCurrentPrice = productOrderPriceVo . getSettlementCurrentPrice ( ) ;
log . info ( "结算金额:{}" , settlementCurrentPrice ) ;
sysBusinessBalanceService . addBalance ( settlementCurrentPrice , productOrderVo . getBusinessId ( ) ,
"冻结转入余额" , productOrderVo . getId ( ) , "order" ) ;
sysBusinessBalanceService . subFrozenBalance ( settlementCurrentPrice , productOrderVo . getBusinessId ( ) ,
"结算扣除冻结金额" , productOrderVo . getId ( ) , "order" ) ;
LambdaUpdateWrapper < ProductOrder > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
updateWrapper . eq ( ProductOrder : : getId , productOrderVo . getId ( ) ) ;
updateWrapper . set ( ProductOrder : : getSettlement , 2L ) ;
updateWrapper . set ( ProductOrder : : getSettlementTime , new Date ( ) ) ;
baseMapper . update ( updateWrapper ) ;
if ( productOrderPriceVo ! = null ) {
BigDecimal settlementCurrentPrice = productOrderPriceVo . getSettlementCurrentPrice ( ) ;
log . info ( "结算金额:{}" , settlementCurrentPrice ) ;
sysBusinessBalanceService . addBalance ( settlementCurrentPrice , productOrderVo . getBusinessId ( ) ,
"冻结转入余额" , productOrderVo . getId ( ) , "order" ) ;
sysBusinessBalanceService . subFrozenBalance ( settlementCurrentPrice , productOrderVo . getBusinessId ( ) ,
"结算扣除冻结金额" , productOrderVo . getId ( ) , "order" ) ;
LambdaUpdateWrapper < ProductOrder > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
updateWrapper . eq ( ProductOrder : : getId , productOrderVo . getId ( ) ) ;
updateWrapper . set ( ProductOrder : : getSettlement , 2L ) ;
updateWrapper . set ( ProductOrder : : getSettlementTime , new Date ( ) ) ;
baseMapper . update ( updateWrapper ) ;
}
} ) ;
}
@ -1043,6 +1058,42 @@ public class ProductOrderServiceImpl implements IProductOrderService {
return wxPayOrderQueryResult ;
}
@Override
public void updateBusinessRemarkByOrderId ( String recordMsg , Long id ) {
LambdaUpdateWrapper < ProductOrder > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
updateWrapper . eq ( ProductOrder : : getId , id ) ;
updateWrapper . set ( ProductOrder : : getBusinessRefund , recordMsg ) ;
baseMapper . update ( updateWrapper ) ;
}
@Override
public void updateCanRefundRemarkByOrderId ( String canRefund , Long id ) {
LambdaUpdateWrapper < ProductOrder > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
updateWrapper . eq ( ProductOrder : : getId , id ) ;
updateWrapper . set ( ProductOrder : : getCanRefund , canRefund ) ;
baseMapper . update ( updateWrapper ) ;
}
@Override
@Transactional
public void refundFailToFinish ( ) {
QueryWrapper < ProductOrder > lqw = new QueryWrapper < > ( ) ;
//待结算
// lqw.in(ProductOrder::getStatus, "4", "5");
//完成时间小于设定时间
lqw . lt ( "fail_refund_time" , DateUtil . offsetDay ( new Date ( ) , - 2 ) . toJdkDate ( ) ) ;
lqw . eq ( "is_pay" , "1" ) ;
lqw . eq ( "status" , "11" ) ;
List < ProductOrderVo > productOrderVos = baseMapper . selectVoList ( lqw ) ;
for ( ProductOrderVo productOrderVo : productOrderVos ) {
updateStatusByOrderId ( "4" , productOrderVo . getId ( ) ) ;
updateCanRefundRemarkByOrderId ( "1" , productOrderVo . getId ( ) ) ;
}
}
private ProductOrderVo insertOrderByVo ( ProductOrderVo vo ) {
Set < String > names = new HashSet < > ( ) ;