@ -1,11 +1,13 @@
package com.hai.service.impl ;
import com.alibaba.fastjson.JSONObject ;
import com.hai.common.QRCodeGenerator ;
import com.hai.common.exception.ErrorCode ;
import com.hai.common.exception.ErrorHelp ;
import com.hai.common.exception.SysCode ;
import com.hai.common.utils.DateUtil ;
import com.hai.common.utils.IDGenerator ;
import com.hai.config.HuiLianTongConfig ;
import com.hai.dao.* ;
import com.hai.entity.* ;
import com.hai.model.HighCouponHandselModel ;
@ -49,6 +51,9 @@ public class HighOrderServiceImpl implements HighOrderService {
@Resource
private HighCouponService highCouponService ;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper ;
@Resource
private HighCouponHandselService highCouponHandselService ;
@ -91,18 +96,20 @@ public class HighOrderServiceImpl implements HighOrderService {
// 商品类型 1:卡卷
if ( childOrder . getGoodsType ( ) = = 1 ) {
// 查询待销售
List < HighCouponCode > list = highCouponCodeService . getNoSaleCode ( childOrder . getGoodsId ( ) ) ;
if ( list = = null | | list . size ( ) = = 0 ) {
throw ErrorHelp . genException ( SysCode . System , ErrorCode . COUPON_STOCK_INSUFFICIENT , "" ) ;
// 查询卡券
HighCoupon couponDetail = highCouponService . getCouponDetail ( childOrder . getGoodsId ( ) ) ;
if ( couponDetail . getCouponSource ( ) ! = 4 ) {
// 查询待销售
List < HighCouponCode > list = highCouponCodeService . getNoSaleCode ( childOrder . getGoodsId ( ) ) ;
if ( list = = null | | list . size ( ) = = 0 ) {
throw ErrorHelp . genException ( SysCode . System , ErrorCode . COUPON_STOCK_INSUFFICIENT , "" ) ;
}
list . get ( 0 ) . setChildOrderId ( childOrder . getId ( ) ) ;
list . get ( 0 ) . setStatus ( 99 ) ; // 状态:1.待销售 2.未使用 3.已使用 99.预支付
highCouponCodeService . updateCouponCode ( list . get ( 0 ) ) ;
childOrder . setExt1 ( list . get ( 0 ) . getExt1 ( ) ) ;
highChildOrderMapper . updateByPrimaryKey ( childOrder ) ;
}
list . get ( 0 ) . setChildOrderId ( childOrder . getId ( ) ) ;
list . get ( 0 ) . setStatus ( 99 ) ; // 状态:1.待销售 2.未使用 3.已使用 99.预支付
highCouponCodeService . updateCouponCode ( list . get ( 0 ) ) ;
childOrder . setExt1 ( list . get ( 0 ) . getExt1 ( ) ) ;
highChildOrderMapper . updateByPrimaryKey ( childOrder ) ;
if ( ! childOrder . getGiveawayType ( ) ) {
// 查看是否需要赠送卡卷
List < HighCouponHandselModel > handselListByCoupon = highCouponHandselService . getHandselListByCoupon ( childOrder . getGoodsId ( ) ) ;
@ -146,12 +153,15 @@ public class HighOrderServiceImpl implements HighOrderService {
@Override
@Transactional ( propagation = Propagation . REQUIRES_NEW )
public void goldPayOrder ( Long userId , Long orderId ) {
public void goldPayOrder ( Long userId , Long orderId ) throws Exception {
HighOrder highOrder = getOrderById ( orderId ) ;
if ( highOrder = = null ) {
throw ErrorHelp . genException ( SysCode . System , ErrorCode . NOT_FOUND_ORDER , "" ) ;
}
// 查询用户
HighUser highUser = highUserService . findByUserId ( highOrder . getMemId ( ) ) ;
// 金币 1:100
Integer goldNum = new BigDecimal ( highOrder . getTotalPrice ( ) . toString ( ) ) . multiply ( new BigDecimal ( "100" ) ) . intValue ( ) ;
highUserService . goldHandle ( userId , goldNum , 2 , 2 , highOrder . getId ( ) ) ;
@ -167,37 +177,63 @@ public class HighOrderServiceImpl implements HighOrderService {
// 商品类型 商品类型 1:卡卷 2:金币充值
if ( highChildOrder . getGoodsType ( ) = = 1 ) {
HighCouponCode code = highCouponCodeService . getCouponCodeByOrderId ( highChildOrder . getId ( ) ) ;
code . setStatus ( 2 ) ; // 状态:1.待销售 2.未使用 3.已使用 99.预支付
code . setReceiveTime ( new Date ( ) ) ;
highCouponCodeService . updateCouponCode ( code ) ;
HighCoupon coupon = highCouponService . getCouponById ( highChildOrder . getGoodsId ( ) ) ;
// 卡卷关联用户
HighUserCoupon highUserCoupon = new HighUserCoupon ( ) ;
highUserCoupon . setMerchantId ( code . getMerchantId ( ) ) ;
highUserCoupon . setCouponId ( code . getCouponId ( ) ) ;
highUserCoupon . setUserId ( highOrder . getMemId ( ) ) ;
highUserCoupon . setCouponCodeId ( code . getId ( ) ) ;
highUserCoupon . setCreateTime ( new Dat e( ) ) ;
highUserCoupon . setQrCodeImg ( code . getExt1 ( ) ) ;
// 计算使用有效期
Calendar userEndTime = Calendar . getInstance ( ) ;
userEndTime . setTime ( new Date ( ) ) ;
userEndTime . set ( Calendar . HOUR_OF_DAY , 23 ) ;
userEndTime . set ( Calendar . MINUTE , 59 ) ;
userEndTime . set ( Calendar . SECOND , 59 ) ;
userEndTime . add ( Calendar . DATE , coupon . getRecycleDay ( ) ) ;
if ( userEndTime . getTime ( ) . compareTo ( code . getUseEndTime ( ) ) = = 1 ) {
highUserCoupon . setUseEndTime ( code . getUseEndTime ( ) ) ;
// 查询卡券
HighCoupon coupon = highCouponService . getCouponDetail ( highChildOrder . getGoodsId ( ) ) ;
// 贵州高速
if ( coupon . getCouponSource ( ) = = 4 ) {
// 获取token
JSONObject tokenObject = HuiLianTongConfig . getToken ( ) ;
if ( ! tokenObject . getString ( "result" ) . equals ( "success" ) ) {
throw ErrorHelp . genException ( SysCode . System , ErrorCode . COMMON_ERROR , "获取token失败" ) ;
}
Map < String , Object > push = new HashMap < > ( ) ;
push . put ( "token" , "data" ) ;
push . put ( "couTypeCode" , coupon . getCouponKey ( ) ) ;
push . put ( "distCouCount" , highChildOrder . getSaleCount ( ) ) ;
push . put ( "userPhone" , highUser . getPhon e ( ) ) ;
push . put ( "thirdUserId" , highUser . getUnionId ( ) ) ;
// 推送给高速
JSONObject returnParam = HuiLianTongConfig . couJointDist ( tokenObject . getString ( "data" ) , coupon . getCouponKey ( ) , highChildOrder . getSaleCount ( ) , highUser . getPhone ( ) , highUser . getUnionId ( ) ) ;
// 推送记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush ( ) ;
highGasOrderPush . setCreateTime ( new Date ( ) ) ;
highGasOrderPush . setCode ( returnParam . getString ( "result" ) ) ;
highGasOrderPush . setRequestContent ( JSONObject . toJSONString ( push ) ) ;
highGasOrderPush . setReturnContent ( returnParam . toJSONString ( ) ) ;
highGasOrderPushMapper . insert ( highGasOrderPush ) ;
} else {
highUserCoupon . setUseEndTime ( userEndTime . getTime ( ) ) ;
HighCouponCode code = highCouponCodeService . getCouponCodeByOrderId ( highChildOrder . getId ( ) ) ;
code . setStatus ( 2 ) ; // 状态:1.待销售 2.未使用 3.已使用 99.预支付
code . setReceiveTime ( new Date ( ) ) ;
highCouponCodeService . updateCouponCode ( code ) ;
// 卡卷关联用户
HighUserCoupon highUserCoupon = new HighUserCoupon ( ) ;
highUserCoupon . setMerchantId ( code . getMerchantId ( ) ) ;
highUserCoupon . setCouponId ( code . getCouponId ( ) ) ;
highUserCoupon . setUserId ( highOrder . getMemId ( ) ) ;
highUserCoupon . setCouponCodeId ( code . getId ( ) ) ;
highUserCoupon . setCreateTime ( new Date ( ) ) ;
highUserCoupon . setQrCodeImg ( code . getExt1 ( ) ) ;
// 计算使用有效期
Calendar userEndTime = Calendar . getInstance ( ) ;
userEndTime . setTime ( new Date ( ) ) ;
userEndTime . set ( Calendar . HOUR_OF_DAY , 23 ) ;
userEndTime . set ( Calendar . MINUTE , 59 ) ;
userEndTime . set ( Calendar . SECOND , 59 ) ;
userEndTime . add ( Calendar . DATE , coupon . getRecycleDay ( ) ) ;
if ( userEndTime . getTime ( ) . compareTo ( code . getUseEndTime ( ) ) = = 1 ) {
highUserCoupon . setUseEndTime ( code . getUseEndTime ( ) ) ;
} else {
highUserCoupon . setUseEndTime ( userEndTime . getTime ( ) ) ;
}
highUserCoupon . setStatus ( 1 ) ; // 状态 0:已过期 1:未使用 2:已使用
highUserCouponMapper . insert ( highUserCoupon ) ;
}
highUserCoupon . setStatus ( 1 ) ; // 状态 0:已过期 1:未使用 2:已使用
highUserCouponMapper . insert ( highUserCoupon ) ;
}
}