You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

165 lines
6.7 KiB

  1. package com.simple.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.simple.common.ErrorCode;
  6. import com.simple.common.Result;
  7. import com.simple.common.ResultData;
  8. import com.simple.domain.po.*;
  9. import com.simple.enums.EnumCarCmd;
  10. import com.simple.enums.EnumCarVendor;
  11. import com.simple.service.WxCUserCarService;
  12. import com.simple.service.WxCarCmdLogService;
  13. import com.simple.service.WxMerchantService;
  14. import com.simple.service.WxParkService;
  15. import com.simple.utils.ETCPUtil;
  16. import com.simple.utils.TJDCarUtil;
  17. import io.swagger.annotations.ApiOperation;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.apache.log4j.Logger;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. @RestController
  27. @RequestMapping("/car")
  28. public class WxCarController extends BaseController
  29. {
  30. private Logger logger = Logger.getLogger(WxCarController.class);
  31. ETCPUtil etcp = new ETCPUtil();
  32. TJDCarUtil tjd = new TJDCarUtil();
  33. @Autowired
  34. WxParkService wxParkService;
  35. @Autowired
  36. WxCUserCarService wxCUserCarService;
  37. @Autowired
  38. WxMerchantService wxMerchantService;
  39. @Autowired
  40. WxCarCmdLogService wxCarCmdLogService;
  41. private WxPark getCurrentPark(MallUserInfo user) {
  42. WxPark parkQ = new WxPark();
  43. parkQ.setTenantId(user.getTenantId());
  44. WxPark wxPark = wxParkService.getByObj(parkQ);
  45. // 1, get mall's park
  46. // future use redis to optimize
  47. return wxPark;
  48. }
  49. @ApiOperation(value = "获取车场支持的厂家",notes="{}")
  50. @GetMapping("/getVendor")
  51. public ResultData getVendor() {
  52. MallUserInfo user = getUser();
  53. // 1, get mall's park
  54. WxPark park = getCurrentPark(user);
  55. Map map = new HashMap();
  56. map.put("vendor", park.getVendorType());
  57. return new ResultData(map);
  58. }
  59. // 优免券模板
  60. /*
  61. {
  62. "id": 4974, //优免券模板 ID
  63. "parkId": "fbqXUlfVvfc=", //车场标识
  64. "businessId": "ZcWQ26TeJuQ=", //商家标识
  65. title -- "businessName": "天洋广场", //商家名称
  66. subtitle -- "name": "商家 1 小时优免券", //优免券名称
  67. "category": "1", //优免券类型 1:小时优惠券,2:金额优惠券,3:折扣优惠券,4:免费券
  68. price -- "categoryValue": "1.00", //优免券价值
  69. total -- "amount": 100000, //优免券数量
  70. valid_start_date -- "effectiveStart": "2018-02-01", //生效开始时间
  71. valid_end_date -- "effectiveEnd": "2028-02-01",//生效结束时间
  72. -"couponType": "0",//优惠券类型
  73. number 库存 -- "avaliavleNum": 99993 //可用优惠券
  74. },
  75. */
  76. @ApiOperation(value = "优免券模板", notes = "{\"merchantId\":\"商户ID\"}\n输出\n" +
  77. "{\n" +
  78. "\"data\":{" +
  79. "\"count\": 4," +
  80. "\"couponPlatformModels\": [\n" +
  81. " {\n" +
  82. " \"id\": 4974, //优免券模板 ID\n" +
  83. " \"parkId\": \"fbqXUlfVvfc=\", //车场标识" +
  84. " \"businessId\": \"ZcWQ26TeJuQ=\", //商家标识" +
  85. " \"businessName\": \"天洋广场\", //商家名称" +
  86. " \"name\": \"商家 1 小时优免券\", //优免券名称" +
  87. " \"category\": \"1\", //优免券类型\n 1:小时优惠券,2:金额优惠券,3:折扣优惠券,4:免费券" +
  88. " \"categoryValue\": \"1.00\", //优免券价值\n" +
  89. " \"amount\": 100000, //优免券数量\n" +
  90. " \"effectiveStart\": \"2018-02-01\", //生效开始时间\n" +
  91. " \"effectiveEnd\": \"2028-02-01\",//生效结束时间\n" +
  92. " \"couponType\": \"0\",//优惠券类型\n" +
  93. " \"avaliavleNum\": 99993 //可用优惠券\n" +
  94. " },\n" +
  95. " {...},\n" +
  96. " {...}\n" +
  97. " ]}}\n")
  98. @PostMapping("/quanTemplate")
  99. public ResultData quanTemplate(Map<String, String > paramMap) {
  100. logger.info("quanTemplate: " + paramMap.toString());
  101. MallUserInfo user = getUser();
  102. /// 1, get mall's park
  103. WxPark park = getCurrentPark(user);
  104. if (park.getVendorType() == EnumCarVendor.CAR_ETCP.getCode()) {
  105. String merchantIdStr = paramMap.get("merchantId");
  106. if (StringUtils.isBlank(merchantIdStr)) {
  107. // 优先从从商户表里取
  108. logger.error("quanTemplate failed, merchantId为空");
  109. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantId为空");
  110. }
  111. String params = park.getVendorParams();
  112. JSONObject objParams = JSON.parseObject(params);
  113. String url = objParams.getString("url");
  114. String merchantNo = objParams.getString("merchantNo");
  115. String merchantKey = objParams.getString("merchantKey");
  116. String version = objParams.getString("version");
  117. String parkId = park.getParkId();
  118. // bussinessId from 参数信息
  119. String businessId = "";
  120. // 优先从从商户表里取
  121. businessId = getETCPBusinessID(merchantIdStr);
  122. if (StringUtils.isBlank(businessId)) {
  123. // 1期只有一个虚拟商户,可以写在商场配置里
  124. businessId = objParams.getString("businessId");
  125. }
  126. String ret = etcp.getBCouponList(url, merchantNo, merchantKey, version, parkId, businessId);
  127. JSONObject retObj = JSON.parseObject(ret);
  128. if (retObj.getIntValue("code") == 0) {
  129. return new ResultData(retObj.getJSONObject("data"));
  130. } else {
  131. logger.error("quanTemplate failed, 优免券模板未发现");
  132. return new ResultData(ErrorCode.ETCP_QUAN_TEMP_FAIL.getCode(), "优免券模板未发现");
  133. }
  134. }
  135. return new ResultData(ErrorCode.CAR_VENDOR_NOT_SUPPORT.getCode(), "优免券模板失败");
  136. }
  137. private String getETCPBusinessID(String merchantIdStr) {
  138. String businessId;
  139. Long merchantId = 0L;
  140. try {
  141. merchantId = Long.valueOf(merchantIdStr);
  142. } catch (NumberFormatException e) {
  143. logger.error(e.getMessage());
  144. }
  145. WxMerchant wxMerchant = wxMerchantService.getById(merchantId);
  146. String carParams = wxMerchant.getCarParams();
  147. JSONObject objParams1 = JSON.parseObject(carParams);
  148. businessId = objParams1.getString("businessId");
  149. return businessId;
  150. }
  151. }