package com.iamberry.wechat.service; import com.iamberry.wechat.core.entity.activity.ActivityDate; import com.iamberry.wechat.core.entity.admin.FullReduction; import com.iamberry.wechat.face.admin.SystemService; import com.iamberry.wechat.face.member.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; import java.util.Date; /** * 上朵活动类 */ @Component public class ActivityUtil { @Autowired private SystemService systemService; @Autowired private MemberService memberService; private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /** * 获取日期 * @param type * @return */ private ActivityDate initDate(Integer type){ ActivityDate activityDate = new ActivityDate(); try { switch (type){ case 1: String begin = systemService.selectOneShopRuleByIdDynamic(236).getRuleDesc(); activityDate.setBeginDate(sd.parse(begin)); ; String end = systemService.selectOneShopRuleByIdDynamic(237).getRuleDesc(); activityDate.setEndDate(sd.parse(end)); break; default: activityDate = null; break; } }catch (Exception e){ activityDate = null; e.printStackTrace(); } return activityDate; } /** * 判断是否在注销时间内 * @return 期限内true; */ public ActivityDate isActivity(){ ActivityDate activityDate = initDate(1); activityDate.setRemark("618活动"); if(activityDate == null){ activityDate.setStatus(false); } Date date = new Date(); if (activityDate.getBeginDate().before(date) && date.before(activityDate.getEndDate())){ //beginDate 比 date 早? true :false activityDate.setStatus(true); return activityDate; } activityDate.setStatus(false); return activityDate; } /** * 查询用户是否满赠优惠 * @return true/false; */ public boolean getFullReduction(String openid){ if(openid == null || openid.equals("")){ return false; } FullReduction fullReduction = memberService.getFullReduction(openid); if(fullReduction == null){ return false; }else{ return true; } } }