CollegeUserPointsService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.ygj.yuemum.service.college;
  2. import com.ygj.yuemum.component.Constant;
  3. import com.ygj.yuemum.controller.global.WeChatInfoController;
  4. import com.ygj.yuemum.dao.college.CollegeUserPointsDao;
  5. import com.ygj.yuemum.domain.college.*;
  6. import com.ygj.yuemum.domain.customer.CustomerBooking;
  7. import com.ygj.yuemum.domain.wxmini.WXUser;
  8. import com.ygj.yuemum.service.coupon.CouponCreateService;
  9. import com.ygj.yuemum.service.customer.CustomerBookingService;
  10. import com.ygj.yuemum.service.wxmini.WXUserService;
  11. import com.ygj.yuemum.utils.DateUtil;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Date;
  16. import java.util.LinkedHashMap;
  17. import java.util.List;
  18. @Service
  19. public class CollegeUserPointsService {
  20. @Autowired
  21. private CollegeUserPointsDao collegeUserPointsDao;
  22. @Autowired
  23. private WXUserService wxUserService;
  24. @Autowired
  25. private CollegePresentRuleService collegePresentRuleService;
  26. @Autowired
  27. private CollegeCurriculumCoreService collegeCurriculumCoreService;
  28. @Autowired
  29. private CollegeCurriculumPracticeService collegeCurriculumPracticeService;
  30. @Autowired
  31. private CollegeCurriculumExperienceService collegeCurriculumExperienceService;
  32. @Autowired
  33. private CollegePointsDetailService collegePointsDetailService;
  34. @Autowired
  35. private CustomerBookingService customerBookingService;
  36. @Autowired
  37. private WeChatInfoController weChatInfoController;
  38. @Autowired
  39. private CouponCreateService couponCreateService;
  40. public Integer LMP = Constant.LMP;
  41. public Integer AGE = Constant.AGE;
  42. public List<CollegeUserPoints> getCollegeUserPoints() {
  43. List<CollegeUserPoints> collegeUserPoints = collegeUserPointsDao.getAll();
  44. return collegeUserPoints;
  45. }
  46. public CollegeUserPoints getCollegeUserPoint(Integer id) {
  47. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.selectByPrimaryKey(id);
  48. return collegeUserPoints;
  49. }
  50. public int addCollegeUserPoints(CollegeUserPoints collegeUserPoints) {
  51. return collegeUserPointsDao.insertSelective(collegeUserPoints);
  52. }
  53. public int deleteCollegeUserPoints(Integer id) {
  54. return collegeUserPointsDao.deleteByPrimaryKey(id);
  55. }
  56. public int updateCollegeUserPoints(CollegeUserPoints collegeUserPoints) {
  57. return collegeUserPointsDao.updateByPrimaryKeySelective(collegeUserPoints);
  58. }
  59. public LinkedHashMap<String, Object> QueryUserPoints(String openid,String city) {
  60. LinkedHashMap<String, Object> tableData = new LinkedHashMap<>();
  61. WXUser wxUser = wxUserService.getWXUser(openid);
  62. tableData.put("stage", null);
  63. tableData.put("stage_date", null);
  64. if (wxUser != null && wxUser.getXu_content_type() != null && wxUser.getXu_content_date() != null &&wxUser.getXu_phone() != null) {
  65. try {
  66. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  67. SimpleDateFormat ldf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  68. Date dateNow = new Date();
  69. Date getDate = sdf.parse(wxUser.getXu_content_date());
  70. CollegeCurriculumCore collegeCurriculumCoreQuery = new CollegeCurriculumCore();
  71. CollegeCurriculumPractice collegeCurriculumPracticeQuery = new CollegeCurriculumPractice();
  72. CollegeCurriculumExperience collegeCurriculumExperienceQuery = new CollegeCurriculumExperience();
  73. CollegePointsDetail collegePointsDetail = new CollegePointsDetail();
  74. if (wxUser.getXu_content_type().equals("B01")) { //育儿
  75. if (DateUtil.getMonthDiff(dateNow, getDate) + 1 < 0) {
  76. //不在育儿期内
  77. return tableData;
  78. } else if (DateUtil.getMonthDiff(dateNow, getDate) + 1 > AGE) {
  79. //超过育儿期
  80. return tableData;
  81. } else {
  82. tableData.put("stage_step", DateUtil.getMonthDiff(dateNow, getDate) + 1);
  83. collegeCurriculumCoreQuery.setC_type("B01");
  84. collegeCurriculumCoreQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
  85. collegeCurriculumPracticeQuery.setC_type("B01");
  86. collegeCurriculumPracticeQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
  87. collegeCurriculumExperienceQuery.setC_type("B01");
  88. collegeCurriculumExperienceQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
  89. }
  90. } else if (wxUser.getXu_content_type().equals("P01")) { //孕周
  91. if (DateUtil.getWeekDiff(dateNow, getDate) < 0) {
  92. // 不在孕周内
  93. return tableData;
  94. } else if (DateUtil.getWeekDiff(dateNow, getDate) > LMP) {
  95. //超过孕周
  96. return tableData;
  97. } else {
  98. tableData.put("stage_step", DateUtil.getWeekDiff(dateNow, getDate));
  99. collegeCurriculumCoreQuery.setC_type("P01");
  100. collegeCurriculumCoreQuery.setC_step(DateUtil.getWeekDiff(dateNow, getDate));
  101. collegeCurriculumPracticeQuery.setC_type("P01");
  102. collegeCurriculumPracticeQuery.setC_step(DateUtil.getWeekDiff(dateNow, getDate));
  103. collegeCurriculumExperienceQuery.setC_type("P01");
  104. collegeCurriculumExperienceQuery.setC_step(DateUtil.getWeekDiff(dateNow, getDate));
  105. }
  106. } else {
  107. return tableData;
  108. }
  109. tableData.put("stage", wxUser.getXu_content_type());
  110. tableData.put("stage_date", wxUser.getXu_content_date());
  111. tableData.put("avatar_url",wxUser.getXu_avatarUrl());
  112. //查询学分
  113. int point_available = 0;
  114. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryUserPoints(openid);
  115. if (collegeUserPoints == null) {
  116. CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
  117. collegeUserPointsNew.setOpenid(openid);
  118. collegeUserPointsNew.setCredit_total(0);
  119. collegeUserPointsNew.setCredit_available(0);
  120. collegeUserPointsDao.insertSelective(collegeUserPointsNew);
  121. tableData.put("credit", 0);
  122. } else {
  123. tableData.put("credit", collegeUserPoints.getCredit_total());
  124. point_available = collegeUserPoints.getCredit_available();
  125. }
  126. //礼品领取情况
  127. List<CollegePresentRule> collegePresentRules = collegePresentRuleService.queryUserReceived(openid);
  128. for(CollegePresentRule collegePresentRule:collegePresentRules) {
  129. if(collegePresentRule.getReceived() != 1 && point_available >= collegePresentRule.getValue()) {
  130. //返回礼品内容
  131. tableData.put("surprise", "true");
  132. tableData.put("surprise_type", collegePresentRule.getType());
  133. tableData.put("surprise_name", collegePresentRule.getPresent_name());
  134. //自动发放礼品
  135. if (collegePresentRule.getType() == 1) {
  136. // 实物生成一条预约信息并发送通知
  137. CustomerBooking customerBooking = new CustomerBooking();
  138. customerBooking.setBk_branches_id(Integer.valueOf(city));
  139. customerBooking.setBk_phone(wxUser.getXu_phone());
  140. customerBooking.setBk_date(ldf.format(new Date()));
  141. customerBooking.setBk_type(6);
  142. customerBooking.setBk_desc(collegePresentRule.getPresent_name());
  143. customerBookingService.insertCustomerBooking(customerBooking);
  144. weChatInfoController.WXSendBookingMessage(customerBooking);
  145. collegePointsDetail.setContext(collegePresentRule.getPresent_name());
  146. } else {
  147. //优惠券领取接口 ???
  148. String cb_code = couponCreateService.couponIssue(collegePresentRule.getCoupon_cid(),wxUser.getXu_phone());
  149. collegePointsDetail.setContext(collegePresentRule.getPresent_name()+":"+cb_code);
  150. }
  151. //保存领取日志
  152. collegePointsDetail.setOpenid(openid);
  153. collegePointsDetail.setDate(ldf.format(new Date()));
  154. collegePointsDetail.setEvent_code(4);
  155. collegePointsDetail.setCredit(collegePresentRule.getValue() * -1);
  156. collegePointsDetailService.addCollegePointsDetail(collegePointsDetail);
  157. //更新学分
  158. collegeUserPoints.setCredit_available(collegeUserPoints.getCredit_available() - collegePresentRule.getValue());
  159. collegeUserPointsDao.updateByPrimaryKeySelective(collegeUserPoints);
  160. break;
  161. }
  162. }
  163. tableData.put("present_received", collegePresentRules);
  164. //常规课
  165. List<CollegeCurriculumCore> collegeCurriculumCores = collegeCurriculumCoreService.queryCoreByStep(collegeCurriculumCoreQuery);
  166. tableData.put("college_core",collegeCurriculumCores);
  167. //实践课
  168. collegeCurriculumPracticeQuery.setDeadline(sdf.format(new Date()));
  169. collegeCurriculumPracticeQuery.setCity(city);
  170. collegeCurriculumPracticeQuery.setStartdate(sdf.format(new Date()));
  171. List<CollegeCurriculumPractice> collegeCurriculumPractices = collegeCurriculumPracticeService.queryPracticeByStep(collegeCurriculumPracticeQuery);
  172. tableData.put("college_practice",collegeCurriculumPractices);
  173. //体验课
  174. collegeCurriculumExperienceQuery.setCity(city);
  175. List<CollegeCurriculumExperience> collegeCurriculumExperiences = collegeCurriculumExperienceService.queryExperienceByStep(collegeCurriculumExperienceQuery);
  176. tableData.put("college_experience",collegeCurriculumExperiences);
  177. return tableData;
  178. } catch (Exception ex) {
  179. ex.printStackTrace();
  180. return tableData;
  181. }
  182. } else {
  183. tableData.put("Tips", "请授权微信小程序用");
  184. return tableData;
  185. }
  186. }
  187. }