123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- package com.ygj.yuemum.service.college;
- import com.ygj.yuemum.component.Constant;
- import com.ygj.yuemum.controller.global.WeChatInfoController;
- import com.ygj.yuemum.dao.college.CollegeUserPointsDao;
- import com.ygj.yuemum.domain.college.*;
- import com.ygj.yuemum.domain.customer.CustomerBooking;
- import com.ygj.yuemum.domain.wxmini.WXUser;
- import com.ygj.yuemum.service.coupon.CouponCreateService;
- import com.ygj.yuemum.service.customer.CustomerBookingService;
- import com.ygj.yuemum.service.wxmini.WXUserService;
- import com.ygj.yuemum.utils.DateUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.LinkedHashMap;
- import java.util.List;
- @Service
- public class CollegeUserPointsService {
- @Autowired
- private CollegeUserPointsDao collegeUserPointsDao;
- @Autowired
- private WXUserService wxUserService;
- @Autowired
- private CollegePresentRuleService collegePresentRuleService;
- @Autowired
- private CollegeCurriculumCoreService collegeCurriculumCoreService;
- @Autowired
- private CollegeCurriculumPracticeService collegeCurriculumPracticeService;
- @Autowired
- private CollegeCurriculumExperienceService collegeCurriculumExperienceService;
- @Autowired
- private CollegePointsDetailService collegePointsDetailService;
- @Autowired
- private CustomerBookingService customerBookingService;
- @Autowired
- private WeChatInfoController weChatInfoController;
- @Autowired
- private CouponCreateService couponCreateService;
- public Integer LMP = Constant.LMP;
- public Integer AGE = Constant.AGE;
- public List<CollegeUserPoints> getCollegeUserPoints() {
- List<CollegeUserPoints> collegeUserPoints = collegeUserPointsDao.getAll();
- return collegeUserPoints;
- }
- public CollegeUserPoints getCollegeUserPoint(Integer id) {
- CollegeUserPoints collegeUserPoints = collegeUserPointsDao.selectByPrimaryKey(id);
- return collegeUserPoints;
- }
- public int addCollegeUserPoints(CollegeUserPoints collegeUserPoints) {
- return collegeUserPointsDao.insertSelective(collegeUserPoints);
- }
- public int deleteCollegeUserPoints(Integer id) {
- return collegeUserPointsDao.deleteByPrimaryKey(id);
- }
- public int updateCollegeUserPoints(CollegeUserPoints collegeUserPoints) {
- return collegeUserPointsDao.updateByPrimaryKeySelective(collegeUserPoints);
- }
- public LinkedHashMap<String, Object> QueryUserPoints(String openid,String city) {
- LinkedHashMap<String, Object> tableData = new LinkedHashMap<>();
- WXUser wxUser = wxUserService.getWXUser(openid);
- tableData.put("stage", null);
- tableData.put("stage_date", null);
- if (wxUser != null && wxUser.getXu_content_type() != null && wxUser.getXu_content_date() != null &&wxUser.getXu_phone() != null) {
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- SimpleDateFormat ldf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date dateNow = new Date();
- Date getDate = sdf.parse(wxUser.getXu_content_date());
- CollegeCurriculumCore collegeCurriculumCoreQuery = new CollegeCurriculumCore();
- CollegeCurriculumPractice collegeCurriculumPracticeQuery = new CollegeCurriculumPractice();
- CollegeCurriculumExperience collegeCurriculumExperienceQuery = new CollegeCurriculumExperience();
- CollegePointsDetail collegePointsDetail = new CollegePointsDetail();
- if (wxUser.getXu_content_type().equals("B01")) { //育儿
- if (DateUtil.getMonthDiff(dateNow, getDate) + 1 < 0) {
- //不在育儿期内
- return tableData;
- } else if (DateUtil.getMonthDiff(dateNow, getDate) + 1 > AGE) {
- //超过育儿期
- return tableData;
- } else {
- tableData.put("stage_step", DateUtil.getMonthDiff(dateNow, getDate) + 1);
- collegeCurriculumCoreQuery.setC_type("B01");
- collegeCurriculumCoreQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
- collegeCurriculumPracticeQuery.setC_type("B01");
- collegeCurriculumPracticeQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
- collegeCurriculumExperienceQuery.setC_type("B01");
- collegeCurriculumExperienceQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
- }
- } else if (wxUser.getXu_content_type().equals("P01")) { //孕周
- if (DateUtil.getWeekDiff(dateNow, getDate) < 0) {
- // 不在孕周内
- return tableData;
- } else if (DateUtil.getWeekDiff(dateNow, getDate) > LMP) {
- //超过孕周
- return tableData;
- } else {
- tableData.put("stage_step", DateUtil.getWeekDiff(dateNow, getDate));
- collegeCurriculumCoreQuery.setC_type("P01");
- collegeCurriculumCoreQuery.setC_step(DateUtil.getWeekDiff(dateNow, getDate));
- collegeCurriculumPracticeQuery.setC_type("P01");
- collegeCurriculumPracticeQuery.setC_step(DateUtil.getWeekDiff(dateNow, getDate));
- collegeCurriculumExperienceQuery.setC_type("P01");
- collegeCurriculumExperienceQuery.setC_step(DateUtil.getWeekDiff(dateNow, getDate));
- }
- } else {
- return tableData;
- }
- tableData.put("stage", wxUser.getXu_content_type());
- tableData.put("stage_date", wxUser.getXu_content_date());
- tableData.put("avatar_url",wxUser.getXu_avatarUrl());
- //查询学分
- int point_available = 0;
- CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryUserPoints(openid);
- if (collegeUserPoints == null) {
- CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
- collegeUserPointsNew.setOpenid(openid);
- collegeUserPointsNew.setCredit_total(0);
- collegeUserPointsNew.setCredit_available(0);
- collegeUserPointsDao.insertSelective(collegeUserPointsNew);
- tableData.put("credit", 0);
- } else {
- tableData.put("credit", collegeUserPoints.getCredit_total());
- point_available = collegeUserPoints.getCredit_available();
- }
- //礼品领取情况
- List<CollegePresentRule> collegePresentRules = collegePresentRuleService.queryUserReceived(openid);
- for(CollegePresentRule collegePresentRule:collegePresentRules) {
- if(collegePresentRule.getReceived() != 1 && point_available >= collegePresentRule.getValue()) {
- //返回礼品内容
- tableData.put("surprise", "true");
- tableData.put("surprise_type", collegePresentRule.getType());
- tableData.put("surprise_name", collegePresentRule.getPresent_name());
- //自动发放礼品
- if (collegePresentRule.getType() == 1) {
- // 实物生成一条预约信息并发送通知
- CustomerBooking customerBooking = new CustomerBooking();
- customerBooking.setBk_branches_id(Integer.valueOf(city));
- customerBooking.setBk_phone(wxUser.getXu_phone());
- customerBooking.setBk_date(ldf.format(new Date()));
- customerBooking.setBk_type(6);
- customerBooking.setBk_desc(collegePresentRule.getPresent_name());
- customerBookingService.insertCustomerBooking(customerBooking);
- weChatInfoController.WXSendBookingMessage(customerBooking);
- collegePointsDetail.setContext(collegePresentRule.getPresent_name());
- } else {
- //优惠券领取接口 ???
- String cb_code = couponCreateService.couponIssue(collegePresentRule.getCoupon_cid(),wxUser.getXu_phone());
- collegePointsDetail.setContext(collegePresentRule.getPresent_name()+":"+cb_code);
- }
- //保存领取日志
- collegePointsDetail.setOpenid(openid);
- collegePointsDetail.setDate(ldf.format(new Date()));
- collegePointsDetail.setEvent_code(4);
- collegePointsDetail.setCredit(collegePresentRule.getValue() * -1);
- collegePointsDetailService.addCollegePointsDetail(collegePointsDetail);
- //更新学分
- collegeUserPoints.setCredit_available(collegeUserPoints.getCredit_available() - collegePresentRule.getValue());
- collegeUserPointsDao.updateByPrimaryKeySelective(collegeUserPoints);
- break;
- }
- }
- tableData.put("present_received", collegePresentRules);
- //常规课
- List<CollegeCurriculumCore> collegeCurriculumCores = collegeCurriculumCoreService.queryCoreByStep(collegeCurriculumCoreQuery);
- tableData.put("college_core",collegeCurriculumCores);
- //实践课
- collegeCurriculumPracticeQuery.setDeadline(sdf.format(new Date()));
- collegeCurriculumPracticeQuery.setCity(city);
- collegeCurriculumPracticeQuery.setStartdate(sdf.format(new Date()));
- List<CollegeCurriculumPractice> collegeCurriculumPractices = collegeCurriculumPracticeService.queryPracticeByStep(collegeCurriculumPracticeQuery);
- tableData.put("college_practice",collegeCurriculumPractices);
- //体验课
- collegeCurriculumExperienceQuery.setCity(city);
- List<CollegeCurriculumExperience> collegeCurriculumExperiences = collegeCurriculumExperienceService.queryExperienceByStep(collegeCurriculumExperienceQuery);
- tableData.put("college_experience",collegeCurriculumExperiences);
- return tableData;
- } catch (Exception ex) {
- ex.printStackTrace();
- return tableData;
- }
- } else {
- tableData.put("Tips", "请授权微信小程序用");
- return tableData;
- }
- }
- }
|