CollegeUserPointsService.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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.WXMktInfo;
  8. import com.ygj.yuemum.domain.wxmini.WXUser;
  9. import com.ygj.yuemum.service.coupon.CouponCreateService;
  10. import com.ygj.yuemum.service.customer.CustomerBookingService;
  11. import com.ygj.yuemum.service.wxmini.WXMktInfoService;
  12. import com.ygj.yuemum.service.wxmini.WXUserService;
  13. import com.ygj.yuemum.utils.DateUtil;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import com.ygj.yuemum.utils.DistanceUtil;
  17. import java.text.SimpleDateFormat;
  18. import java.util.Date;
  19. import java.util.LinkedHashMap;
  20. import java.util.LinkedList;
  21. import java.util.List;
  22. @Service
  23. public class CollegeUserPointsService {
  24. @Autowired
  25. private CollegeUserPointsDao collegeUserPointsDao;
  26. @Autowired
  27. private WXUserService wxUserService;
  28. @Autowired
  29. private CollegePresentCreditService collegePresentCreditService;
  30. @Autowired
  31. private CollegeCurriculumCoreService collegeCurriculumCoreService;
  32. @Autowired
  33. private CollegeCurriculumPracticeService collegeCurriculumPracticeService;
  34. @Autowired
  35. private CollegeCurriculumExperienceService collegeCurriculumExperienceService;
  36. @Autowired
  37. private CollegePointsDetailService collegePointsDetailService;
  38. @Autowired
  39. private CustomerBookingService customerBookingService;
  40. @Autowired
  41. private WeChatInfoController weChatInfoController;
  42. @Autowired
  43. private CouponCreateService couponCreateService;
  44. @Autowired
  45. private CollegeBookingService collegeBookingService;
  46. @Autowired
  47. private CollegeLearningDetailService collegeLearningDetailService;
  48. @Autowired
  49. private CollegeScholarshipsDetailService collegeScholarshipsDetailService;
  50. @Autowired
  51. private CollegePresentScholarshipsService collegePresentScholarshipsService;
  52. @Autowired
  53. private CollegeUserLevelService collegeUserLevelService;
  54. @Autowired
  55. private WXMktInfoService wxMktInfoService;
  56. public Integer LMP = Constant.LMP;
  57. public Integer AGE = Constant.AGE;
  58. public List<CollegeUserPoints> getCollegeUserPoints() {
  59. List<CollegeUserPoints> collegeUserPoints = collegeUserPointsDao.getAll();
  60. return collegeUserPoints;
  61. }
  62. public CollegeUserPoints getCollegeUserPoint(Integer id) {
  63. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.selectByPrimaryKey(id);
  64. return collegeUserPoints;
  65. }
  66. public int addCollegeUserPoints(CollegeUserPoints collegeUserPoints) {
  67. return collegeUserPointsDao.insertSelective(collegeUserPoints);
  68. }
  69. public int deleteCollegeUserPoints(Integer id) {
  70. return collegeUserPointsDao.deleteByPrimaryKey(id);
  71. }
  72. public int updateCollegeUserPoints(CollegeUserPoints collegeUserPoints) {
  73. return collegeUserPointsDao.updateByPrimaryKeySelective(collegeUserPoints);
  74. }
  75. public int updatePointsByTest(CollegePointsDetail collegePointsDetail) {
  76. return collegeUserPointsDao.updatePointsByTest(collegePointsDetail);
  77. }
  78. public int updateScholarships(CollegeUserPoints collegePointsDetail) {
  79. return collegeUserPointsDao.updateScholarships(collegePointsDetail);
  80. }
  81. public CollegeUserPoints queryOneUserPoints(String openid) {
  82. return collegeUserPointsDao.queryOneUserPoints(openid);
  83. }
  84. public LinkedHashMap<String, Object> queryUserPoints(String openid, String city) {
  85. LinkedHashMap<String, Object> tableData = new LinkedHashMap<>();
  86. WXUser wxUser = wxUserService.getWXUser(openid);
  87. tableData.put("stage", null);
  88. tableData.put("stage_date", null);
  89. if (wxUser != null && wxUser.getXu_phone() != null) {
  90. if (wxUser.getXu_content_type() != null && wxUser.getXu_content_date() != null) {
  91. try {
  92. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  93. SimpleDateFormat ldf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  94. Date dateNow = new Date();
  95. Date getDate = sdf.parse(wxUser.getXu_content_date());
  96. CollegeCurriculumCore collegeCurriculumCoreQuery = new CollegeCurriculumCore();
  97. CollegeCurriculumPractice collegeCurriculumPracticeQuery = new CollegeCurriculumPractice();
  98. CollegeCurriculumExperience collegeCurriculumExperienceQuery = new CollegeCurriculumExperience();
  99. collegeCurriculumCoreQuery.setOpenid(openid);
  100. collegeCurriculumPracticeQuery.setOpenid(openid);
  101. collegeCurriculumExperienceQuery.setOpenid(openid);
  102. CollegePointsDetail collegePointsDetail = new CollegePointsDetail();
  103. if (wxUser.getXu_content_type().equals("B01")) { //育儿
  104. if (dateNow.getTime() < getDate.getTime()) {
  105. //还没出生
  106. return tableData;
  107. } else {
  108. if (DateUtil.getMonthDiff(dateNow, getDate) + 1 > AGE) {
  109. return tableData;
  110. } else {
  111. tableData.put("stage_step", DateUtil.getMonthDiff(dateNow, getDate) + 1);
  112. collegeCurriculumCoreQuery.setC_type("B01");
  113. collegeCurriculumCoreQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
  114. collegeCurriculumPracticeQuery.setC_type("B01");
  115. collegeCurriculumPracticeQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
  116. collegeCurriculumExperienceQuery.setC_type("B01");
  117. collegeCurriculumExperienceQuery.setC_step(DateUtil.getMonthDiff(dateNow, getDate) + 1);
  118. }
  119. }
  120. } else if (wxUser.getXu_content_type().equals("P01")) { //孕周
  121. if (dateNow.getTime() < getDate.getTime()) {
  122. if (LMP - DateUtil.getWeekDiff(dateNow, getDate) < 0) {
  123. return tableData; //还没怀孕
  124. } else {
  125. tableData.put("stage_step", LMP - DateUtil.getWeekDiff(dateNow, getDate));
  126. collegeCurriculumCoreQuery.setC_type("P01");
  127. collegeCurriculumCoreQuery.setC_step(LMP - DateUtil.getWeekDiff(dateNow, getDate));
  128. collegeCurriculumPracticeQuery.setC_type("P01");
  129. collegeCurriculumPracticeQuery.setC_step(LMP - DateUtil.getWeekDiff(dateNow, getDate));
  130. collegeCurriculumExperienceQuery.setC_type("P01");
  131. collegeCurriculumExperienceQuery.setC_step(LMP - DateUtil.getWeekDiff(dateNow, getDate));
  132. }
  133. } else {
  134. return tableData;
  135. }
  136. } else {
  137. return tableData;
  138. }
  139. tableData.put("stage", wxUser.getXu_content_type());
  140. tableData.put("stage_date", wxUser.getXu_content_date());
  141. tableData.put("avatar_url", wxUser.getXu_avatarUrl());
  142. //查询学分
  143. int point_available = 0;
  144. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryOneUserPoints(openid);
  145. if (collegeUserPoints == null) {
  146. CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
  147. collegeUserPointsNew.setOpenid(openid);
  148. collegeUserPointsNew.setCredit_total(0);
  149. collegeUserPointsNew.setCredit_available(0);
  150. collegeUserPointsDao.insertSelective(collegeUserPointsNew);
  151. tableData.put("credit", 0);
  152. } else {
  153. tableData.put("credit", collegeUserPoints.getCredit_total());
  154. point_available = collegeUserPoints.getCredit_total();
  155. }
  156. //查询奖学金
  157. tableData.put("scholarships", collegeUserPoints.getScholarships_available());
  158. //礼品领取情况
  159. List<CollegePresentCredit> collegePresentCredits = collegePresentCreditService.queryUserReceived(openid);
  160. for (CollegePresentCredit collegePresentCredit : collegePresentCredits) {
  161. if (collegePresentCredit.getReceived() != 1 && point_available >= collegePresentCredit.getValue()) {
  162. //返回礼品内容
  163. tableData.put("surprise", "true");
  164. tableData.put("surprise_type", collegePresentCredit.getType());
  165. tableData.put("surprise_name", collegePresentCredit.getPresent_name());
  166. //自动发放礼品
  167. if (collegePresentCredit.getType() == 1) {
  168. // 实物生成一条预约信息并发送通知
  169. CustomerBooking customerBooking = new CustomerBooking();
  170. customerBooking.setBk_branches_id(Integer.valueOf(city));
  171. customerBooking.setBk_phone(wxUser.getXu_phone());
  172. customerBooking.setBk_date(ldf.format(new Date()));
  173. customerBooking.setBk_type(6);
  174. customerBooking.setBk_desc(collegePresentCredit.getPresent_name());
  175. customerBookingService.insertCustomerBooking(customerBooking);
  176. weChatInfoController.WXSendBookingMessage(customerBooking);
  177. collegePointsDetail.setContext(collegePresentCredit.getPresent_name());
  178. } else {
  179. //优惠券领取接口
  180. String cb_code = couponCreateService.couponIssue(collegePresentCredit.getCoupon_cid(), wxUser.getXu_phone(),"College");
  181. collegePointsDetail.setContext(collegePresentCredit.getPresent_name() + ":" + cb_code);
  182. }
  183. //保存领取日志
  184. collegePointsDetail.setOpenid(openid);
  185. collegePointsDetail.setDate(ldf.format(new Date()));
  186. collegePointsDetail.setEvent_code(4);
  187. collegePointsDetail.setCredit(collegePresentCredit.getValue() * -1);
  188. collegePointsDetail.setRule_id(collegePresentCredit.getId());
  189. collegePointsDetailService.addCollegePointsDetail(collegePointsDetail);
  190. //更新学分 学分不减
  191. // collegeUserPoints.setCredit_available(collegeUserPoints.getCredit_available() - collegePresentRule.getValue());
  192. // collegeUserPointsDao.updateByPrimaryKeySelective(collegeUserPoints);
  193. break;
  194. }
  195. }
  196. tableData.put("present_received", collegePresentCredits);
  197. //常规课
  198. List<CollegeCurriculumCore> collegeCurriculumCores = collegeCurriculumCoreService.queryCoreByStep(collegeCurriculumCoreQuery);
  199. for (CollegeCurriculumCore collegeCurriculumCore : collegeCurriculumCores) {
  200. if (collegeCurriculumCore.getStatus() != null && collegeCurriculumCore.getStatus().equals("9")) { //1-已预约,2-学习中,3-已过期, 9-已完成
  201. collegeCurriculumCore.setStatus("已完成");
  202. //获取实际奖学金
  203. CollegeScholarshipsDetail collegeScholarshipsDetailQuery = new CollegeScholarshipsDetail();
  204. collegeScholarshipsDetailQuery.setOpenid(openid);
  205. collegeScholarshipsDetailQuery.setEvent_code(1);
  206. collegeScholarshipsDetailQuery.setType("learning");
  207. collegeScholarshipsDetailQuery.setCollege_type("core");
  208. collegeScholarshipsDetailQuery.setCollege_id(collegeCurriculumCore.getId());
  209. CollegeScholarshipsDetail collegeScholarshipsDetail = collegeScholarshipsDetailService.queryCollegeScholarships(collegeScholarshipsDetailQuery);
  210. if(collegeScholarshipsDetail != null) {
  211. collegeCurriculumCore.setScholarships(String.valueOf(collegeScholarshipsDetail.getScholarships()));
  212. } else {
  213. collegeCurriculumCore.setScholarships("0-100");
  214. }
  215. } else if (collegeCurriculumCore.getStatus() != null && collegeCurriculumCore.getStatus().equals("2")) {
  216. collegeCurriculumCore.setStatus("待完成");
  217. collegeCurriculumCore.setScholarships("0-100");
  218. } else {
  219. if (collegeCurriculumCore.getC_step() >= DateUtil.getWeekDiff(dateNow, getDate)) {
  220. collegeCurriculumCore.setStatus("待完成");
  221. collegeCurriculumCore.setScholarships("0-100");
  222. } else {
  223. collegeCurriculumCore.setStatus("未完成");
  224. collegeCurriculumCore.setScholarships("0");
  225. }
  226. }
  227. }
  228. tableData.put("college_core", collegeCurriculumCores);
  229. //实践课
  230. collegeCurriculumPracticeQuery.setDeadline(sdf.format(new Date()));
  231. collegeCurriculumPracticeQuery.setCity(city);
  232. collegeCurriculumPracticeQuery.setStartdate(sdf.format(new Date()));
  233. List<CollegeCurriculumPractice> collegeCurriculumPractices = collegeCurriculumPracticeService.queryPracticeByStep(collegeCurriculumPracticeQuery);
  234. //判断日期
  235. for (CollegeCurriculumPractice collegeCurriculumPractice : collegeCurriculumPractices) {
  236. Date deadLine = ldf.parse(collegeCurriculumPractice.getDeadline());
  237. Date now = new Date();
  238. if (collegeCurriculumPractice.getLearningStatus() != null && collegeCurriculumPractice.getLearningStatus().equals("9")) {
  239. //已完成
  240. collegeCurriculumPractice.setStatus("已完成");
  241. //已完成
  242. collegeCurriculumPractice.setLearningStatus("已完成");
  243. CollegeScholarshipsDetail collegeScholarshipsDetailQuery = new CollegeScholarshipsDetail();
  244. collegeScholarshipsDetailQuery.setOpenid(openid);
  245. collegeScholarshipsDetailQuery.setEvent_code(1);
  246. collegeScholarshipsDetailQuery.setType("learning");
  247. collegeScholarshipsDetailQuery.setCollege_type("practice");
  248. collegeScholarshipsDetailQuery.setCollege_id(collegeCurriculumPractice.getId());
  249. CollegeScholarshipsDetail collegeScholarshipsDetail = collegeScholarshipsDetailService.queryCollegeScholarships(collegeScholarshipsDetailQuery);
  250. if(collegeScholarshipsDetail != null) {
  251. collegeCurriculumPractice.setScholarships(String.valueOf(collegeScholarshipsDetail.getScholarships()));
  252. } else {
  253. collegeCurriculumPractice.setScholarships("0-100");
  254. }
  255. } else if (collegeCurriculumPractice.getLearningStatus() != null && collegeCurriculumPractice.getLearningStatus().equals("1")) {
  256. if (now.getTime() > deadLine.getTime()) {
  257. //未完成
  258. collegeCurriculumPractice.setStatus("未完成");
  259. //已过期
  260. collegeCurriculumPractice.setLearningStatus("已过期");
  261. collegeCurriculumPractice.setScholarships("0");
  262. } else {
  263. //待完成
  264. collegeCurriculumPractice.setStatus("已报名");
  265. //查看报名
  266. collegeCurriculumPractice.setLearningStatus("查看报名");
  267. collegeCurriculumPractice.setScholarships("0-100");
  268. }
  269. } else {
  270. if (now.getTime() > deadLine.getTime()) {
  271. //未完成
  272. collegeCurriculumPractice.setStatus("未完成");
  273. //已过期
  274. collegeCurriculumPractice.setLearningStatus("已过期");
  275. collegeCurriculumPractice.setScholarships("0");
  276. } else if (collegeCurriculumPractice.getPcount() >= 99) {
  277. //未完成
  278. collegeCurriculumPractice.setStatus("未完成");
  279. //已约满
  280. collegeCurriculumPractice.setLearningStatus("已约满");
  281. collegeCurriculumPractice.setScholarships("0-100");
  282. } else {
  283. //待完成
  284. collegeCurriculumPractice.setStatus("待完成");
  285. //立即报名
  286. collegeCurriculumPractice.setLearningStatus("立即报名");
  287. collegeCurriculumPractice.setScholarships("0-100");
  288. }
  289. }
  290. }
  291. tableData.put("college_practice", collegeCurriculumPractices);
  292. //体验课
  293. collegeCurriculumExperienceQuery.setCity(city);
  294. List<CollegeCurriculumExperience> collegeCurriculumExperiences = collegeCurriculumExperienceService.queryExperienceByStep(collegeCurriculumExperienceQuery);
  295. for (CollegeCurriculumExperience collegeCurriculumExperience : collegeCurriculumExperiences) {
  296. if (collegeCurriculumExperience.getStatus() != null && collegeCurriculumExperience.getStatus().equals("9")) { //1-已预约,2-学习中,3-已过期, 9-已完成
  297. collegeCurriculumExperience.setStatus("已完成");
  298. collegeCurriculumExperience.setLearningStatus("已完成");
  299. CollegeScholarshipsDetail collegeScholarshipsDetailQuery = new CollegeScholarshipsDetail();
  300. collegeScholarshipsDetailQuery.setOpenid(openid);
  301. collegeScholarshipsDetailQuery.setEvent_code(1);
  302. collegeScholarshipsDetailQuery.setType("learning");
  303. collegeScholarshipsDetailQuery.setCollege_type("experience");
  304. collegeScholarshipsDetailQuery.setCollege_id(collegeCurriculumExperience.getId());
  305. CollegeScholarshipsDetail collegeScholarshipsDetail = collegeScholarshipsDetailService.queryCollegeScholarships(collegeScholarshipsDetailQuery);
  306. if(collegeScholarshipsDetail != null) {
  307. collegeCurriculumExperience.setScholarships(String.valueOf(collegeScholarshipsDetail.getScholarships()));
  308. } else {
  309. collegeCurriculumExperience.setScholarships("0-100");
  310. }
  311. } else if (collegeCurriculumExperience.getStatus() != null && collegeCurriculumExperience.getStatus().equals("1")) {
  312. collegeCurriculumExperience.setStatus("已预约");
  313. collegeCurriculumExperience.setLearningStatus("查看预约");
  314. collegeCurriculumExperience.setScholarships("0-100");
  315. } else {
  316. collegeCurriculumExperience.setStatus("未完成");
  317. collegeCurriculumExperience.setLearningStatus("立即预约");
  318. collegeCurriculumExperience.setScholarships("0-100");
  319. }
  320. }
  321. tableData.put("college_experience", collegeCurriculumExperiences);
  322. return tableData;
  323. } catch (Exception ex) {
  324. ex.printStackTrace();
  325. return tableData;
  326. }
  327. } else {
  328. tableData.put("status", "5"); //没有设置日期
  329. return tableData;
  330. }
  331. } else {
  332. tableData.put("status", "6"); //没有授权手机号
  333. return tableData;
  334. }
  335. }
  336. public int getPointsByOffline(String openid, String c_code, String lat, String lon) {
  337. //51-参数错误 52-没有预约 53-不在范围 54-已完成
  338. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  339. String college_type = "";
  340. Integer id = null;
  341. if (c_code.indexOf("College") == -1) {
  342. return 51; //参数错误
  343. }
  344. CollegeBooking collegeBooking = new CollegeBooking();
  345. collegeBooking.setOpenid(openid);
  346. collegeBooking.setCollege_code(c_code.substring(8, c_code.length()));
  347. String lat_l, lon_l;
  348. int credit = 0;
  349. if (collegeBookingService.checkBooking(collegeBooking) != null) {
  350. if (c_code.substring(7, 1) == "P") {
  351. college_type = "practice";
  352. CollegeCurriculumPractice collegeCurriculumPractice = collegeCurriculumPracticeService.getPracticeByCode(c_code);
  353. lat_l = collegeCurriculumPractice.getMi_latitude();
  354. lon_l = collegeCurriculumPractice.getMi_longitude();
  355. credit = collegeCurriculumPractice.getCredit();
  356. id = collegeCurriculumPractice.getId();
  357. } else if (c_code.substring(7, 1) == "E") {
  358. college_type = "experience";
  359. CollegeCurriculumExperience collegeCurriculumExperience = collegeCurriculumExperienceService.getExperienceByCode(c_code.substring(8, c_code.length()));
  360. lat_l = collegeCurriculumExperience.getLatitude();
  361. lon_l = collegeCurriculumExperience.getLongitude();
  362. credit = collegeCurriculumExperience.getCredit();
  363. id = collegeCurriculumExperience.getId();
  364. } else {
  365. return 51; //参数错误
  366. }
  367. DistanceUtil distanceUtil = new DistanceUtil();
  368. double distance = distanceUtil.GetDistance(Double.parseDouble(lat_l), Double.parseDouble(lon_l), Double.parseDouble(lat), Double.parseDouble(lon));
  369. if (distance > 500) {
  370. return 53; //不在范围内
  371. } else {
  372. //判断是否已完成
  373. CollegeLearningDetail collegeLearningDetail = new CollegeLearningDetail();
  374. collegeLearningDetail.setOpen_id(openid);
  375. collegeLearningDetail.setC_code(c_code.substring(8, c_code.length()));
  376. CollegeLearningDetail collegeLearningDetailC = collegeLearningDetailService.checkCorePositive(collegeLearningDetail);
  377. if (collegeLearningDetailC.getStatus() != 9) {
  378. collegeLearningDetailC.setDate(sdf.format(new Date()));
  379. collegeLearningDetailC.setStatus(9);
  380. collegeLearningDetailC.setCredit(credit);
  381. collegeLearningDetailService.addCollegeLearningDetail(collegeLearningDetailC);
  382. } else {
  383. return 54; //已完成
  384. }
  385. //判断是否已经学习 增加学分
  386. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryOneUserPoints(openid);
  387. if (collegeUserPoints == null) {
  388. CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
  389. collegeUserPointsNew.setOpenid(openid);
  390. collegeUserPointsNew.setCredit_total(credit);
  391. collegeUserPointsNew.setCredit_available(credit);
  392. } else {
  393. CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
  394. collegeUserPointsNew.setOpenid(openid);
  395. collegeUserPointsNew.setCredit_total(collegeUserPoints.getCredit_total() + credit);
  396. collegeUserPointsNew.setCredit_available(collegeUserPoints.getCredit_available() + credit);
  397. }
  398. //增加奖学金
  399. collegeScholarshipsDetailService.addScholarships(openid, "learning",college_type, id, null, null);
  400. return 1;
  401. }
  402. } else {
  403. return 52; //没有预约
  404. }
  405. }
  406. public LinkedHashMap<String, Object> queryRedeemIndex(String openid) {
  407. LinkedHashMap<String, Object> userInfo = new LinkedHashMap<>();
  408. LinkedHashMap<String, Object> returnInfo = new LinkedHashMap<>();
  409. List<Object> presentInfoTemp = new LinkedList<>();
  410. WXUser wxUser = wxUserService.getWXUser(openid);
  411. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryOneUserPoints(openid);
  412. CollegeUserLevel collegeUserLevel;
  413. if(collegeUserPoints == null) {
  414. //新增用户
  415. CollegeUserPoints collegeUserPointsNew = new CollegeUserPoints();
  416. collegeUserPointsNew.setOpenid(openid);
  417. collegeUserPointsNew.setCredit_available(0);
  418. collegeUserPointsNew.setCredit_total(0);
  419. collegeUserPointsNew.setScholarships_available(0);
  420. collegeUserPointsNew.setScholarships_total(0);
  421. collegeUserPointsDao.insertSelective(collegeUserPointsNew);
  422. collegeUserLevel = collegeUserLevelService.getUserLevel(0);
  423. collegeUserPoints = collegeUserPointsNew;
  424. } else {
  425. collegeUserLevel = collegeUserLevelService.getUserLevel(collegeUserPoints.getCredit_available());
  426. }
  427. int level = 0;
  428. if (collegeUserLevel != null) {
  429. level = collegeUserLevel.getLevel();
  430. }
  431. userInfo.put("name", wxUser.getXu_name());
  432. userInfo.put("avatarUrl", wxUser.getXu_avatarUrl());
  433. userInfo.put("Scholarships", collegeUserPoints.getScholarships_available());
  434. userInfo.put("level", level);
  435. List<CollegePresentScholarships> collegePresentScholarships = collegePresentScholarshipsService.getCollegePresentScholarships();
  436. for (CollegePresentScholarships collegePresentScholarship : collegePresentScholarships) {
  437. LinkedHashMap<String, Object> presents = new LinkedHashMap<>();
  438. //通过等级判断是否适合商品
  439. presents.put("id",collegePresentScholarship.getId());
  440. presents.put("name", collegePresentScholarship.getName());
  441. presents.put("level", collegePresentScholarship.getLevel());
  442. presents.put("scholarships", collegePresentScholarship.getScholarships());
  443. presents.put("list_img_href", collegePresentScholarship.getList_img_href());
  444. presents.put("count", collegePresentScholarship.getCount());
  445. if (collegePresentScholarship.getLevel() > level) {
  446. presents.put("redeem", false);
  447. } else {
  448. presents.put("redeem", true);
  449. }
  450. presentInfoTemp.add(presents);
  451. }
  452. returnInfo.put("userInfo", userInfo);
  453. returnInfo.put("presentInfo", presentInfoTemp);
  454. return returnInfo;
  455. }
  456. public LinkedHashMap<String, Object> queryRedeem(Integer presentId) {
  457. LinkedHashMap<String, Object> returnInfo = new LinkedHashMap<>();
  458. CollegePresentScholarships collegePresentScholarships = collegePresentScholarshipsService.getCollegePresentScholarship(presentId);
  459. returnInfo.put("detail_img_href",collegePresentScholarships.getDetail_img_href());
  460. return returnInfo;
  461. }
  462. public LinkedHashMap<String, Object> queryRedeemDetail(Integer presentId,String openid) {
  463. LinkedHashMap<String, Object> returnInfo = new LinkedHashMap<>();
  464. CollegePresentScholarships collegePresentScholarships = collegePresentScholarshipsService.getCollegePresentScholarship(presentId);
  465. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryOneUserPoints(openid);
  466. CollegeUserLevel collegeUserLevelTemp = collegeUserLevelService.getUserLevel(collegeUserPoints.getCredit_available());
  467. int level = 0;
  468. if (collegeUserLevelTemp != null) {
  469. level = collegeUserLevelTemp.getLevel();
  470. }
  471. if(collegeUserPoints == null || collegePresentScholarships == null) {
  472. returnInfo.put("error", "未找到信息");
  473. } else {
  474. CollegeUserLevel collegeUserLevel = collegeUserLevelService.getUserLevelDesc(collegePresentScholarships.getLevel());
  475. returnInfo.put("level",collegePresentScholarships.getLevel());
  476. returnInfo.put("levelDesc",collegeUserLevel.getDesc());
  477. returnInfo.put("presentDesc",collegePresentScholarships.getDesc());
  478. returnInfo.put("presentType",collegePresentScholarships.getType());
  479. returnInfo.put("presentName",collegePresentScholarships.getName());
  480. returnInfo.put("presentRedeemImg",collegePresentScholarships.getRedeem_img_href());
  481. returnInfo.put("presentScholarships",collegePresentScholarships.getScholarships());
  482. returnInfo.put("userScholarships",collegeUserPoints.getScholarships_available());
  483. if (collegePresentScholarships.getLevel() > level) {
  484. returnInfo.put("redeem", false);
  485. } else {
  486. returnInfo.put("redeem", true);
  487. }
  488. if(collegePresentScholarships.getType() == 2) {
  489. List<WXMktInfo> wxMktInfo = wxMktInfoService.getMktInfos(null);
  490. returnInfo.put("mktInfo",wxMktInfo);
  491. }
  492. }
  493. return returnInfo;
  494. }
  495. public LinkedHashMap<String, Object> userRedeem(CollegePresentScholarshipsLogs collegePresentScholarshipsLogs) {
  496. LinkedHashMap<String, Object> returnInfo = new LinkedHashMap<>();
  497. CollegePresentScholarships collegePresentScholarships = collegePresentScholarshipsService.getCollegePresentScholarship(collegePresentScholarshipsLogs.getPresent_id());
  498. CollegeUserPoints collegeUserPoints = collegeUserPointsDao.queryOneUserPoints(collegePresentScholarshipsLogs.getOpenid());
  499. CollegeUserLevel collegeUserLevel = collegeUserLevelService.getUserLevel(collegeUserPoints.getCredit_available());
  500. int level = 0;
  501. if (collegeUserLevel != null) {
  502. level = collegeUserLevel.getLevel();
  503. }
  504. //判断等级
  505. if(level < collegePresentScholarships.getLevel()) {
  506. returnInfo.put("code","90");
  507. returnInfo.put("msg","等级未达到");
  508. return returnInfo;
  509. }
  510. //判断奖学金
  511. if(collegeUserPoints.getScholarships_available() < collegePresentScholarships.getScholarships()) {
  512. returnInfo.put("code","91");
  513. returnInfo.put("msg","奖学金不足");
  514. return returnInfo;
  515. }
  516. //subtractScholarships
  517. if(collegeScholarshipsDetailService.subtractScholarships(collegePresentScholarshipsLogs) == 1){
  518. returnInfo.put("code","1");
  519. returnInfo.put("msg","兑换成功");
  520. return returnInfo;
  521. } else {
  522. returnInfo.put("code","99");
  523. returnInfo.put("msg","系统异常");
  524. return returnInfo;
  525. }
  526. }
  527. }