ActivityUtil.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.iamberry.wechat.service;
  2. import com.iamberry.wechat.core.entity.activity.ActivityDate;
  3. import com.iamberry.wechat.core.entity.admin.FullReduction;
  4. import com.iamberry.wechat.face.admin.SystemService;
  5. import com.iamberry.wechat.face.member.MemberService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Component;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. /**
  11. * 上朵活动类
  12. */
  13. @Component
  14. public class ActivityUtil {
  15. @Autowired
  16. private SystemService systemService;
  17. @Autowired
  18. private MemberService memberService;
  19. private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  20. /**
  21. * 获取日期
  22. * @param type
  23. * @return
  24. */
  25. private ActivityDate initDate(Integer type){
  26. ActivityDate activityDate = new ActivityDate();
  27. try {
  28. switch (type){
  29. case 1:
  30. String begin = systemService.selectOneShopRuleByIdDynamic(236).getRuleDesc();
  31. activityDate.setBeginDate(sd.parse(begin)); ;
  32. String end = systemService.selectOneShopRuleByIdDynamic(237).getRuleDesc();
  33. activityDate.setEndDate(sd.parse(end));
  34. break;
  35. default:
  36. activityDate = null;
  37. break;
  38. }
  39. }catch (Exception e){
  40. activityDate = null;
  41. e.printStackTrace();
  42. }
  43. return activityDate;
  44. }
  45. /**
  46. * 判断是否在注销时间内
  47. * @return 期限内true;
  48. */
  49. public ActivityDate isActivity(){
  50. ActivityDate activityDate = initDate(1);
  51. activityDate.setRemark("618活动");
  52. if(activityDate == null){
  53. activityDate.setStatus(false);
  54. }
  55. Date date = new Date();
  56. if (activityDate.getBeginDate().before(date) && date.before(activityDate.getEndDate())){ //beginDate 比 date 早? true :false
  57. activityDate.setStatus(true);
  58. return activityDate;
  59. }
  60. activityDate.setStatus(false);
  61. return activityDate;
  62. }
  63. /**
  64. * 查询用户是否满赠优惠
  65. * @return true/false;
  66. */
  67. public boolean getFullReduction(String openid){
  68. if(openid == null || openid.equals("")){
  69. return false;
  70. }
  71. FullReduction fullReduction = memberService.getFullReduction(openid);
  72. if(fullReduction == null){
  73. return false;
  74. }else{
  75. return true;
  76. }
  77. }
  78. }