CustomerGradeController.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package com.platform.yijia.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.google.gson.Gson;
  4. import com.platform.yijia.pojo.CustomerManage;
  5. import com.platform.yijia.service.CustomerGradeServices;
  6. import com.platform.yijia.service.PayOrderService;
  7. import com.platform.yijia.service.StationService;
  8. import com.platform.yijia.utils.CodeMsg;
  9. import com.platform.yijia.utils.ResultData;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.annotation.Resource;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * 客户优惠和营销
  21. */
  22. @Controller
  23. @RequestMapping("/demo")
  24. public class CustomerGradeController {
  25. private static Logger logger =(Logger) LoggerFactory.getLogger(CustomerGradeController.class);
  26. @Resource
  27. private CustomerGradeServices customerGradeServices;
  28. @Resource
  29. private PayOrderService payOrderService;
  30. @Resource
  31. private StationService stationService;
  32. /*
  33. * 查询直降客户等级条件和优惠
  34. * @param stationId
  35. * @return
  36. */
  37. @RequestMapping(value = "/getCustomerGradeList", method = RequestMethod.GET)
  38. @ResponseBody
  39. public String getCustomerGradeList(@RequestParam("stationId") String stationId){
  40. Gson gson =new Gson();
  41. ResultData resultData =null;
  42. if(StringUtils.isNotBlank(stationId)){
  43. Map params = new HashMap();
  44. params.put("stationId", stationId);
  45. String discountPlanType = stationService.getStationDiscountWay(stationId);
  46. if(discountPlanType.equals("1")){
  47. //直降表查询
  48. List<Map> customerGradeList = customerGradeServices.getCustomerGradeList(params);
  49. resultData = ResultData.success(customerGradeList);
  50. }else {
  51. //立减满减表查询
  52. List<Map> customerMarkertPlanList = customerGradeServices.getCustomerMarkertPlanList(params);
  53. resultData = ResultData.success(customerMarkertPlanList);
  54. }
  55. }else {
  56. resultData=ResultData.error(CodeMsg.SEARCH_FAIL);
  57. }
  58. return gson.toJson(resultData);
  59. }
  60. /*
  61. * 查询客户等级信息
  62. * @param jsonObject
  63. * @return
  64. */
  65. @RequestMapping(value = "/getCustomerGradeInfo", method = RequestMethod.POST)
  66. @ResponseBody
  67. public String getCustomerGradeInfo(@RequestBody JSONObject jsonObject){
  68. Gson gson =new Gson();
  69. ResultData resultData =null;
  70. Map<String, Object> params = new HashMap<>();
  71. //oilName
  72. params.put("oilName", jsonObject.get("oilName"));
  73. params.put("mobilePhone", jsonObject.get("mobilePhone"));
  74. params.put("stationId", jsonObject.get("stationId"));
  75. params.put("userType", jsonObject.get("userType"));
  76. //用户类型
  77. switch (jsonObject.get("userType").toString()){
  78. case "1":
  79. params.put("blogOpenid", jsonObject.get("openId").toString());
  80. break;
  81. case "2":
  82. params.put("minaOpenid", jsonObject.get("openId").toString());
  83. break;
  84. }
  85. logger.info("查询客户等级所传参数:"+params.toString());
  86. //优惠方案类型
  87. String discountPlanType = stationService.getStationDiscountWay(params.get("stationId").toString());
  88. if(discountPlanType != null && discountPlanType !=""){
  89. params.put("discountPlanType", discountPlanType);
  90. CustomerManage customerManage = new CustomerManage();
  91. customerManage.setPhoneNumber(params.get("mobilePhone").toString());
  92. customerManage.setOilName(params.get("oilName").toString());
  93. customerManage.setStationId(Integer.valueOf(params.get("stationId").toString()));
  94. CustomerManage existCustomer = payOrderService.isExistCustomer(customerManage);
  95. //如果为空则是此油品第一次下单
  96. if(existCustomer ==null){
  97. if(discountPlanType.equals("1")){
  98. //如果该油站使用是直降
  99. List<Map<String, Object>> customerGradeInfoList = customerGradeServices.getCustomerGradeInfo(params);
  100. //只存在一种等级的时候
  101. if(customerGradeInfoList !=null && customerGradeInfoList.size() ==1){
  102. resultData = ResultData.success(customerGradeInfoList);
  103. }else if(customerGradeInfoList !=null && customerGradeInfoList.size() >1){
  104. //存在多个等级时 查询出结果按优惠的油量升序排列取第一个即可
  105. resultData = ResultData.success(customerGradeInfoList.get(0));
  106. }else{
  107. //直降表查询 升序取第一个
  108. List<Map> customerGradeList = customerGradeServices.getCustomerGradeList(params);
  109. resultData = ResultData.success(customerGradeList.get(0));
  110. }
  111. }else {
  112. //此处重新赋值123的原因:station_pay表取值 1 2 3 4 分别代表 等级直降 满减 立减 直降; 而 在markert_plan 1 2 3代表 满减 立减 直降
  113. switch (discountPlanType){
  114. case "2":
  115. params.put("discountPlanType", "1");
  116. break;
  117. case "3":
  118. params.put("discountPlanType", "2");
  119. break;
  120. case "4":
  121. params.put("discountPlanType", "3");
  122. break;
  123. }
  124. //立减满减表查询站的优惠
  125. List<Map> customerMarkertPlanList = customerGradeServices.getCustomerMarkertPlanList(params);
  126. resultData = ResultData.success(customerMarkertPlanList);
  127. }
  128. }else{
  129. //否则该客户此油品已下过订单
  130. String memberGrade = existCustomer.getMemberGrade();
  131. if(memberGrade != null && memberGrade !=""){
  132. params.put("grade", memberGrade);
  133. }
  134. if(discountPlanType.equals("1")){
  135. //此处判断用于当该站由其他优惠改为等级直降时 (先使用其他优惠不存在等级时再改为直降方式)
  136. if(memberGrade == null || memberGrade.equals("")){
  137. Map map = new HashMap();
  138. map.put("stationId", existCustomer.getStationId());
  139. map.put("oilName", existCustomer.getOilName());
  140. List<Map> customerGradeInfo = customerGradeServices.getCustomerGradeList(map); //直降
  141. for (Map m: customerGradeInfo){
  142. if(Double.valueOf(customerManage.getAmt().toString()) >= Double.valueOf(m.get("memberConditStart").toString()) && Double.valueOf(customerManage.getAmt().toString()) < Double.valueOf(m.get("memberConditEnd").toString())){
  143. params.put("grade", m.get("id").toString());
  144. break;
  145. }
  146. }
  147. }
  148. //如果该油站使用是直降
  149. List<Map<String, Object>> customerGradeInfoList = customerGradeServices.getCustomerGradeInfo(params);
  150. resultData = ResultData.success(customerGradeInfoList);
  151. }else{
  152. switch (discountPlanType){
  153. case "2":
  154. params.put("discountPlanType", "1");
  155. break;
  156. case "3":
  157. params.put("discountPlanType", "2");
  158. break;
  159. case "4":
  160. params.put("discountPlanType", "3");
  161. break;
  162. }
  163. //立减满减表查询站的优惠
  164. List<Map> customerMarkertPlanList = customerGradeServices.getCustomerMarkertPlanList(params);
  165. resultData = ResultData.success(customerMarkertPlanList);
  166. }
  167. }
  168. }else {
  169. resultData = ResultData.success("该油站暂无设置优惠方案");
  170. }
  171. return gson.toJson(resultData);
  172. }
  173. }