提交代码

dev-discount
胡锐 2 years ago
parent fba9e3334d
commit 93abb5496b
  1. 33
      hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java
  2. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  3. 25
      hai-service/src/main/java/com/hai/dao/HighCouponCodeOtherMapper.java
  4. 14
      hai-service/src/main/java/com/hai/dao/HighCouponCodeOtherSqlProvider.java
  5. 18
      hai-service/src/main/java/com/hai/entity/HighCouponCodeOther.java
  6. 60
      hai-service/src/main/java/com/hai/entity/HighCouponCodeOtherExample.java
  7. 7
      hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java
  8. 7
      hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java
  9. 25
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java
  10. 86
      hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java
  11. 11
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java

@ -1,16 +1,21 @@
package com.cweb.controller; package com.cweb.controller;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hai.common.Base64Util; import com.hai.common.Base64Util;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.AESEncodeUtil; import com.hai.common.security.AESEncodeUtil;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighDiscountAgentCode; import com.hai.config.ChongQingCNPCService;
import com.hai.entity.HighDiscountAgentRel; import com.hai.entity.*;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.service.HighDiscountAgentCodeService; import com.hai.service.HighDiscountAgentCodeService;
import com.hai.service.HighDiscountAgentRelService; import com.hai.service.HighDiscountAgentRelService;
import com.hai.service.HighDiscountCouponRelService; import com.hai.service.HighDiscountCouponRelService;
@ -20,13 +25,17 @@ import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -158,4 +167,24 @@ public class HighDiscountController {
} }
} }
@RequestMapping(value="/useDiscount",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "使用优惠券")
public ResponseData useDiscount(@RequestParam(name = "discountAgentCodeId", required = true) Long discountAgentCodeId) {
try {
highDiscountAgentCodeService.useDiscount(discountAgentCodeId);
return ResponseMsgUtil.success("操作成功");
} catch (DeadlockLoserDataAccessException deadlockLoserDataAccessException) {
log.error("HighActivityController -> userLottery() error!", "服务器繁忙");
return ResponseMsgUtil.builderResponse(ErrorCode.SERVER_BUSY_ERROR.getCode(),ErrorCode.SERVER_BUSY_ERROR.getMsg(),null);
} catch (Exception e) {
log.error("HighDiscountController -> useDiscount() error!",e);
return ResponseMsgUtil.exception(e);
}
}
} }

File diff suppressed because one or more lines are too long

