ApiMerchantController.java 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.ssj.api.controller;
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import com.alibaba.fastjson.JSONObject;
  12. import com.ssj.api.domain.vo.merchant.ServiceVo;
  13. import com.ssj.api.security.annotation.IgnoreSecurity;
  14. import com.ssj.bean.sys.fx.domain.Merchant;
  15. import com.ssj.bean.weixin.libmy.domain.TbLibJoinConsume;
  16. import com.ssj.framework.basic.utils.DateHelper;
  17. import com.ssj.framework.core.common.controller.BaseController;
  18. import com.ssj.framework.core.util.ResponseConstant;
  19. import com.ssj.framework.core.util.ResponseEntity;
  20. import com.ssj.service.sys.fx.service.MerchantService;
  21. import com.ssj.service.weixin.library.service.ILibJoinConsumeService;
  22. import io.swagger.annotations.Api;
  23. import io.swagger.annotations.ApiOperation;
  24. @Api(value = "商户相关的", tags = "商户相关的")
  25. @RestController
  26. @RequestMapping("/open/api/merchant")
  27. public class ApiMerchantController extends BaseController {
  28. @Autowired
  29. private MerchantService merchantService;
  30. @Autowired
  31. private ILibJoinConsumeService libJoinConsumeService;
  32. @IgnoreSecurity
  33. @RequestMapping(value = "/service")
  34. @ApiOperation(value = "获取商户套餐信息接口", notes = "获取商户套餐信息接口")
  35. public ResponseEntity getAccessToken(@RequestBody ServiceVo requestVO) {
  36. logger.info("第三方调用接口【service】,请求参数:"+JSONObject.toJSONString(requestVO));
  37. ResponseEntity responseEntity = new ResponseEntity();
  38. Map<String,Object> data=new HashMap<String, Object>();
  39. try {
  40. Merchant merchant=merchantService.getMerchantByLibId(requestVO.getLibId());
  41. if(merchant!=null) {
  42. //大于2020-10-09才会结算。
  43. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  44. String dateString="2020-10-09";
  45. if(requestVO.getType()==1
  46. && sdf.parse(dateString).getTime()<=new Date().getTime()) {
  47. merchant.setCurIsSummary(1);
  48. merchant.setCurSummaryTime(new Date());
  49. merchant.setNextSummaryTime(DateHelper.getMonthDate(merchant.getCurSummaryTime(),1));
  50. merchantService.save(merchant);
  51. TbLibJoinConsume consume = new TbLibJoinConsume();
  52. consume.setFromLibId(merchant.getLibId());
  53. consume.setFromMerchantId(merchant.getId());
  54. consume.setLibService(merchant.getLibService());
  55. consume.setPlatformService(0);
  56. consume.setType(2);
  57. consume.setRemarks("消费【新模式用户激活消费】 -来源开放接口");
  58. consume.setCreateTime(new Date());
  59. libJoinConsumeService.save(consume);
  60. }
  61. DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  62. data.put("id", merchant.getId());
  63. data.put("libId", merchant.getLibId());
  64. data.put("summaryTime", merchant.getCurSummaryTime()!=null ? format.format(merchant.getCurSummaryTime()) : "");
  65. data.put("endSummaryTime", merchant.getCurSummaryTime()!=null ? format.format(DateHelper.getMonthDate(merchant.getCurSummaryTime(),merchant.getLibServiceMonth())) : "");
  66. data.put("signType", merchant.getSignType());
  67. data.put("libService", merchant.getLibService());
  68. responseEntity.success(data, "获取商户套餐信息成功");
  69. }else {
  70. responseEntity.failure(ResponseConstant.CODE_500, "libId未绑定商户");
  71. }
  72. } catch (Exception e) {
  73. logger.error("获取商户套餐信息接口", e);
  74. responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙,请稍后重试");
  75. }
  76. logger.info("第三方调用接口【service】,返回结果:"+JSONObject.toJSONString(responseEntity));
  77. return responseEntity;
  78. }
  79. }