123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- 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 com.ygj.yuemum.utils.DistanceUtil;
- 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;
- @Autowired
- private CollegeBookingService collegeBookingService;
- @Autowired
- private CollegeLearningDetailService collegeLearningDetailService;
- 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 int updatePointsByTest(CollegePointsDetail collegePointsDetail) {
- return collegeUserPointsDao.updatePointsByTest(collegePointsDetail);
- }
- public CollegeUserPoints queryOneUserPoints(String openid) {
- return collegeUserPointsDao.queryOneUserPoints(openid);
- }
- 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_phone() != null) {
- if (wxUser.getXu_content_type() != null && wxUser.getXu_content_date() != 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();
- collegeCurriculumCoreQuery.setOpenid(openid);
- collegeCurriculumPracticeQuery.setOpenid(openid);
- collegeCurriculumExperienceQuery.setOpenid(openid);
- CollegePointsDetail collegePointsDetail = new CollegePointsDetail();
- if (wxUser.getXu_content_type().equals("B01")) { //育儿
- if (dateNow.getTime() < getDate.getTime()) {
- //还没出生
- 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 (dateNow.getTime() < getDate.getTime()) {
- if (LMP - DateUtil.getWeekDiff(dateNow, getDate) < 0) {
- return tableData; //还没怀孕
- } else {
- tableData.put("stage_step", LMP - DateUtil.getWeekDiff(dateNow, getDate));
- collegeCurriculumCoreQuery.setC_type("P01");
- collegeCurriculumCoreQuery.setC_step(LMP - DateUtil.getWeekDiff(dateNow, getDate));
- collegeCurriculumPracticeQuery.setC_type("P01");
- collegeCurriculumPracticeQuery.setC_step(LMP - DateUtil.getWeekDiff(dateNow, getDate));
- collegeCurriculumExperienceQuery.setC_type("P01");
- collegeCurriculumExperienceQuery.setC_step(LMP - DateUtil.getWeekDiff(dateNow, getDate));
- }
- } else {
- return tableData;
- }
- } 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.queryOneUserPoints(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_total();
- }
- //礼品领取情况
- 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);
- collegePointsDetail.setRule_id(collegePresentRule.getId());
- 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);
- for (CollegeCurriculumCore collegeCurriculumCore : collegeCurriculumCores) {
- if (collegeCurriculumCore.getStatus() != null && collegeCurriculumCore.getStatus().equals("9")) { //1-已预约,2-学习中,3-已过期, 9-已完成
- collegeCurriculumCore.setStatus("已完成");
- } else if (collegeCurriculumCore.getStatus() != null && collegeCurriculumCore.getStatus().equals("2")) {
- collegeCurriculumCore.setStatus("待完成");
- } else {
- if (collegeCurriculumCore.getC_step() >= DateUtil.getWeekDiff(dateNow, getDate)) {
- collegeCurriculumCore.setStatus("待完成");
- } else {
- collegeCurriculumCore.setStatus("未完成");
- }
- }
- }
- 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);
- //判断日期
- for (CollegeCurriculumPractice collegeCurriculumPractice : collegeCurriculumPractices) {
- Date deadLine = ldf.parse(collegeCurriculumPractice.getDeadline());
- Date now = new Date();
- if (collegeCurriculumPractice.getLearningStatus() != null && collegeCurriculumPractice.getLearningStatus().equals("9")) {
- //已完成
- collegeCurriculumPractice.setStatus("已完成");
- //已完成
- collegeCurriculumPractice.setLearningStatus("已完成");
- } else if (collegeCurriculumPractice.getLearningStatus() != null && collegeCurriculumPractice.getLearningStatus().equals("1")) {
- if (now.getTime() > deadLine.getTime()) {
- //未完成
- collegeCurriculumPractice.setStatus("未完成");
- //已过期
- collegeCurriculumPractice.setLearningStatus("已过期");
- } else {
- //待完成
- collegeCurriculumPractice.setStatus("已报名");
- //查看报名
- collegeCurriculumPractice.setLearningStatus("查看报名");
- }
- } else {
- if (now.getTime() > deadLine.getTime()) {
- //未完成
- collegeCurriculumPractice.setStatus("未完成");
- //已过期
- collegeCurriculumPractice.setLearningStatus("已过期");
- } else if (collegeCurriculumPractice.getPcount() >= 99) {
- //未完成
- collegeCurriculumPractice.setStatus("未完成");
- //已约满
- collegeCurriculumPractice.setLearningStatus("已约满");
- } else {
- //待完成
- collegeCurriculumPractice.setStatus("待完成");
- //立即报名
- collegeCurriculumPractice.setLearningStatus("立即报名");
- }
- }
- }
- tableData.put("college_practice", collegeCurriculumPractices);
- //体验课
- collegeCurriculumExperienceQuery.setCity(city);
- List<CollegeCurriculumExperience> collegeCurriculumExperiences = collegeCurriculumExperienceService.queryExperienceByStep(collegeCurriculumExperienceQuery);
- for (CollegeCurriculumExperience collegeCurriculumExperience : collegeCurriculumExperiences) {
- if (collegeCurriculumExperience.getStatus() != null && collegeCurriculumExperience.getStatus().equals("9")) { //1-已预约,2-学习中,3-已过期, 9-已完成
- collegeCurriculumExperience.setStatus("已完成");
- collegeCurriculumExperience.setLearningStatus("已完成");
- } else if (collegeCurriculumExperience.getStatus() != null && collegeCurriculumExperience.getStatus().equals("1")) {
- collegeCurriculumExperience.setStatus("已预约");
- collegeCurriculumExperience.setLearningStatus("查看预约");
- } else {
- collegeCurriculumExperience.setStatus("未完成");
- collegeCurriculumExperience.setLearningStatus("立即预约");
- }
- }
- tableData.put("college_experience", collegeCurriculumExperiences);
- return tableData;
- } catch (Exception ex) {
- ex.printStackTrace();
- return tableData;
- }
- } else {
- tableData.put("status", "5"); //没有设置日期
- return tableData;
- }
- } else {
- tableData.put("status", "6"); //没有授权手机号
- return tableData;
- }
- }
- public int getPointsByOffline(String openid, String c_code, String lat, String lon) {
- //51-参数错误 52-没有预约 53-不在范围 54-已完成
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (c_code.indexOf("College") == -1) {
- return 51; //参数错误
- }
- CollegeBooking collegeBooking = new CollegeBooking();
- collegeBooking.setOpenid(openid);
- collegeBooking.setCollege_code(c_code.substring(8, c_code.length()));
- String lat_l, lon_l;
- int credit = 0;
- if (collegeBookingService.checkBooking(collegeBooking) != null) {
- if (c_code.substring(7, 1) == "P") {
- CollegeCurriculumPractice collegeCurriculumPractice = collegeCurriculumPracticeService.getPracticeByCode(c_code);
- lat_l = collegeCurriculumPractice.getMi_latitude();
- lon_l = collegeCurriculumPractice.getMi_longitude();
- credit = collegeCurriculumPractice.getCredit();
- } else if (c_code.substring(7, 1) == "E") {
- CollegeCurriculumExperience collegeCurriculumExperience = collegeCurriculumExperienceService.getExperienceByCode(c_code.substring(8, c_code.length()));
- lat_l = collegeCurriculumExperience.getLatitude();
- lon_l = collegeCurriculumExperience.getLongitude();
- credit = collegeCurriculumExperience.getCredit();
- } else {
- return 51; //参数错误
- }
- DistanceUtil distanceUtil = new DistanceUtil();
- double distance = distanceUtil.GetDistance(Double.parseDouble(lat_l), Double.parseDouble(lon_l), Double.parseDouble(lat), Double.parseDouble(lon));
- if (distance > 500) {
- return 53; //不在范围内
- } else {
- //判断是否已完成
- CollegeLearningDetail collegeLearningDetail = new CollegeLearningDetail();
- collegeLearningDetail.setOpen_id(openid);
- collegeLearningDetail.setC_code(c_code.substring(8, c_code.length()));
- CollegeLearningDetail collegeLearningDetailC = collegeLearningDetailService.checkCorePositive(collegeLearningDetail);
- if (collegeLearningDetailC.getStatus() != 9) {
- collegeLearningDetailC.setDate(sdf.format(new Date()));
- collegeLearningDetailC.setStatus(9);
- collegeLearningDetailC.setCredit(credit);
- collegeLearningDetailService.addCollegeLearningDetail(collegeLearningDetailC);
- } else {
- return 54; //已完成
- }
- //判断是否已经学习 增加学分
- CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryOneUserPoints(openid);
- if (collegeUserPoints == null) {
- CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
- collegeUserPointsNew.setOpenid(openid);
- collegeUserPointsNew.setCredit_total(credit);
- collegeUserPointsNew.setCredit_available(credit);
- } else {
- CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
- collegeUserPointsNew.setOpenid(openid);
- collegeUserPointsNew.setCredit_total(collegeUserPoints.getCredit_total() + credit);
- collegeUserPointsNew.setCredit_available(collegeUserPoints.getCredit_available() + credit);
- }
- return 1;
- }
- } else {
- return 52; //没有预约
- }
- }
- }
|