@ -39,18 +39,18 @@ public interface HighCouponCodeOtherMapper extends HighCouponCodeOtherMapperExt
int deleteByPrimaryKey(Long id); int deleteByPrimaryKey(Long id);
@Insert({ @Insert({
"insert into high_coupon_code_other (`type`, coupon_agent_code_id, ", "insert into high_coupon_code_other (`type`, discount_agent_code_id, ",
"order_id, child_order_id, ", "coupon_agent_code_id, order_id, ",
"cou_type_code, cou_no, ", "child_order_id, cou_type_code, ",
"`status`, active_time, ", "cou_no, `status`, active_time, ",
"valid_start_date, valid_end_date, ", "valid_start_date, valid_end_date, ",
"use_time, station_code, ", "use_time, station_code, ",
"station_name, create_time, ", "station_name, create_time, ",
"ext_1, ext_2, ext_3)", "ext_1, ext_2, ext_3)",
"values (#{type,jdbcType=INTEGER}, #{couponAgentCodeId,jdbcType=BIGINT}, ", "values (#{type,jdbcType=INTEGER}, #{discountAgentCodeId,jdbcType=BIGINT}, ",
"#{orderId,jdbcType=BIGINT}, #{childOrderId,jdbcType=BIGINT}, ", "#{couponAgentCodeId,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, ",
"#{couTypeCode,jdbcType=VARCHAR}, #{couNo,jdbcType=VARCHAR}, ", "#{childOrderId,jdbcType=BIGINT}, #{couTypeCode,jdbcType=VARCHAR}, ",
"#{status,jdbcType=INTEGER}, #{activeTime,jdbcType=TIMESTAMP}, ", "#{couNo,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{activeTime,jdbcType=TIMESTAMP}, ",
"#{validStartDate,jdbcType=TIMESTAMP}, #{validEndDate,jdbcType=TIMESTAMP}, ", "#{validStartDate,jdbcType=TIMESTAMP}, #{validEndDate,jdbcType=TIMESTAMP}, ",
"#{useTime,jdbcType=TIMESTAMP}, #{stationCode,jdbcType=VARCHAR}, ", "#{useTime,jdbcType=TIMESTAMP}, #{stationCode,jdbcType=VARCHAR}, ",
"#{stationName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ", "#{stationName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
@ -67,6 +67,7 @@ public interface HighCouponCodeOtherMapper extends HighCouponCodeOtherMapperExt
@Results({ @Results({
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="type", property="type", jdbcType=JdbcType.INTEGER), @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
@Result(column="discount_agent_code_id", property="discountAgentCodeId", jdbcType=JdbcType.BIGINT),
@Result(column="coupon_agent_code_id", property="couponAgentCodeId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_agent_code_id", property="couponAgentCodeId", jdbcType=JdbcType.BIGINT),
@Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT),
@Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT), @Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT),
@ -88,15 +89,16 @@ public interface HighCouponCodeOtherMapper extends HighCouponCodeOtherMapperExt
@Select({ @Select({
"select", "select",
"id, `type`, coupon_agent_code_id, order_id, child_order_id, cou_type_code, cou_no, ", "id, `type`, discount_agent_code_id, coupon_agent_code_id, order_id, child_order_id, ",
"`status`, active_time, valid_start_date, valid_end_date, use_time, station_code, ", "cou_type_code, cou_no, `status`, active_time, valid_start_date, valid_end_date, ",
"station_name, create_time, ext_1, ext_2, ext_3", "use_time, station_code, station_name, create_time, ext_1, ext_2, ext_3",
"from high_coupon_code_other", "from high_coupon_code_other",
"where id = #{id,jdbcType=BIGINT}" "where id = #{id,jdbcType=BIGINT}"
}) })
@Results({ @Results({
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="type", property="type", jdbcType=JdbcType.INTEGER), @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
@Result(column="discount_agent_code_id", property="discountAgentCodeId", jdbcType=JdbcType.BIGINT),
@Result(column="coupon_agent_code_id", property="couponAgentCodeId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_agent_code_id", property="couponAgentCodeId", jdbcType=JdbcType.BIGINT),
@Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT),
@Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT), @Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT),
@ -128,6 +130,7 @@ public interface HighCouponCodeOtherMapper extends HighCouponCodeOtherMapperExt
@Update({ @Update({
"update high_coupon_code_other", "update high_coupon_code_other",
"set `type` = #{type,jdbcType=INTEGER},", "set `type` = #{type,jdbcType=INTEGER},",
"discount_agent_code_id = #{discountAgentCodeId,jdbcType=BIGINT},",
"coupon_agent_code_id = #{couponAgentCodeId,jdbcType=BIGINT},", "coupon_agent_code_id = #{couponAgentCodeId,jdbcType=BIGINT},",
"order_id = #{orderId,jdbcType=BIGINT},", "order_id = #{orderId,jdbcType=BIGINT},",
"child_order_id = #{childOrderId,jdbcType=BIGINT},", "child_order_id = #{childOrderId,jdbcType=BIGINT},",

@ -32,6 +32,10 @@ public class HighCouponCodeOtherSqlProvider {
sql.VALUES("`type`", "#{type,jdbcType=INTEGER}"); sql.VALUES("`type`", "#{type,jdbcType=INTEGER}");
} }
if (record.getDiscountAgentCodeId() != null) {
sql.VALUES("discount_agent_code_id", "#{discountAgentCodeId,jdbcType=BIGINT}");
}
if (record.getCouponAgentCodeId() != null) { if (record.getCouponAgentCodeId() != null) {
sql.VALUES("coupon_agent_code_id", "#{couponAgentCodeId,jdbcType=BIGINT}"); sql.VALUES("coupon_agent_code_id", "#{couponAgentCodeId,jdbcType=BIGINT}");
} }
@ -107,6 +111,7 @@ public class HighCouponCodeOtherSqlProvider {
sql.SELECT("id"); sql.SELECT("id");
} }
sql.SELECT("`type`"); sql.SELECT("`type`");
sql.SELECT("discount_agent_code_id");
sql.SELECT("coupon_agent_code_id"); sql.SELECT("coupon_agent_code_id");
sql.SELECT("order_id"); sql.SELECT("order_id");
sql.SELECT("child_order_id"); sql.SELECT("child_order_id");
@ -148,6 +153,10 @@ public class HighCouponCodeOtherSqlProvider {
sql.SET("`type` = #{record.type,jdbcType=INTEGER}"); sql.SET("`type` = #{record.type,jdbcType=INTEGER}");
} }
if (record.getDiscountAgentCodeId() != null) {
sql.SET("discount_agent_code_id = #{record.discountAgentCodeId,jdbcType=BIGINT}");
}
if (record.getCouponAgentCodeId() != null) { if (record.getCouponAgentCodeId() != null) {
sql.SET("coupon_agent_code_id = #{record.couponAgentCodeId,jdbcType=BIGINT}"); sql.SET("coupon_agent_code_id = #{record.couponAgentCodeId,jdbcType=BIGINT}");
} }
@ -222,6 +231,7 @@ public class HighCouponCodeOtherSqlProvider {
sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("id = #{record.id,jdbcType=BIGINT}");
sql.SET("`type` = #{record.type,jdbcType=INTEGER}"); sql.SET("`type` = #{record.type,jdbcType=INTEGER}");
sql.SET("discount_agent_code_id = #{record.discountAgentCodeId,jdbcType=BIGINT}");
sql.SET("coupon_agent_code_id = #{record.couponAgentCodeId,jdbcType=BIGINT}"); sql.SET("coupon_agent_code_id = #{record.couponAgentCodeId,jdbcType=BIGINT}");
sql.SET("order_id = #{record.orderId,jdbcType=BIGINT}"); sql.SET("order_id = #{record.orderId,jdbcType=BIGINT}");
sql.SET("child_order_id = #{record.childOrderId,jdbcType=BIGINT}"); sql.SET("child_order_id = #{record.childOrderId,jdbcType=BIGINT}");
@ -252,6 +262,10 @@ public class HighCouponCodeOtherSqlProvider {
sql.SET("`type` = #{type,jdbcType=INTEGER}"); sql.SET("`type` = #{type,jdbcType=INTEGER}");
} }
if (record.getDiscountAgentCodeId() != null) {
sql.SET("discount_agent_code_id = #{discountAgentCodeId,jdbcType=BIGINT}");
}
if (record.getCouponAgentCodeId() != null) { if (record.getCouponAgentCodeId() != null) {
sql.SET("coupon_agent_code_id = #{couponAgentCodeId,jdbcType=BIGINT}"); sql.SET("coupon_agent_code_id = #{couponAgentCodeId,jdbcType=BIGINT}");
} }

@ -19,10 +19,15 @@ public class HighCouponCodeOther implements Serializable {
private Long id; private Long id;
/** /**
* 类型 1 贵州中石化 2 重庆中石油 * 类型 1 贵州中石化 2 重庆中石油 3 优惠券
*/ */
private Integer type; private Integer type;
/**
* 代理商优惠券code
*/
private Long discountAgentCodeId;
/** /**
* 代理商卡券销售码id * 代理商卡券销售码id
*/ */
@ -112,6 +117,14 @@ public class HighCouponCodeOther implements Serializable {
this.type = type; this.type = type;
} }
public Long getDiscountAgentCodeId() {
return discountAgentCodeId;
}
public void setDiscountAgentCodeId(Long discountAgentCodeId) {
this.discountAgentCodeId = discountAgentCodeId;
}
public Long getCouponAgentCodeId() { public Long getCouponAgentCodeId() {
return couponAgentCodeId; return couponAgentCodeId;
} }
@ -254,6 +267,7 @@ public class HighCouponCodeOther implements Serializable {
HighCouponCodeOther other = (HighCouponCodeOther) that; HighCouponCodeOther other = (HighCouponCodeOther) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getDiscountAgentCodeId() == null ? other.getDiscountAgentCodeId() == null : this.getDiscountAgentCodeId().equals(other.getDiscountAgentCodeId()))
&& (this.getCouponAgentCodeId() == null ? other.getCouponAgentCodeId() == null : this.getCouponAgentCodeId().equals(other.getCouponAgentCodeId())) && (this.getCouponAgentCodeId() == null ? other.getCouponAgentCodeId() == null : this.getCouponAgentCodeId().equals(other.getCouponAgentCodeId()))
&& (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId())) && (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId()))
&& (this.getChildOrderId() == null ? other.getChildOrderId() == null : this.getChildOrderId().equals(other.getChildOrderId())) && (this.getChildOrderId() == null ? other.getChildOrderId() == null : this.getChildOrderId().equals(other.getChildOrderId()))
@ -278,6 +292,7 @@ public class HighCouponCodeOther implements Serializable {
int result = 1; int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getDiscountAgentCodeId() == null) ? 0 : getDiscountAgentCodeId().hashCode());
result = prime * result + ((getCouponAgentCodeId() == null) ? 0 : getCouponAgentCodeId().hashCode()); result = prime * result + ((getCouponAgentCodeId() == null) ? 0 : getCouponAgentCodeId().hashCode());
result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode()); result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode());
result = prime * result + ((getChildOrderId() == null) ? 0 : getChildOrderId().hashCode()); result = prime * result + ((getChildOrderId() == null) ? 0 : getChildOrderId().hashCode());
@ -305,6 +320,7 @@ public class HighCouponCodeOther implements Serializable {
sb.append("Hash = ").append(hashCode()); sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id); sb.append(", id=").append(id);
sb.append(", type=").append(type); sb.append(", type=").append(type);
sb.append(", discountAgentCodeId=").append(discountAgentCodeId);
sb.append(", couponAgentCodeId=").append(couponAgentCodeId); sb.append(", couponAgentCodeId=").append(couponAgentCodeId);
sb.append(", orderId=").append(orderId); sb.append(", orderId=").append(orderId);
sb.append(", childOrderId=").append(childOrderId); sb.append(", childOrderId=").append(childOrderId);

