@ -9,19 +9,19 @@ import com.hfkj.common.pay.util.SignatureUtil;
import com.hfkj.common.utils.DateUtil ;
import com.hfkj.common.utils.ResponseMsgUtil ;
import com.hfkj.entity.* ;
import com.hfkj.model.DiscountUserModel ;
import com.hfkj.model.ResponseData ;
import com.hfkj.openapi.model.request.RequestPushDiscountModel ;
import com.hfkj.openapi.model.request.RequestPushPkDiscountModel ;
import com.hfkj.openapi.model.request.RequestQueryCodeModel ;
import com.hfkj.openapi.model.request.RequestQueryDiscountListModel ;
import com.hfkj.openapi.model.response.ResponsePushDiscountModel ;
import com.hfkj.openapi.model.response.ResponsePushDiscountPkModel ;
import com.hfkj.openapi.model.response.ResponseQueryCodeModel ;
import com.hfkj.openapi.model.UserDiscountModel ;
import com.hfkj.openapi.model.request.* ;
import com.hfkj.openapi.model.response.* ;
import com.hfkj.service.agent.BsAgentApiLogService ;
import com.hfkj.service.agent.BsAgentApiParamService ;
import com.hfkj.service.agent.BsAgentDiscountService ;
import com.hfkj.service.discount.BsDiscountPkRelService ;
import com.hfkj.service.discount.BsDiscountPkService ;
import com.hfkj.service.discount.BsDiscountService ;
import com.hfkj.service.discount.BsDiscountUserService ;
import com.hfkj.sysenum.discount.DiscountPkStatusEnum ;
import com.hfkj.sysenum.discount.DiscountStockCodeObtainTypeEnum ;
import io.swagger.annotations.Api ;
import io.swagger.annotations.ApiOperation ;
@ -32,10 +32,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.* ;
import javax.annotation.Resource ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
@Controller
@RequestMapping ( value = "/discount" )
@ -47,6 +44,10 @@ public class BsDiscountController {
@Resource
private BsAgentDiscountService agentDiscountService ;
@Resource
private BsDiscountPkService discountPkService ;
@Resource
private BsDiscountPkRelService discountPkRelService ;
@Resource
private BsAgentApiLogService agentApiLogService ;
@Resource
private BsDiscountUserService discountUserService ;
@ -121,6 +122,82 @@ public class BsDiscountController {
}
}
@RequestMapping ( value = "/queryPkDetail" , method = RequestMethod . POST )
@ResponseBody
@ApiOperation ( value = "查询优惠券包详情" )
public ResponseData queryPkDetail ( @Validated @RequestBody RequestQueryPkDiscountModel body ) {
log . info ( "========= Start 查询优惠券详情 Start ===========" ) ;
log . info ( "请求参数:" + JSONObject . toJSONString ( body ) ) ;
BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs ( ) ;
try {
// 验证签名
BsAgentApiParam apiParam = agentApiParamService . getParamByAppId ( body . getAppId ( ) ) ;
if ( ! SignatureUtil . checkSign ( body . getSign ( ) , body , apiParam . getAppSecret ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_SIGN_ERR , "" ) ;
}
// 验证请求id
if ( agentApiLogService . isExist ( body . getAppId ( ) , body . getReqId ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_REQ_ID_ERR , "" ) ;
}
apiLog . setAppId ( body . getAppId ( ) ) ;
apiLog . setRequestId ( body . getReqId ( ) ) ;
apiLog . setRequestUrl ( "discount/queryPkDetail" ) ;
apiLog . setRequestParam ( JSONObject . toJSONString ( body ) ) ;
// 查询代理商是否拥有优惠券包权限
if ( agentDiscountService . getDetail ( apiParam . getAgentId ( ) , 2 , body . getDiscountPkNo ( ) ) = = null ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_COMMON , "未配置优惠券包" ) ;
}
// 查询优惠券包
BsDiscountPk discountPk = discountPkService . getDetail ( body . getDiscountPkNo ( ) ) ;
if ( discountPk = = null ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_COMMON , "未找到优惠券包" ) ;
}
if ( ! discountPk . getStatus ( ) . equals ( DiscountPkStatusEnum . status2 . getCode ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_COMMON , "未找到优惠券包" ) ;
}
ResponseQueryPkDiscountModel response = new ResponseQueryPkDiscountModel ( ) ;
response . setAppId ( body . getAppId ( ) ) ;
response . setReqId ( body . getReqId ( ) ) ;
response . setDiscountPkNo ( discountPk . getDiscountPkNo ( ) ) ;
response . setDiscountPkName ( discountPk . getDiscountPkName ( ) ) ;
response . setDiscountList ( new LinkedList < > ( ) ) ;
// 券包中的优惠券列表
List < BsDiscountPkRel > discountPkRelList = discountPkRelService . getList ( body . getDiscountPkNo ( ) ) ;
for ( BsDiscountPkRel discount : discountPkRelList ) {
JSONObject discountObj = new JSONObject ( ) ;
discountObj . put ( "number" , discount . getNumber ( ) ) ;
discountObj . put ( "discountNo" , discount . getDiscountNo ( ) ) ;
discountObj . put ( "discountName" , discount . getDiscountName ( ) ) ;
discountObj . put ( "discountType" , discount . getDiscountType ( ) ) ;
discountObj . put ( "discountCondition" , discount . getDiscountCondition ( ) ) ;
discountObj . put ( "discountPrice" , discount . getDiscountPrice ( ) ) ;
discountObj . put ( "useScope" , discount . getUseScope ( ) ) ;
discountObj . put ( "receiveExpirationDate" , discount . getReceiveExpirationDate ( ) ) ;
response . getDiscountList ( ) . add ( discountObj ) ;
}
response . setSign ( SignatureUtil . createSign ( response , agentApiParamService . getParamByAppId ( body . getAppId ( ) ) . getAppSecret ( ) ) ) ;
log . info ( "返回参数:" + JSONObject . toJSONString ( response ) ) ;
apiLog . setResponseParam ( JSONObject . toJSONString ( response ) ) ;
return ResponseMsgUtil . success ( response ) ;
} catch ( Exception e ) {
log . info ( "出现异常:" , e ) ;
// 异常内容
ResponseData exception = ResponseMsgUtil . exception ( e ) ;
apiLog . setErrorContent ( JSONObject . toJSONString ( exception ) ) ;
return exception ;
} finally {
// 记录日志
if ( apiLog . getAppId ( ) ! = null ) {
agentApiLogService . edit ( apiLog ) ;
}
log . info ( "========= END 查询优惠券详情 END ===========" ) ;
}
}
@RequestMapping ( value = "/pushPk" , method = RequestMethod . POST )
@ResponseBody
@ApiOperation ( value = "推送优惠券包" )
@ -250,5 +327,70 @@ public class BsDiscountController {
}
}
@RequestMapping ( value = "/queryListByPhone" , method = RequestMethod . POST )
@ResponseBody
@ApiOperation ( value = "根据手机号查询优惠券列表" )
public ResponseData queryListByPhone ( @Validated @RequestBody RequestQueryListByPhoneModel body ) {
log . info ( "========= Start 根据手机号查询优惠券列表 Start ===========" ) ;
log . info ( "请求参数:" + JSONObject . toJSONString ( body ) ) ;
BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs ( ) ;
try {
// 验证签名
BsAgentApiParam apiParam = agentApiParamService . getParamByAppId ( body . getAppId ( ) ) ;
if ( ! SignatureUtil . checkSign ( body . getSign ( ) , body , apiParam . getAppSecret ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_SIGN_ERR , "" ) ;
}
// 验证请求id
if ( agentApiLogService . isExist ( body . getAppId ( ) , body . getReqId ( ) ) ) {
throw ErrorHelp . genException ( SysCode . OpenApi , ErrorCode . OPEN_API_REQ_ID_ERR , "" ) ;
}
apiLog . setAppId ( body . getAppId ( ) ) ;
apiLog . setRequestId ( body . getReqId ( ) ) ;
apiLog . setRequestUrl ( "discount/queryListByPhone" ) ;
apiLog . setRequestParam ( JSONObject . toJSONString ( body ) ) ;
Map < String , Object > param = new HashMap < > ( ) ;
param . put ( "userPhone" , body . getPhone ( ) ) ;
param . put ( "status" , body . getStatus ( ) ) ;
List < DiscountUserModel > userDiscountList = discountUserService . getUserDiscountList ( param ) ;
ResponseUserDiscountModel response = new ResponseUserDiscountModel ( ) ;
response . setReqId ( body . getReqId ( ) ) ;
response . setUserPhone ( body . getPhone ( ) ) ;
response . setDataList ( new LinkedList < > ( ) ) ;
for ( DiscountUserModel model : userDiscountList ) {
UserDiscountModel userDiscount = new UserDiscountModel ( ) ;
userDiscount . setDiscountNo ( model . getDiscountNo ( ) ) ;
userDiscount . setDiscountName ( model . getDiscountName ( ) ) ;
userDiscount . setDiscountType ( model . getDiscountType ( ) ) ;
userDiscount . setDiscountCondition ( model . getDiscountCondition ( ) ) ;
userDiscount . setDiscountPrice ( model . getDiscountPrice ( ) ) ;
userDiscount . setCode ( model . getDiscountStockCode ( ) ) ;
userDiscount . setCreateTime ( model . getCreateTime ( ) ) ;
userDiscount . setUseTime ( model . getUseDate ( ) ) ;
userDiscount . setExpirationTime ( model . getExpirationDate ( ) ) ;
userDiscount . setStatus ( model . getStatus ( ) ) ;
response . getDataList ( ) . add ( userDiscount ) ;
}
response . setSign ( SignatureUtil . createSign ( response , agentApiParamService . getParamByAppId ( body . getAppId ( ) ) . getAppSecret ( ) ) ) ;
log . info ( "返回参数:" + JSONObject . toJSONString ( response ) ) ;
apiLog . setResponseParam ( JSONObject . toJSONString ( response ) ) ;
return ResponseMsgUtil . success ( response ) ;
} catch ( Exception e ) {
log . info ( "出现异常:" , e ) ;
// 异常内容
ResponseData exception = ResponseMsgUtil . exception ( e ) ;
apiLog . setErrorContent ( JSONObject . toJSONString ( exception ) ) ;
return exception ;
} finally {
// 记录日志
if ( apiLog . getAppId ( ) ! = null ) {
agentApiLogService . edit ( apiLog ) ;
}
log . info ( "========= END 根据手机号查询优惠券列表 END ===========" ) ;
}
}
}