@ -26,6 +26,7 @@ import com.hfkj.service.agent.BsAgentApiParamService;
import com.hfkj.service.agent.BsAgentMerService ;
import com.hfkj.service.agent.BsAgentMerService ;
import com.hfkj.service.agent.BsAgentService ;
import com.hfkj.service.agent.BsAgentService ;
import com.hfkj.service.gas.BsGasClassGroupTaskService ;
import com.hfkj.service.gas.BsGasClassGroupTaskService ;
import com.hfkj.service.gas.BsGasOilPriceService ;
import com.hfkj.service.gas.BsGasOrderService ;
import com.hfkj.service.gas.BsGasOrderService ;
import com.hfkj.service.gas.BsGasService ;
import com.hfkj.service.gas.BsGasService ;
import com.hfkj.service.merchant.BsMerchantAccountService ;
import com.hfkj.service.merchant.BsMerchantAccountService ;
@ -75,8 +76,6 @@ public class ApiGasOrderService {
@Resource
@Resource
private BsGasService gasService ;
private BsGasService gasService ;
@Resource
@Resource
private BsOrderService orderService ;
@Resource
private BsGasOrderService gasOrderService ;
private BsGasOrderService gasOrderService ;
@Resource
@Resource
private BsGasClassGroupTaskService gasClassGroupTaskService ;
private BsGasClassGroupTaskService gasClassGroupTaskService ;
@ -88,9 +87,10 @@ public class ApiGasOrderService {
private BsAgentApiAccountService agentApiAccountService ;
private BsAgentApiAccountService agentApiAccountService ;
@Resource
@Resource
private BsAgentApiParamService agentApiParamService ;
private BsAgentApiParamService agentApiParamService ;
@Resource
@Resource
private BsOrderRefundService orderRefundService ;
private BsOrderRefundService orderRefundService ;
@Resource
private BsGasOilPriceService gasOilPriceService ;
/ * *
/ * *
* 推送加油订单
* 推送加油订单
* @param request
* @param request
@ -148,33 +148,41 @@ public class ApiGasOrderService {
gasOrder . setStatus ( OrderOilStatus . STATUS2 . getNumber ( ) ) ;
gasOrder . setStatus ( OrderOilStatus . STATUS2 . getNumber ( ) ) ;
gasOrder . setReceiptStatus ( GasOrderReceiptStatusEnum . status0 . getStatus ( ) ) ;
gasOrder . setReceiptStatus ( GasOrderReceiptStatusEnum . status0 . getStatus ( ) ) ;
// 结算信息
gasOrder . setTotalDeductionPrice ( new BigDecimal ( "0" ) ) ;
gasOrder . setDeductionCouponPrice ( new BigDecimal ( "0" ) ) ;
gasOrder . setDeductionOilPrice ( new BigDecimal ( "0" ) ) ;
gasOrder . setPayablePrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setPayablePrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setGasRefuelPrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setGasSettlePrice ( gasOrder . getGasRefuelPrice ( ) ) ;
gasOrder . setGasAgentSettlePrice ( gasOrder . getGasRefuelPrice ( ) ) ;
// 油价信息
// 油价信息
gasOrder . setGasRefuelPrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setGasRefuelPrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setGasOilNo ( request . getOilNo ( ) ) ;
gasOrder . setGasOilNo ( request . getOilNo ( ) ) ;
gasOrder . setGasGunNo ( request . getGunNo ( ) ) ;
gasOrder . setGasGunNo ( request . getGunNo ( ) ) ;
gasOrder . setGasOilType ( oilPrice . getOilType ( ) ) ;
gasOrder . setGasOilType ( oilPrice . getOilType ( ) ) ;
gasOrder . setGasPriceGun ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasPriceGun ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasPriceVip ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasPriceVip ( oilPrice . getPriceVip ( ) ) ;
gasOrder . setGasPriceCost ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasPriceCost ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasPriceOfficial ( oilPrice . getPriceOfficial ( ) ) ;
gasOrder . setGasPriceOfficial ( oilPrice . getPriceOfficial ( ) ) ;
gasOrder . setGasPricePlatform ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasPricePlatform ( oilPrice . getPriceGun ( ) ) ;
gasOrder . setGasOilLiters ( gasOrder . getGasSettlePrice ( ) . divide ( gasOrder . getGasPriceGun ( ) , 2 , BigDecimal . ROUND_HALF_UP ) ) ;
gasOrder . setGasDiscount ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasDiscount ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasOilSubsidy ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasOilSubsidy ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasLitersPreferences ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasLitersPreferences ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasPricePreferences ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasPricePreferences ( new BigDecimal ( "0" ) ) ;
gasOrder . setCreateType ( GasOrderCreateType . TYPE2 . getNumber ( ) ) ;
gasOrder . setCreateType ( GasOrderCreateType . TYPE2 . getNumber ( ) ) ;
gasOrder . setGasOilLiters ( gasOrder . getGasRefuelPrice ( ) . divide ( gasOrder . getGasPriceGun ( ) , 2 , BigDecimal . ROUND_HALF_UP ) ) ;
// 结算信息
gasOrder . setTotalDeductionPrice ( new BigDecimal ( "0" ) ) ;
gasOrder . setDeductionCouponPrice ( new BigDecimal ( "0" ) ) ;
gasOrder . setDeductionOilPrice ( new BigDecimal ( "0" ) ) ;
gasOrder . setPayablePrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setGasRefuelPrice ( request . getRefuelingAmount ( ) ) ;
gasOrder . setGasServiceFeeRate ( new BigDecimal ( "0" ) ) ;
gasOrder . setGasServiceFeePrice ( new BigDecimal ( "0" ) ) ;
if ( gasOrder . getChannelType ( ) . equals ( MerchantSourceTypeEnum . type1 . getNumber ( ) ) ) {
// 油站结算 公式 1. 加油升数 * (油枪价 - 优惠价) = 优惠金额 2. 加油金额 - 优惠金额 = 扣款金额
BigDecimal gasSettlePrice = gasOrder . getGasRefuelPrice ( ) . subtract (
// 优惠金额
gasOrder . getGasOilLiters ( ) . multiply ( oilPrice . getPriceGun ( ) . subtract ( oilPrice . getPriceVip ( ) ) ) ) ;
gasOrder . setGasSettlePrice ( gasSettlePrice ) ;
} else {
gasOrder . setGasSettlePrice ( gasOrder . getGasRefuelPrice ( ) ) ;
}
gasOrder . setGasAgentSettlePrice ( gasOrder . getGasRefuelPrice ( ) ) ;
// 油站是否开启班组
// 油站是否开启班组
BsGasClassGroupTask groupTask = gasClassGroupTaskService . getCurrentTaskByMerId ( gasDetail . getId ( ) ) ;
BsGasClassGroupTask groupTask = gasClassGroupTaskService . getCurrentTaskByMerId ( gasDetail . getId ( ) ) ;
if ( groupTask ! = null ) {
if ( groupTask ! = null ) {
@ -211,15 +219,18 @@ public class ApiGasOrderService {
* @throws Exception
* @throws Exception
* /
* /
@Transactional ( propagation = Propagation . REQUIRES_NEW , rollbackFor = { RuntimeException . class } )
@Transactional ( propagation = Propagation . REQUIRES_NEW , rollbackFor = { RuntimeException . class } )
public String refundOrder ( RequestOrderRefundModel request ) {
public String refundOrder ( Long agentId , RequestOrderRefundModel request ) {
// 查询加油订单
// 查询加油订单
BsGasOrder gasOrder = gasOrderService . getDetailByOrderNo ( request . getOrderNo ( ) ) ;
BsGasOrder gasOrder = gasOrderService . getDetailByOrderNo ( request . getOrderNo ( ) ) ;
if ( gasOrder = = null ) {
if ( gasOrder = = null ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "未找到订单号" ) ;
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "未找到订单" ) ;
}
if ( ! Objects . equals ( agentId , gasOrder . getAgentId ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "未找到订单" ) ;
}
}
if ( ! gasOrder . getStatus ( ) . equals ( OrderOilStatus . STATUS2 . getNumber ( ) )
if ( ! gasOrder . getStatus ( ) . equals ( OrderOilStatus . STATUS2 . getNumber ( ) )
| | gasOrder . getStatus ( ) . equals ( OrderOilStatus . STATUS6 . getNumber ( ) ) ) {
| | gasOrder . getStatus ( ) . equals ( OrderOilStatus . STATUS6 . getNumber ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "订单无法退款" ) ;
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "订单状态暂时 无法申请 退款" ) ;
}
}
// 创建退款订单
// 创建退款订单
BsOrderRefund orderRefund = new BsOrderRefund ( ) ;
BsOrderRefund orderRefund = new BsOrderRefund ( ) ;
@ -238,6 +249,10 @@ public class ApiGasOrderService {
orderRefund . setCreateType ( GasOrderCreateType . TYPE2 . getNumber ( ) ) ;
orderRefund . setCreateType ( GasOrderCreateType . TYPE2 . getNumber ( ) ) ;
orderRefundService . editData ( orderRefund ) ;
orderRefundService . editData ( orderRefund ) ;
// 修改订单状态
gasOrder . setStatus ( OrderOilStatus . STATUS5 . getNumber ( ) ) ;
gasOrderService . updateGasOrder ( gasOrder ) ;
ResponseOrderPushModel response = new ResponseOrderPushModel ( ) ;
ResponseOrderPushModel response = new ResponseOrderPushModel ( ) ;
response . setOrderNo ( gasOrder . getOrderNo ( ) ) ;
response . setOrderNo ( gasOrder . getOrderNo ( ) ) ;
response . setChannelType ( gasOrder . getChannelType ( ) ) ;
response . setChannelType ( gasOrder . getChannelType ( ) ) ;
@ -245,21 +260,43 @@ public class ApiGasOrderService {
// 创建一个单线程的线程池
// 创建一个单线程的线程池
ExecutorService singleThreadExecutor = Executors . newSingleThreadExecutor ( ) ;
ExecutorService singleThreadExecutor = Executors . newSingleThreadExecutor ( ) ;
// 异步记录登录信息
// 异步处理退款
singleThreadExecutor . submit ( new Runnable ( ) {
singleThreadExecutor . submit ( new Runnable ( ) {
@Override
@Override
public void run ( ) {
public void run ( ) {
if ( ! gasOrder . getChannelType ( ) . equals ( MerchantSourceTypeEnum . type2 . getNumber ( ) ) ) {
if ( gasOrder . getChannelType ( ) . equals ( MerchantSourceTypeEnum . type2 . getNumber ( ) ) ) {
// 团油
try {
// 请求团油渠道申请退款
JSONObject object = NewLinkRequestService . refuelingOrderRefund ( gasOrder . getUserPhone ( ) , gasOrder . getOrderNo ( ) , orderRefund . getRefundRemark ( ) ) ;
if ( object = = null | | ! object . getString ( "code" ) . equals ( "200" ) ) {
gasOrder . setAbnormal ( true ) ;
gasOrder . setAbnormalContent ( "渠道申请退款失败!原因:" + object . getString ( "message" ) ) ;
gasOrderService . updateGasOrder ( gasOrder ) ;
}
} catch ( Exception e ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "请求退款失败" ) ;
}
} else {
try {
try {
// 退款
// 退款
agentApiAccountService . refund ( gasOrder . getAgentId ( ) , gasOrder . getGasRefuelPrice ( ) , orderRefund ) ;
agentApiAccountService . refund ( gasOrder . getAgentId ( ) , gasOrder . getGasRefuelPrice ( ) , orderRefund ) ;
orderRefund . setRefundStatus ( OrderRefundStatusEnum . status2 . getCode ( ) ) ;
orderRefund . setRefundStatus ( OrderRefundStatusEnum . status2 . getCode ( ) ) ;
orderRefund . setFinishTime ( new Date ( ) ) ;
orderRefund . setFinishTime ( new Date ( ) ) ;
orderRefundService . editData ( orderRefund ) ;
orderRefundService . editData ( orderRefund ) ;
gasOrder . setStatus ( OrderOilStatus . STATUS4 . getNumber ( ) ) ;
gasOrder . setRefundTime ( orderRefund . getFinishTime ( ) ) ;
gasOrderService . updateGasOrder ( gasOrder ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
orderRefund . setRefundStatus ( OrderRefundStatusEnum . status3 . getCode ( ) ) ;
orderRefund . setRefundStatus ( OrderRefundStatusEnum . status3 . getCode ( ) ) ;
orderRefund . setRefundFailReason ( "退款失败!" ) ;
orderRefund . setRefundFailReason ( "退款失败!" ) ;
orderRefundService . editData ( orderRefund ) ;
orderRefundService . editData ( orderRefund ) ;
gasOrder . setStatus ( OrderOilStatus . STATUS6 . getNumber ( ) ) ;
gasOrder . setReceiptFailRemark ( orderRefund . getRefundFailReason ( ) ) ;
gasOrderService . updateGasOrder ( gasOrder ) ;
}
}
// 退款通知
// 退款通知
// 代理参数
// 代理参数
@ -273,7 +310,7 @@ public class ApiGasOrderService {
refundNotify . setRefundResult ( orderRefund . getRefundStatus ( ) = = 2 ? true : false ) ;
refundNotify . setRefundResult ( orderRefund . getRefundStatus ( ) = = 2 ? true : false ) ;
refundNotify . setRefundFailReason ( orderRefund . getRefundFailReason ( ) ) ;
refundNotify . setRefundFailReason ( orderRefund . getRefundFailReason ( ) ) ;
refundNotify . setSign ( SignatureUtil . createSign ( refundNotify , apiParam . getAppSecret ( ) ) ) ;
refundNotify . setSign ( SignatureUtil . createSign ( refundNotify , apiParam . getAppSecret ( ) ) ) ;
HttpsUtils . doPost ( apiParam . getOrderRefundNotify ( ) , JSONObject . toJSONString ( refundNotify ) ) ;
HttpsUtils . doPost ( apiParam . getOrderRefundNotify ( ) , JSONObject . parseObject ( JSONObject . toJSONString ( refundNotify ) , JSONObject . class ) ) ;
}
}
}
}
}
}
@ -287,11 +324,14 @@ public class ApiGasOrderService {
* @return
* @return
* @throws Exception
* @throws Exception
* /
* /
public ResponseOrderDetailModel queryOrderDetail ( RequestOrderDetailModel request ) throws Exception {
public ResponseOrderDetailModel queryOrderDetail ( Long agentId , RequestOrderDetailModel request ) {
// 查询加油订单
// 查询加油订单
BsGasOrder gasOrder = gasOrderService . getDetailByOrderNo ( request . getOrderNo ( ) ) ;
BsGasOrder gasOrder = gasOrderService . getDetailByOrderNo ( request . getOrderNo ( ) ) ;
if ( gasOrder = = null ) {
if ( gasOrder = = null ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "未找到订单号" ) ;
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "未找到订单" ) ;
}
if ( ! Objects . equals ( agentId , gasOrder . getAgentId ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . COMMON_ERROR , "未找到订单" ) ;
}
}
ResponseOrderDetailModel response = new ResponseOrderDetailModel ( ) ;
ResponseOrderDetailModel response = new ResponseOrderDetailModel ( ) ;
response . setOrderNo ( gasOrder . getOrderNo ( ) ) ;
response . setOrderNo ( gasOrder . getOrderNo ( ) ) ;