新人福利优惠券领取

This commit is contained in:
zhangheng 2023-11-08 16:40:58 +08:00
parent b02fc13a63
commit 9c9bc2542c
3 changed files with 90 additions and 12 deletions

View File

@ -4,36 +4,39 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.xinelu.common.config.AppletChatConfig;
import com.xinelu.common.entity.AppletPhoneVO;
import com.xinelu.common.enums.CouponReceiveTypeEnum;
import com.xinelu.common.enums.CouponUseStatusEnum;
import com.xinelu.common.exception.ServiceException;
import com.xinelu.common.utils.bean.BeanUtils;
import com.xinelu.common.utils.http.HttpService;
import com.xinelu.common.utils.http.HttpUtils;
import com.xinelu.common.utils.http.SslUtils;
import com.xinelu.common.utils.spring.SpringUtils;
import com.xinelu.common.utils.uuid.IdUtils;
import com.xinelu.familydoctor.applet.mapper.ResidentPatientInfoMapper;
import com.xinelu.familydoctor.applet.pojo.body.PatientInfoBody;
import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo;
import com.xinelu.familydoctor.applet.pojo.query.PatientInfoQuery;
import com.xinelu.familydoctor.applet.pojo.vo.SignInfoDetailVo;
import com.xinelu.familydoctor.applet.service.IResidentPatientInfoService;
import com.xinelu.familydoctor.applet.utils.AppletAccessTokenUtils;
import com.xinelu.manage.domain.coupon.Coupon;
import com.xinelu.manage.domain.patientcouponreceive.PatientCouponReceive;
import com.xinelu.manage.domain.receiveAddressInfo.ReceiveAddressInfo;
import com.xinelu.manage.mapper.coupon.CouponMapper;
import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper;
import com.xinelu.manage.mapper.receiveAddressInfo.ReceiveAddressInfoMapper;
import com.xinelu.manage.vo.patientcouponreceive.PatientCouponReceiveInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -58,6 +61,10 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
private RedisTemplate<String, Object> redisTemplate;
@Resource
private ReceiveAddressInfoMapper receiveAddressInfoMapper;
@Resource
private PatientCouponReceiveMapper patientCouponReceiveMapper;
@Resource
private CouponMapper couponMapper;
/**
* @return com.xinelu.familydoctor.applet.pojo.entity.PatientInfo
@ -192,7 +199,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
} else {
patientInfo.setDisease("0");
}
patientInfo.setLoginFlag(Long.valueOf(1));
patientInfo.setLoginFlag(1L);
patientInfo.setBindOpenid(body.getOpenid());
updatePatientInfo(patientInfo);
@ -216,7 +223,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
patientInfo.setUpdateBy(body.getCardNo());
patientInfo.setHeadPictureUrl(body.getHeadPictureUrl());
patientInfo.setDelFlag(0);
patientInfo.setLoginFlag(Long.valueOf(1));
patientInfo.setLoginFlag(1L);
if (body.getDiseaseList() != null) {
patientInfo.setDisease(body.getDiseaseList().stream().collect(Collectors.joining(",")));
} else {
@ -245,7 +252,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
entity.setIsChecked("0");
entity.setCreateTime(new Date());
entity.setCreateBy(body.getCardNo());
entity.setLoginFlag(Long.valueOf(1));
entity.setLoginFlag(1L);
entity.setDelFlag(0);
entity.setBindOpenid(body.getOpenid());
residentPatientInfoMapper.insertPatientInfo(entity);
@ -264,6 +271,15 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
}
this.insertReceiveAddress(patientInfo);
}
PatientInfo patient = residentPatientInfoMapper.getLoginByOpenId(body.getOpenid());
//判断是否是第一次完善如果是则发放新人优惠券信息
PatientCouponReceive patientCouponReceive = new PatientCouponReceive();
patientCouponReceive.setReceiveSource(CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo());
patientCouponReceive.setPatientId(patient.getId());
int couponReceiveCount = patientCouponReceiveMapper.getCouponReceiveByReceiveSource(patient.getId(), CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo());
if (Objects.nonNull(patient.getLoginFlag()) && patient.getLoginFlag() ==1 && couponReceiveCount <= 0) {
issueCoupons(patient);
}
}
/** 新增收货人地址信息 */
@ -450,4 +466,50 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
HashMap.put("cityCode", cityCode);
return HashMap;
}
/**
* 发放优惠券方法胡
*
* @param patient 会员信息
*/
public void issueCoupons(PatientInfo patient ) {
PatientCouponReceiveInfoVO receiveInfoVO = new PatientCouponReceiveInfoVO();
//查询新人福利的优惠券列表信息
Coupon coupon = new Coupon();
Long patientId = patient.getId();
coupon.setReceiveType(CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo());
List<Coupon> couponList = couponMapper.selectCouponList(coupon);
if (CollectionUtils.isEmpty(couponList)) {
return ;
}
//组装优惠券信息
List<PatientCouponReceive> couponReceiveList = Lists.newArrayList();
for (Coupon couponInfo : couponList) {
if (Objects.isNull(couponInfo.getId())) {
continue;
}
PatientCouponReceive couponReceive = new PatientCouponReceive();
couponReceive.setPatientId(patientId);
couponReceive.setCouponId(couponInfo.getId());
couponReceive.setReceiveSource(CouponReceiveTypeEnum.NEW_PEOPLE_WELFARE.getInfo());
couponReceive.setUseStatus(CouponUseStatusEnum.NOT_USED.getInfo());
couponReceive.setExpirationStartTime(LocalDateTime.now());
couponReceive.setExpirationEndTime(LocalDate.now().plusDays(Objects.isNull(couponInfo.getCouponReductionDays()) ? 0 : couponInfo.getCouponReductionDays()).atTime(23, 59, 59));
couponReceive.setReceiveTime(LocalDateTime.now());
couponReceive.setCouponReductionDays(Objects.isNull(couponInfo.getCouponReductionDays()) ? 0 : couponInfo.getCouponReductionDays());
couponReceive.setCreateTime(LocalDateTime.now());
couponReceive.setCouponTitle(StringUtils.isBlank(couponInfo.getCouponTitle()) ? "" : couponInfo.getCouponTitle());
couponReceive.setCouponPrice(Objects.isNull(couponInfo.getCouponPrice()) ? BigDecimal.ZERO : couponInfo.getCouponPrice());
couponReceive.setCouponConsumePrice(Objects.isNull(couponInfo.getCouponConsumePrice()) ? BigDecimal.ZERO : couponInfo.getCouponConsumePrice());
couponReceive.setCouponDescription(StringUtils.isBlank(couponInfo.getCouponDescription()) ? "" : couponInfo.getCouponDescription());
couponReceiveList.add(couponReceive);
}
if (CollectionUtils.isNotEmpty(couponReceiveList)) {
int insertCount = patientCouponReceiveMapper.insertBatchPatientReceive(couponReceiveList);
if (insertCount <= 0) {
log.error("完善用户信息接口-新人送券执行失败,输入参数[{}]", couponReceiveList);
throw new ServiceException("完善用户信息失败,请联系管理员!");
}
}
}
}

View File

@ -127,4 +127,12 @@ public interface PatientCouponReceiveMapper {
* @return 会员用户优惠券领取记录
*/
PatientCouponReceiveInfoVO selectPatientCouponReceive(@Param("patientId") Long patientId, @Param("couponId") Long couponId);
/**
*
* @param patientId 用户id
* @param receiveSource 优惠券状态
* @return int
*/
int getCouponReceiveByReceiveSource(@Param("patientId") Long patientId, @Param("receiveSource") String receiveSource);
}

View File

@ -363,4 +363,12 @@
where pcr.patient_id = #{patientId}
and pcr.coupon_id = #{couponId}
</select>
<select id="getCouponReceiveByReceiveSource" resultType="java.lang.Integer">
select
count(1)
where
patient_id = #{patientId}
and receive_source = #{receiveSource}
</select>
</mapper>