@ -245,6 +245,66 @@ public class HighCouponCodeOtherExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andDiscountAgentCodeIdIsNull() {
addCriterion("discount_agent_code_id is null");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdIsNotNull() {
addCriterion("discount_agent_code_id is not null");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdEqualTo(Long value) {
addCriterion("discount_agent_code_id =", value, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdNotEqualTo(Long value) {
addCriterion("discount_agent_code_id <>", value, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdGreaterThan(Long value) {
addCriterion("discount_agent_code_id >", value, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdGreaterThanOrEqualTo(Long value) {
addCriterion("discount_agent_code_id >=", value, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdLessThan(Long value) {
addCriterion("discount_agent_code_id <", value, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdLessThanOrEqualTo(Long value) {
addCriterion("discount_agent_code_id <=", value, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdIn(List<Long> values) {
addCriterion("discount_agent_code_id in", values, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdNotIn(List<Long> values) {
addCriterion("discount_agent_code_id not in", values, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdBetween(Long value1, Long value2) {
addCriterion("discount_agent_code_id between", value1, value2, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andDiscountAgentCodeIdNotBetween(Long value1, Long value2) {
addCriterion("discount_agent_code_id not between", value1, value2, "discountAgentCodeId");
return (Criteria) this;
}
public Criteria andCouponAgentCodeIdIsNull() { public Criteria andCouponAgentCodeIdIsNull() {
addCriterion("coupon_agent_code_id is null"); addCriterion("coupon_agent_code_id is null");
return (Criteria) this; return (Criteria) this;

@ -94,4 +94,11 @@ public interface HighDiscountAgentCodeService {
Integer getSalesDiscount(Long discountAgentId); Integer getSalesDiscount(Long discountAgentId);
List<HighDiscountAgentCode> getDiscountAgentCodByLimit(Long discountAgentId , Long num); List<HighDiscountAgentCode> getDiscountAgentCodByLimit(Long discountAgentId , Long num);
/**
* 优惠券前往使用
* @param discountAgentCodeId
* @throws Exception
*/
void useDiscount(Long discountAgentCodeId) throws Exception;
} }

@ -48,6 +48,13 @@ public interface HighDiscountUserRelService {
**/ **/
HighDiscountUserRel getRelByDiscount(Long discountId); HighDiscountUserRel getRelByDiscount(Long discountId);
/**
* 根据代理商优惠券code查询
* @param agentCodeId
* @return
*/
HighDiscountUserRel getRelByAgentCodeId(Long agentCodeId);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 根据id查询 * @Description 根据id查询

@ -7,6 +7,8 @@ import com.hai.dao.HighCouponCodeOtherMapper;
import com.hai.dao.HighUserCouponMapper; import com.hai.dao.HighUserCouponMapper;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.service.HighCouponCodeOtherService; import com.hai.service.HighCouponCodeOtherService;
import com.hai.service.HighDiscountAgentCodeService;
import com.hai.service.HighDiscountUserRelService;
import com.hai.service.HighOrderService; import com.hai.service.HighOrderService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -31,6 +33,12 @@ public class HighCouponCodeOtherServiceImpl implements HighCouponCodeOtherServic
@Resource @Resource
private HighOrderService highOrderService; private HighOrderService highOrderService;
@Resource
private HighDiscountAgentCodeService discountAgentCodeService;
@Resource
private HighDiscountUserRelService discountUserRelService;
@Override @Override
public void update(HighCouponCodeOther couponCodeOther) { public void update(HighCouponCodeOther couponCodeOther) {
highCouponCodeOtherMapper.updateByPrimaryKey(couponCodeOther); highCouponCodeOtherMapper.updateByPrimaryKey(couponCodeOther);
@ -102,11 +110,26 @@ public class HighCouponCodeOtherServiceImpl implements HighCouponCodeOtherServic
if (couponCodeOther.getCouponAgentCodeId() != null) { if (couponCodeOther.getCouponAgentCodeId() != null) {
HighCouponAgentCode agentCode = highCouponAgentCodeMapper.selectByPrimaryKey(couponCodeOther.getCouponAgentCodeId()); HighCouponAgentCode agentCode = highCouponAgentCodeMapper.selectByPrimaryKey(couponCodeOther.getCouponAgentCodeId());
if (agentCode == null) { if (agentCode != null) {
agentCode.setStatus(3); agentCode.setStatus(3);
highCouponAgentCodeMapper.updateByPrimaryKey(agentCode); highCouponAgentCodeMapper.updateByPrimaryKey(agentCode);
} }
} }
if (couponCodeOther.getDiscountAgentCodeId() != null) {
HighDiscountAgentCode discountAgentCode = discountAgentCodeService.getCodeById(couponCodeOther.getDiscountAgentCodeId());
if (discountAgentCode != null) {
discountAgentCode.setStatus(3);
discountAgentCodeService.updateCode(discountAgentCode);
HighDiscountUserRel discountUserRel = discountUserRelService.getRelByAgentCodeId(couponCodeOther.getDiscountAgentCodeId());
if (discountUserRel != null) {
discountUserRel.setStatus(2);
discountUserRel.setUseTime(couponCodeOther.getUseTime());
discountUserRelService.updateDiscountUserRel(discountUserRel);
}
}
}
} }
} }
} }

@ -1,12 +1,23 @@
package com.hai.service.impl; package com.hai.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil; import com.hai.common.utils.DateUtil;
import com.hai.config.ChongQingCNPCService;
import com.hai.dao.HighCouponCodeMapper; import com.hai.dao.HighCouponCodeMapper;
import com.hai.dao.HighCouponCodeOtherMapper;
import com.hai.dao.HighDiscountAgentCodeMapper; import com.hai.dao.HighDiscountAgentCodeMapper;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.model.HighUserModel;
import com.hai.service.*; import com.hai.service.*;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -14,6 +25,7 @@ import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -47,6 +59,15 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe
@Resource @Resource
private HighDiscountUserRelService highDiscountUserRelService; private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighCouponCodeOtherMapper highCouponCodeOtherMapper;
@Resource
private HighDiscountCouponRelService highDiscountCouponRelService;
@Resource
private UserCenter userCenter;
@Override @Override
public void insertCodeList(List<HighDiscountAgentCode> discountAgentCodeList) { public void insertCodeList(List<HighDiscountAgentCode> discountAgentCodeList) {
highDiscountAgentCodeMapper.insertListCode(discountAgentCodeList); highDiscountAgentCodeMapper.insertListCode(discountAgentCodeList);
@ -158,4 +179,69 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe
public List<HighDiscountAgentCode> getDiscountAgentCodByLimit(Long discountAgentId, Long num) { public List<HighDiscountAgentCode> getDiscountAgentCodByLimit(Long discountAgentId, Long num) {
return highDiscountAgentCodeMapper.getDiscountAgentCodByLimit(discountAgentId,num); return highDiscountAgentCodeMapper.getDiscountAgentCodByLimit(discountAgentId,num);
} }
@Override
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW, timeout = 30)
public void useDiscount(Long discountAgentCodeId) throws Exception {
HighUserModel userModel = userCenter.getSessionModel(HighUserModel.class);
if (userModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, "");
}
if (StringUtils.isBlank(userModel.getHighUser().getPhone())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "客户未设置手机号");
}
// 查询优惠券code
HighDiscountAgentCode discountAgentCode = getCodeById(discountAgentCodeId);
if (discountAgentCode == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券code错误");
}
if (!discountAgentCode.getStatus().equals(2)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误");
}
if (StringUtils.isBlank(discountAgentCode.getExt2())) {
HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(discountAgentCode.getDiscountAgentId());
if (rel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到代理商关联关系");
}
HighDiscount discount = highDiscountService.getDiscountById(rel.getDiscountId());
if (discount == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到优惠券");
}
List<HighDiscountCouponRel> couponRelList = highDiscountCouponRelService.getRelByDiscount(discount.getId());
if (couponRelList.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券未配置卡券");
}
List<HighDiscountCouponRel> couponList = couponRelList.stream().filter(o -> o.getHighCoupon().getCouponSource().equals(5)).collect(Collectors.toList());
if (couponList.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券未配置重庆中石油卡券");
}
String tradeId = discountAgentCode.getId()+""+System.currentTimeMillis()+"";
// 给用户发码
JSONObject response = ChongQingCNPCService.sendCNPCTicket(
couponList.get(0).getHighCoupon().getCouponKey(),
tradeId,
1,
userModel.getHighUser().getPhone());
JSONObject couponDetail = response.getJSONObject("ticketDetail");
JSONArray codeList = response.getJSONArray("codeList");
for (Object data : codeList) {
HighCouponCodeOther couponCodeOther = new HighCouponCodeOther();
couponCodeOther.setType(3);
couponCodeOther.setDiscountAgentCodeId(discountAgentCode.getId());
couponCodeOther.setCouTypeCode(couponDetail.getString("requestCode"));
couponCodeOther.setCouNo(ChongQingCNPCService.decryptCouponCode(String.valueOf(data)));
couponCodeOther.setActiveTime(new Date());
couponCodeOther.setValidStartDate(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd"));
couponCodeOther.setValidEndDate(DateUtil.format(couponDetail.getString("expiredDate"), "yyyy-MM-dd"));
couponCodeOther.setStatus(20);
couponCodeOther.setCreateTime(new Date());
highCouponCodeOtherMapper.insert(couponCodeOther);
}
discountAgentCode.setExt2(tradeId);
updateCode(discountAgentCode);
}
}
} }

@ -199,6 +199,17 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
return null; return null;
} }
@Override
public HighDiscountUserRel getRelByAgentCodeId(Long agentCodeId) {
HighDiscountUserRelExample example = new HighDiscountUserRelExample();
example.createCriteria().andDiscountAgentCodeIdEqualTo(agentCodeId);
List<HighDiscountUserRel> list = highDiscountUserRelMapper.selectByExample(example);
if (list.size() > 0) {
return list.get(0);
}
return null;
}
@Override @Override
public HighDiscountUserRel getRelById(Long id) { public HighDiscountUserRel getRelById(Long id) {
HighDiscountUserRel rel = highDiscountUserRelMapper.selectByPrimaryKey(id); HighDiscountUserRel rel = highDiscountUserRelMapper.selectByPrimaryKey(id);

Loading…
Cancel
Save