Commit 2357c337 by 吕明尚

查询可用优惠卷完成

parent 87fdcdb2
...@@ -47,7 +47,7 @@ public class QPController { ...@@ -47,7 +47,7 @@ public class QPController {
//用户销券接口 //用户销券接口
@GetMapping("/reverseconsumeByUser") @GetMapping("/reverseconsumeByUser")
public R reverseconsumeByUser(String code, String appDealId) { public R reverseconsumeByUser(Long id) {
return R.ok(qpService.reverseconsumeByUser(code, appDealId)); return R.ok(qpService.reverseconsumeByUser(id));
} }
} }
...@@ -38,14 +38,12 @@ public class SCoupon extends BaseEntity ...@@ -38,14 +38,12 @@ public class SCoupon extends BaseEntity
private Date endDate; private Date endDate;
/** 有效开始时段 */ /** 有效开始时段 */
@JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "有效开始时段", width = 30, dateFormat = "HH:mm")
@Excel(name = "有效开始时段", width = 30, dateFormat = "yyyy-MM-dd") private String validStartTime;
private Date validStartTime;
/** 有效结束时段 */ /** 有效结束时段 */
@JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "有效结束时段", width = 30, dateFormat = "HH:mm")
@Excel(name = "有效结束时段", width = 30, dateFormat = "yyyy-MM-dd") private String validEndTime;
private Date validEndTime;
//门店类型 //门店类型
@Excel(name = "门店类型(1:标准店,2:外卖店,3:酒店,4:其他)") @Excel(name = "门店类型(1:标准店,2:外卖店,3:酒店,4:其他)")
......
...@@ -18,5 +18,5 @@ public interface QPService { ...@@ -18,5 +18,5 @@ public interface QPService {
String consumeByUser(String code, int count); String consumeByUser(String code, int count);
String reverseconsumeByUser(String code, String appDealId); String reverseconsumeByUser(Long id);
} }
...@@ -11,9 +11,11 @@ import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptPrepare; ...@@ -11,9 +11,11 @@ import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptPrepare;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptReverseConsume; import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptReverseConsume;
import com.dianping.openapi.sdk.api.tuangou.entity.*; import com.dianping.openapi.sdk.api.tuangou.entity.*;
import com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient; import com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import share.common.utils.uuid.UUID;
import share.system.domain.SConsumer; import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon; import share.system.domain.SConsumerCoupon;
import share.system.domain.SCoupon; import share.system.domain.SCoupon;
...@@ -22,7 +24,11 @@ import share.system.service.ISConsumerCouponService; ...@@ -22,7 +24,11 @@ import share.system.service.ISConsumerCouponService;
import share.system.service.ISCouponService; import share.system.service.ISCouponService;
import share.system.service.QPService; import share.system.service.QPService;
import java.util.List; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Service @Service
public class QPServiceImpl implements QPService { public class QPServiceImpl implements QPService {
...@@ -72,6 +78,8 @@ public class QPServiceImpl implements QPService { ...@@ -72,6 +78,8 @@ public class QPServiceImpl implements QPService {
sConsumerCoupon.setPlatformType("2"); sConsumerCoupon.setPlatformType("2");
sConsumerCoupon.setStartDate(sCoupon.getStartDate()); sConsumerCoupon.setStartDate(sCoupon.getStartDate());
sConsumerCoupon.setEndDate(item.getReceiptEndDate()); sConsumerCoupon.setEndDate(item.getReceiptEndDate());
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime());
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId())); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon); isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
}); });
...@@ -79,9 +87,24 @@ public class QPServiceImpl implements QPService { ...@@ -79,9 +87,24 @@ public class QPServiceImpl implements QPService {
} }
@Override @Override
public String reverseconsumeByUser(String code, String appDealId) { public String reverseconsumeByUser(Long id) {
TuangouReceiptGetConsumedReponseEntity getconsumed = getconsumed(code); SConsumerCoupon byId = isConsumerCouponService.getById(id);
return null; if (byId == null) {
throw new RuntimeException("未找到对应的券码");
}
if(StringUtils.isBlank(byId.getCouponCode())){
throw new RuntimeException("未找到对应的券码");
}
TuangouReceiptGetConsumedReponseEntity getconsumed = getconsumed(byId.getCouponCode());
if (getconsumed == null) {
throw new RuntimeException("未找到对应的券码");
}
List<TuangouReceiptReverseConsumeResponseEntity> reverseconsume = reverseconsume(byId.getCouponCode(), getconsumed.getApp_shop_id());
if (reverseconsume == null) {
throw new RuntimeException("未找到对应的券码");
}
isConsumerCouponService.removeById(id);
return "销卷成功";
} }
/** /**
......
...@@ -2,6 +2,7 @@ package share.system.service.impl; ...@@ -2,6 +2,7 @@ package share.system.service.impl;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
...@@ -32,8 +33,7 @@ import share.system.service.ISStoreService; ...@@ -32,8 +33,7 @@ import share.system.service.ISStoreService;
* @date 2023-10-12 * @date 2023-10-12
*/ */
@Service @Service
public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMapper, SConsumerCoupon> implements ISConsumerCouponService public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMapper, SConsumerCoupon> implements ISConsumerCouponService {
{
@Autowired @Autowired
private SConsumerCouponMapper sConsumerCouponMapper; private SConsumerCouponMapper sConsumerCouponMapper;
...@@ -50,8 +50,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -50,8 +50,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
* @return 优惠券领取记录 * @return 优惠券领取记录
*/ */
@Override @Override
public SConsumerCoupon selectSConsumerCouponById(Long id) public SConsumerCoupon selectSConsumerCouponById(Long id) {
{
return sConsumerCouponMapper.selectSConsumerCouponById(id); return sConsumerCouponMapper.selectSConsumerCouponById(id);
} }
...@@ -62,8 +61,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -62,8 +61,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
* @return 优惠券领取记录 * @return 优惠券领取记录
*/ */
@Override @Override
public List<SConsumerCoupon> selectSConsumerCouponList(SConsumerCoupon sConsumerCoupon) public List<SConsumerCoupon> selectSConsumerCouponList(SConsumerCoupon sConsumerCoupon) {
{
return sConsumerCouponMapper.selectSConsumerCouponList(sConsumerCoupon); return sConsumerCouponMapper.selectSConsumerCouponList(sConsumerCoupon);
} }
...@@ -74,8 +72,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -74,8 +72,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertSConsumerCoupon(SConsumerCoupon sConsumerCoupon) public int insertSConsumerCoupon(SConsumerCoupon sConsumerCoupon) {
{
sConsumerCoupon.setCreateTime(DateUtils.getNowDate()); sConsumerCoupon.setCreateTime(DateUtils.getNowDate());
return sConsumerCouponMapper.insertSConsumerCoupon(sConsumerCoupon); return sConsumerCouponMapper.insertSConsumerCoupon(sConsumerCoupon);
} }
...@@ -87,8 +84,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -87,8 +84,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateSConsumerCoupon(SConsumerCoupon sConsumerCoupon) public int updateSConsumerCoupon(SConsumerCoupon sConsumerCoupon) {
{
sConsumerCoupon.setUpdateTime(DateUtils.getNowDate()); sConsumerCoupon.setUpdateTime(DateUtils.getNowDate());
return sConsumerCouponMapper.updateSConsumerCoupon(sConsumerCoupon); return sConsumerCouponMapper.updateSConsumerCoupon(sConsumerCoupon);
} }
...@@ -100,8 +96,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -100,8 +96,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteSConsumerCouponByIds(Long[] ids) public int deleteSConsumerCouponByIds(Long[] ids) {
{
return sConsumerCouponMapper.deleteSConsumerCouponByIds(ids); return sConsumerCouponMapper.deleteSConsumerCouponByIds(ids);
} }
...@@ -112,8 +107,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -112,8 +107,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteSConsumerCouponById(Long id) public int deleteSConsumerCouponById(Long id) {
{
return sConsumerCouponMapper.deleteSConsumerCouponById(id); return sConsumerCouponMapper.deleteSConsumerCouponById(id);
} }
...@@ -127,7 +121,8 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -127,7 +121,8 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon(); SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
SConsumer user = FrontTokenComponent.getWxSConsumerEntry(); SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
sConsumerCoupon.setUseStatus("0"); sConsumerCoupon.setUseStatus("0");
sConsumerCoupon.setConsumerId(user.getId()); // sConsumerCoupon.setConsumerId(user.getId());
sConsumerCoupon.setConsumerId(1714160213741535234L);
//查询用户未使用的优惠券 //查询用户未使用的优惠券
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponMapper.selectSConsumerCouponList(sConsumerCoupon); List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponMapper.selectSConsumerCouponList(sConsumerCoupon);
//计算时长 //计算时长
...@@ -137,13 +132,16 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -137,13 +132,16 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
} }
//迭代 //迭代
sConsumerCoupons.forEach(item -> { sConsumerCoupons.forEach(item -> {
if (item.getStartDate().compareTo(couponRequest.getPreStartDate()) < 0) { if (item.getStartDate().compareTo(couponRequest.getPreStartDate()) <= 0 && item.getEndDate().compareTo(couponRequest.getPreEndDate()) >= 0) {
SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm");
String proStartTime = sdf1.format(couponRequest.getPreStartDate());
if (proStartTime.compareTo(item.getCouponTimeStart()) >= 0) {
SStore sStore = sStoreService.getById(couponRequest.getStoreId()); SStore sStore = sStoreService.getById(couponRequest.getStoreId());
SRoom byId = sRoomService.getById(couponRequest.getRoomId()); SRoom byId = sRoomService.getById(couponRequest.getRoomId());
BigDecimal subtract = new BigDecimal(item.getMinDuration()); BigDecimal subtract = new BigDecimal(item.getMinDuration());
if (item.getCouponType().equals("3")) { if (item.getCouponType().equals("3")) {
//判断门槛时长 //判断门槛时长
if (bigDecimal.compareTo(subtract) > 0) { if (bigDecimal.compareTo(subtract) >= 0) {
//判断门店类型 //判断门店类型
if (item.getStoreType().contains(sStore.getStoreType())) { if (item.getStoreType().contains(sStore.getStoreType())) {
//判断房间类型 //判断房间类型
...@@ -187,9 +185,9 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -187,9 +185,9 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
//计算价格 //计算价格
BigDecimal multiply = bigDecimal.multiply(byId.getPrice()); BigDecimal multiply = bigDecimal.multiply(byId.getPrice());
//判断是否满足优惠券门槛 //判断是否满足优惠券门槛
if (item.getMinPrice().compareTo(multiply) > 0) { if (item.getMinPrice().compareTo(multiply) <= 0) {
//判断门槛时长 //判断门槛时长
if (bigDecimal.compareTo(subtract) > 0) { if (bigDecimal.compareTo(subtract) >= 0) {
//判断门店类型 //判断门店类型
if (item.getStoreType().contains(sStore.getStoreType())) { if (item.getStoreType().contains(sStore.getStoreType())) {
//判断房间类型 //判断房间类型
...@@ -237,7 +235,11 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe ...@@ -237,7 +235,11 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
} }
} else { } else {
item.setIsAvailable(1); item.setIsAvailable(1);
item.setReason("优惠卷未生效,优惠卷生效时间为" + item.getStartDate() + "-" + item.getEndDate()); item.setReason("优惠卷未生效,优惠卷有效时段为每天" + item.getCouponTimeStart() + "-" + item.getCouponTimeEnd());
}
} else {
item.setIsAvailable(1);
item.setReason("优惠卷未生效,优惠卷有效时间为" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, item.getStartDate()) + "-" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, item.getEndDate()));
} }
}); });
return sConsumerCoupons; return sConsumerCoupons;
......
...@@ -70,7 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -70,7 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectSCouponVo"/> <include refid="selectSCouponVo"/>
where id = #{id} where id = #{id}
</select> </select>
<select id="selectSCouponByName" resultType="share.system.domain.SCoupon"> <select id="selectSCouponByName" resultMap="SCouponResult">
<include refid="selectSCouponVo"/> <include refid="selectSCouponVo"/>
where name = #{name} where name = #{name}
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment