|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.hai.service.impl; |
|
|
|
package com.hai.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
|
|
import com.hai.common.GenerateCode; |
|
|
|
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; |
|
|
@ -15,6 +16,7 @@ import com.hai.service.*; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
@ -54,13 +56,9 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
private HighAgentService highAgentService; |
|
|
|
private HighAgentService highAgentService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW) |
|
|
|
public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel,Integer stockCount) { |
|
|
|
public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel,Integer stockCount) { |
|
|
|
|
|
|
|
|
|
|
|
// 查询未销售的卡券
|
|
|
|
|
|
|
|
List<HighCouponCode> codeList = highCouponCodeService.getNoSaleCode(highCouponAgentRel.getCouponId()); |
|
|
|
|
|
|
|
if (stockCount > codeList.size()) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法分配,分配数量超过库存数量"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (highCouponAgentRel.getId() != null) { |
|
|
|
if (highCouponAgentRel.getId() != null) { |
|
|
|
highCouponAgentRelMapper.updateByPrimaryKey(highCouponAgentRel); |
|
|
|
highCouponAgentRelMapper.updateByPrimaryKey(highCouponAgentRel); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -87,26 +85,50 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
record.setCreateTime(new Date()); |
|
|
|
record.setCreateTime(new Date()); |
|
|
|
highCouponAgentRecordMapper.insert(record); |
|
|
|
highCouponAgentRecordMapper.insert(record); |
|
|
|
|
|
|
|
|
|
|
|
List<HighCouponCode> assignCouponCodeList = codeList.stream().limit(stockCount).collect(Collectors.toList()); |
|
|
|
if (highCouponAgentRel.getType() == 1) { |
|
|
|
HighCouponAgentCode highCouponAgentCode; |
|
|
|
// 查询未销售的卡券
|
|
|
|
for (HighCouponCode code : assignCouponCodeList) { |
|
|
|
List<HighCouponCode> codeList = highCouponCodeService.getNoSaleCode(highCouponAgentRel.getCouponId()); |
|
|
|
code.setAgentId(highCouponAgentRel.getAgentId()); |
|
|
|
if (stockCount > codeList.size()) { |
|
|
|
code.setIsAssignAgent(true); |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法分配,分配数量超过库存数量"); |
|
|
|
highCouponCodeService.updateCouponCode(code); |
|
|
|
} |
|
|
|
|
|
|
|
List<HighCouponCode> assignCouponCodeList = codeList.stream().limit(stockCount).collect(Collectors.toList()); |
|
|
|
highCouponAgentCode = new HighCouponAgentCode(); |
|
|
|
HighCouponAgentCode highCouponAgentCode; |
|
|
|
highCouponAgentCode.setCouponAgentId(highCouponAgentRel.getId()); |
|
|
|
for (HighCouponCode code : assignCouponCodeList) { |
|
|
|
highCouponAgentCode.setCouponAgentRecordId(record.getId()); |
|
|
|
code.setAgentId(highCouponAgentRel.getAgentId()); |
|
|
|
highCouponAgentCode.setCouponId(code.getCouponId()); |
|
|
|
code.setIsAssignAgent(true); |
|
|
|
highCouponAgentCode.setAgentId(highCouponAgentRel.getAgentId()); |
|
|
|
highCouponCodeService.updateCouponCode(code); |
|
|
|
highCouponAgentCode.setCouponCodeId(code.getId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setCouponCode(code.getSalesCode()); |
|
|
|
highCouponAgentCode = new HighCouponAgentCode(); |
|
|
|
highCouponAgentCode.setQrCode(code.getExt1()); |
|
|
|
highCouponAgentCode.setCouponAgentId(highCouponAgentRel.getId()); |
|
|
|
highCouponAgentCode.setStatus(1); |
|
|
|
highCouponAgentCode.setCouponAgentRecordId(record.getId()); |
|
|
|
highCouponAgentCode.setCreateTime(new Date()); |
|
|
|
highCouponAgentCode.setCouponId(code.getCouponId()); |
|
|
|
highCouponAgentCode.setOperatorId(highCouponAgentRel.getOperatorId()); |
|
|
|
highCouponAgentCode.setAgentId(highCouponAgentRel.getAgentId()); |
|
|
|
highCouponAgentCode.setOperatorName(highCouponAgentRel.getOperatorName()); |
|
|
|
highCouponAgentCode.setCouponCodeId(code.getId()); |
|
|
|
highCouponAgentCodeMapper.insert(highCouponAgentCode); |
|
|
|
highCouponAgentCode.setCouponCode(code.getSalesCode()); |
|
|
|
|
|
|
|
highCouponAgentCode.setQrCode(code.getExt1()); |
|
|
|
|
|
|
|
highCouponAgentCode.setStatus(1); |
|
|
|
|
|
|
|
highCouponAgentCode.setCreateTime(new Date()); |
|
|
|
|
|
|
|
highCouponAgentCode.setOperatorId(highCouponAgentRel.getOperatorId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setOperatorName(highCouponAgentRel.getOperatorName()); |
|
|
|
|
|
|
|
highCouponAgentCodeMapper.insert(highCouponAgentCode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (highCouponAgentRel.getType() == 2) { |
|
|
|
|
|
|
|
HighCouponAgentCode highCouponAgentCode; |
|
|
|
|
|
|
|
for (int i = 0; i < stockCount; i++) { |
|
|
|
|
|
|
|
highCouponAgentCode = new HighCouponAgentCode(); |
|
|
|
|
|
|
|
highCouponAgentCode.setCouponAgentId(highCouponAgentRel.getId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setCouponAgentRecordId(record.getId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setCouponId(highCoupon.getId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setAgentId(highCouponAgentRel.getAgentId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setConvertCode(generateConvertCode(highCouponAgentRel.getId())); |
|
|
|
|
|
|
|
highCouponAgentCode.setStatus(1); |
|
|
|
|
|
|
|
highCouponAgentCode.setCreateTime(new Date()); |
|
|
|
|
|
|
|
highCouponAgentCode.setOperatorId(highCouponAgentRel.getOperatorId()); |
|
|
|
|
|
|
|
highCouponAgentCode.setOperatorName(highCouponAgentRel.getOperatorName()); |
|
|
|
|
|
|
|
highCouponAgentCodeMapper.insert(highCouponAgentCode); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -116,9 +138,9 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public HighCouponAgentRel getRelByCouponAgent(Long couponId, Long agentId) { |
|
|
|
public HighCouponAgentRel getRelByCouponAgent(Long couponId, Long agentId,Integer type) { |
|
|
|
HighCouponAgentRelExample example = new HighCouponAgentRelExample(); |
|
|
|
HighCouponAgentRelExample example = new HighCouponAgentRelExample(); |
|
|
|
example.createCriteria().andCouponIdEqualTo(couponId).andAgentIdEqualTo(agentId); |
|
|
|
example.createCriteria().andCouponIdEqualTo(couponId).andAgentIdEqualTo(agentId).andTypeEqualTo(type); |
|
|
|
List<HighCouponAgentRel> list = highCouponAgentRelMapper.selectByExample(example); |
|
|
|
List<HighCouponAgentRel> list = highCouponAgentRelMapper.selectByExample(example); |
|
|
|
if (list != null && list.size() > 0) { |
|
|
|
if (list != null && list.size() > 0) { |
|
|
|
return list.get(0); |
|
|
|
return list.get(0); |
|
|
@ -131,6 +153,10 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
HighCouponAgentRelExample example = new HighCouponAgentRelExample(); |
|
|
|
HighCouponAgentRelExample example = new HighCouponAgentRelExample(); |
|
|
|
HighCouponAgentRelExample.Criteria criteria = example.createCriteria(); |
|
|
|
HighCouponAgentRelExample.Criteria criteria = example.createCriteria(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (MapUtils.getInteger(map, "type") != null) { |
|
|
|
|
|
|
|
criteria.andTypeEqualTo(MapUtils.getInteger(map, "type")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (MapUtils.getLong(map, "couponId") != null) { |
|
|
|
if (MapUtils.getLong(map, "couponId") != null) { |
|
|
|
criteria.andCouponIdEqualTo(MapUtils.getLong(map, "couponId")); |
|
|
|
criteria.andCouponIdEqualTo(MapUtils.getLong(map, "couponId")); |
|
|
|
} |
|
|
|
} |
|
|
@ -213,15 +239,19 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
couponAgentCode.setRemark(remark); |
|
|
|
couponAgentCode.setRemark(remark); |
|
|
|
highCouponAgentCodeMapper.updateByPrimaryKey(couponAgentCode); |
|
|
|
highCouponAgentCodeMapper.updateByPrimaryKey(couponAgentCode); |
|
|
|
|
|
|
|
|
|
|
|
HighCouponAgentRel couponAgent = getRelByCouponAgent(couponAgentCode.getCouponId(), couponAgentCode.getAgentId()); |
|
|
|
HighCouponAgentRel couponAgent = getRelByCouponAgent(couponAgentCode.getCouponId(), couponAgentCode.getAgentId(), couponAgentCode.getType()); |
|
|
|
couponAgent.setStockCount(couponAgent.getStockCount() - 1); |
|
|
|
couponAgent.setStockCount(couponAgent.getStockCount() - 1); |
|
|
|
couponAgent.setSalesCount(couponAgent.getSalesCount() + 1); |
|
|
|
couponAgent.setSalesCount(couponAgent.getSalesCount() + 1); |
|
|
|
highCouponAgentRelMapper.updateByPrimaryKey(couponAgent); |
|
|
|
highCouponAgentRelMapper.updateByPrimaryKey(couponAgent); |
|
|
|
|
|
|
|
|
|
|
|
HighCouponCode couponCode = highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId()); |
|
|
|
|
|
|
|
couponCode.setStatus(2); |
|
|
|
HighCouponCode couponCode = null; |
|
|
|
couponCode.setReceiveTime(new Date()); |
|
|
|
if (couponAgentCode.getType() == 1) { |
|
|
|
highCouponCodeService.updateCouponCode(couponCode); |
|
|
|
couponCode = highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId()); |
|
|
|
|
|
|
|
couponCode.setStatus(2); |
|
|
|
|
|
|
|
couponCode.setReceiveTime(new Date()); |
|
|
|
|
|
|
|
highCouponCodeService.updateCouponCode(couponCode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); |
|
|
|
map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); |
|
|
@ -231,12 +261,13 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Object> getSalesCountByAgent(Long agentId) throws Exception { |
|
|
|
public Map<String, Object> getSalesCountByAgent(Long agentId, Integer type) throws Exception { |
|
|
|
BigDecimal surplusCountPrice = new BigDecimal("0"); |
|
|
|
BigDecimal surplusCountPrice = new BigDecimal("0"); |
|
|
|
BigDecimal salesCountPrice = new BigDecimal("0"); |
|
|
|
BigDecimal salesCountPrice = new BigDecimal("0"); |
|
|
|
|
|
|
|
|
|
|
|
Map<String,Object> listMap = new HashMap<>(); |
|
|
|
Map<String,Object> listMap = new HashMap<>(); |
|
|
|
listMap.put("agentId", agentId); |
|
|
|
listMap.put("agentId", agentId); |
|
|
|
|
|
|
|
listMap.put("type", type); |
|
|
|
List<HighCouponAgentRel> list = getCouponAgentList(listMap).stream().sorted(Comparator.comparing(HighCouponAgentRel::getSalesPrice)).collect(Collectors.toList()); |
|
|
|
List<HighCouponAgentRel> list = getCouponAgentList(listMap).stream().sorted(Comparator.comparing(HighCouponAgentRel::getSalesPrice)).collect(Collectors.toList()); |
|
|
|
for (HighCouponAgentRel highCouponAgentRel : list) { |
|
|
|
for (HighCouponAgentRel highCouponAgentRel : list) { |
|
|
|
BigDecimal surplusPrice = new BigDecimal(highCouponAgentRel.getStockCount()).multiply((highCouponAgentRel.getSalesPrice())); |
|
|
|
BigDecimal surplusPrice = new BigDecimal(highCouponAgentRel.getStockCount()).multiply((highCouponAgentRel.getSalesPrice())); |
|
|
@ -246,7 +277,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
salesCountPrice = salesCountPrice.add(salesPrice); |
|
|
|
salesCountPrice = salesCountPrice.add(salesPrice); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 计算使用有效期
|
|
|
|
// 当前日时间
|
|
|
|
Calendar consumeTimeS = Calendar.getInstance(); |
|
|
|
Calendar consumeTimeS = Calendar.getInstance(); |
|
|
|
consumeTimeS.setTime(new Date()); |
|
|
|
consumeTimeS.setTime(new Date()); |
|
|
|
consumeTimeS.set(Calendar.HOUR_OF_DAY, 00); |
|
|
|
consumeTimeS.set(Calendar.HOUR_OF_DAY, 00); |
|
|
@ -265,8 +296,8 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
returnMap.put("orderCount", agentSales.getCount()); |
|
|
|
returnMap.put("orderCount", agentSales.getCount()); |
|
|
|
returnMap.put("turnoverPrice", agentSales.getSalesCountPrice()); |
|
|
|
returnMap.put("turnoverPrice", agentSales.getSalesCountPrice()); |
|
|
|
|
|
|
|
|
|
|
|
returnMap.put("laveStockCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "1")); // 库存数量
|
|
|
|
returnMap.put("laveStockCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "1", type)); // 库存数量
|
|
|
|
returnMap.put("soldCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "2,3")); // 销售数量
|
|
|
|
returnMap.put("soldCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "2,3", type)); // 销售数量
|
|
|
|
|
|
|
|
|
|
|
|
returnMap.put("surplusCountPrice", surplusCountPrice); // 剩余总额
|
|
|
|
returnMap.put("surplusCountPrice", surplusCountPrice); // 剩余总额
|
|
|
|
returnMap.put("salesCountPrice", salesCountPrice); // 销售总额
|
|
|
|
returnMap.put("salesCountPrice", salesCountPrice); // 销售总额
|
|
|
@ -312,4 +343,52 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { |
|
|
|
} |
|
|
|
} |
|
|
|
return new ArrayList<>(); |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String generateConvertCode(Long couponAgentRelId) { |
|
|
|
|
|
|
|
// 生成兑换码
|
|
|
|
|
|
|
|
String code = GenerateCode.convertCode(couponAgentRelId); |
|
|
|
|
|
|
|
if (getConvertCode(code) != null){ |
|
|
|
|
|
|
|
return generateConvertCode(couponAgentRelId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return code; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public HighCouponAgentCode getConvertCode(String convertCode) { |
|
|
|
|
|
|
|
HighCouponAgentCodeExample example = new HighCouponAgentCodeExample(); |
|
|
|
|
|
|
|
example.createCriteria().andConvertCodeEqualTo(convertCode); |
|
|
|
|
|
|
|
List<HighCouponAgentCode> list = highCouponAgentCodeMapper.selectByExample(example); |
|
|
|
|
|
|
|
if (list.size() > 0) { |
|
|
|
|
|
|
|
return list.get(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) |
|
|
|
|
|
|
|
public String useConvertCode(String code) { |
|
|
|
|
|
|
|
// 查询兑换码
|
|
|
|
|
|
|
|
HighCouponAgentCode convertCode = getConvertCode(code); |
|
|
|
|
|
|
|
if (convertCode == null) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的兑换码"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (convertCode.getStatus() != 1) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 查询未销售的卡券
|
|
|
|
|
|
|
|
List<HighCouponCode> codeList = highCouponCodeService.getNoSaleCode(convertCode.getCouponId()); |
|
|
|
|
|
|
|
if (codeList.size() == 0) { |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法使用兑换码"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
HighCouponCode couponCode = codeList.get(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
convertCode.setCouponCodeId(couponCode.getId()); |
|
|
|
|
|
|
|
convertCode.setCouponCode(couponCode.getSalesCode()); |
|
|
|
|
|
|
|
convertCode.setQrCode(couponCode.getExt1()); |
|
|
|
|
|
|
|
convertCode.setStatus(2); |
|
|
|
|
|
|
|
highCouponAgentCodeMapper.updateByPrimaryKey(convertCode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "/couponCode/"+couponCode.getExt1(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|