Authored by wujiexiang

券 增加用户类型过滤

... ... @@ -27,10 +27,10 @@ public interface UserCouponMapper {
int updateCoupon2Invalidate(@Param("uid") Integer id, @Param("couponCode") String couponCode);
List<UserCoupon> selectByUidAndCouponCodes(@Param("uid") Integer uid, @Param("couponCodes") List<String> couponCode);
List<UserCoupon> selectByUidAndCouponCodes(@Param("uid") Integer uid, @Param("userType") Integer userType, @Param("couponCodes") List<String> couponCode);
List<UserCoupon> selectUsableCouponByUid(@Param("uid") Integer uid, @Param("now") int now);
List<UserCoupon> selectUsableCouponByUid(@Param("uid") Integer uid, @Param("userType") Integer userType, @Param("now") int now);
int selectCntUsableCouponByUid(@Param("uid") Integer uid, @Param("now") int now,
@Param("businessClient") String businessClient);
... ...
... ... @@ -6,6 +6,8 @@ public class CouponUseDO {
private int uid;
private int userType;
private List<String> couponCodes;
private long orderCode;
... ... @@ -14,6 +16,7 @@ public class CouponUseDO {
private CouponUseDO(Builder builder) {
setUid(builder.uid);
setUserType(builder.userType);
setCouponCodes(builder.couponCodes);
setOrderCode(builder.orderCode);
setUseTime(builder.useTime);
... ... @@ -31,6 +34,14 @@ public class CouponUseDO {
this.uid = uid;
}
public int getUserType() {
return userType;
}
public void setUserType(int userType) {
this.userType = userType;
}
public List<String> getCouponCodes() {
return couponCodes;
}
... ... @@ -58,6 +69,7 @@ public class CouponUseDO {
public static final class Builder {
private int uid;
private int userType;
private List<String> couponCodes;
private long orderCode;
private int useTime;
... ... @@ -70,6 +82,10 @@ public class CouponUseDO {
return this;
}
public Builder userType(int val) {
userType = val;
return this;
}
public Builder couponCodes(List<String> val) {
couponCodes = val;
return this;
... ...
... ... @@ -40,6 +40,9 @@
<include refid="Base_Column_List"/>
from user_coupon
where uid = #{uid}
<if test="userType != null">
and user_type = #{userType,jdbcType=INTEGER}
</if>
AND coupon_code IN
<foreach collection="couponCodes" item="couponCode" open="(" separator="," close=")">
#{couponCode,jdbcType=VARCHAR}
... ... @@ -63,6 +66,9 @@
<include refid="Base_Column_List" />
from user_coupon
where uid = #{uid,jdbcType=INTEGER}
<if test="userType != null">
and user_type = #{userType,jdbcType=INTEGER}
</if>
<include refid="CouponsLogsQueryUsable" />
order by end_time
</select>
... ... @@ -192,6 +198,9 @@
status=1
</set>
where uid= #{uid}
<if test="userType != null">
and user_type= #{userType,jdbcType=INTEGER}
</if>
and coupon_code in
<foreach collection="couponCodes" index="index" item="couponCode"
open="(" separator="," close=")">
... ...
... ... @@ -40,12 +40,13 @@ public class OrderCouponController {
@RequestMapping(params = "method=ufo.coupons.use")
@ResponseBody
public ApiResponse useCoupon(@RequestParam(value = "uid") Integer uid,
@RequestParam(value = "userType", defaultValue = "1") int userType,
@RequestParam(value = "orderCode") long orderCode,
@RequestParam(value = "couponCodes") List<String> couponCodes) {
logger.info("use coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode);
boolean useSuccess = couponService.useCoupon(uid, couponCodes, orderCode);
logger.info("use coupons, uid: {},couponCodes: {}, orderCode :{},result: {}", uid, couponCodes, orderCode, useSuccess);
logger.info("use coupons, uid: {},userType:{}, couponCodes: {}, orderCode :{}", uid, userType, couponCodes, orderCode);
boolean useSuccess = couponService.useCoupon(uid, userType, couponCodes, orderCode);
logger.info("use coupons, uid: {},userType:{}, couponCodes: {}, orderCode :{},result: {}", uid, userType, couponCodes, orderCode, useSuccess);
return new ApiResponse.ApiResponseBuilder().code(200).data(useSuccess).build();
}
... ... @@ -73,14 +74,16 @@ public class OrderCouponController {
/**
* 优惠券列表(订单使用)
* @param uid
* @param userType 1 买家 2 卖家
* @return
*/
@RequestMapping(params = "method=ufo.coupons.listNoUsed")
@ResponseBody
public ApiResponse queryUserNoUsedCoupons(@RequestParam(value = "uid") Integer uid) {
public ApiResponse queryUserNoUsedCoupons(@RequestParam(value = "uid") Integer uid,
@RequestParam(value = "userType",defaultValue = "1") Integer userType) {
logger.info("use coupons, uid: {}", uid);
UserCouponsListBo couponBoList = couponService.queryUserNoUsedCoupons(uid);
UserCouponsListBo couponBoList = couponService.queryUserNoUsedCoupons(uid, userType);
logger.info("use coupons, uid: {}, success", uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(couponBoList).build();
}
... ...
... ... @@ -70,11 +70,12 @@ public interface ICouponService {
* 使用优惠券
*
* @param uid
* @param userType
* @param couponCodes
* @param orderCode
* @return
*/
boolean useCoupon(Integer uid, List<String> couponCodes, long orderCode);
boolean useCoupon(Integer uid, int userType, List<String> couponCodes, long orderCode);
/**
* 退还优惠券
... ... @@ -98,9 +99,10 @@ public interface ICouponService {
* 获取优惠券列表(订单)
*
* @param uid
* @param userType
* @return
*/
UserCouponsListBo queryUserNoUsedCoupons(Integer uid);
UserCouponsListBo queryUserNoUsedCoupons(Integer uid, Integer userType);
/**
* 校验券并返回券信息
... ...
... ... @@ -275,21 +275,22 @@ public class CouponServiceImpl implements ICouponService {
}
@Override
public boolean useCoupon(Integer uid, List<String> couponCodes, long orderCode) {
public boolean useCoupon(Integer uid, int userType, List<String> couponCodes, long orderCode) {
if (uid == null || uid.intValue() <= 0
if (uid == null || uid.intValue() <= 0 || userType <= 0
|| CollectionUtils.isEmpty(couponCodes)
|| orderCode < 0) {
logger.warn("useCoupon param invalidate");
throw new ServiceException(ServiceError.PROMOTION_REQUEST_PAREMENT_ERROR);
}
if (checkUserCoupon(uid, couponCodes, orderCode)) {
if (checkUserCoupon(uid, userType, couponCodes, orderCode)) {
return false;
}
CouponUseDO couponUseDO = CouponUseDO.newBuilder()
.uid(uid)
.userType(userType)
.orderCode(orderCode)
.useTime(DateUtil.getCurrentTimeSecond())
.couponCodes(couponCodes)
... ... @@ -335,8 +336,8 @@ public class CouponServiceImpl implements ICouponService {
userCouponMapper.updateCoupon2Invalidate(uid, couponCode);
}
private boolean checkUserCoupon(Integer uid, List<String> couponCodes, long orderCode) {
List<UserCoupon> userCoupons = userCouponMapper.selectByUidAndCouponCodes(uid, couponCodes);
private boolean checkUserCoupon(Integer uid, Integer userType, List<String> couponCodes, long orderCode) {
List<UserCoupon> userCoupons = userCouponMapper.selectByUidAndCouponCodes(uid, userType, couponCodes);
if (CollectionUtils.isEmpty(userCoupons) || userCoupons.size() != couponCodes.size()) {
logger.warn("user {},{} coupon not enough {},{} ", uid, orderCode, couponCodes.size(), userCoupons.size());
return true;
... ... @@ -389,10 +390,12 @@ public class CouponServiceImpl implements ICouponService {
/**
*
* @param uid
* @param userType
* @return
*/
public UserCouponsListBo queryUserNoUsedCoupons(Integer uid) {
public UserCouponsListBo queryUserNoUsedCoupons(Integer uid, Integer userType) {
if (uid == null || uid <= 0) {
logger.warn("query coupon list param invalidate");
... ...