UserApiController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.kede.user.controller;
  2. import java.util.Map;
  3. import javax.annotation.Resource;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestMethod;
  6. import org.springframework.web.bind.annotation.RestController;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.kede.common.bo.Result;
  9. import com.kede.common.constant.ErrorConstants;
  10. import com.kede.common.controller.BaseController;
  11. import com.kede.common.model.Order;
  12. import com.kede.common.model.Project;
  13. import com.kede.common.utils.StringUtils;
  14. import com.kede.core.shiro.token.TokenManager;
  15. import com.kede.order.service.impl.OrderService;
  16. import com.kede.project.service.ProjectService;
  17. import com.kede.user.service.UserService;
  18. import com.kede.wxsdk.service.WxService;
  19. @RestController
  20. @RequestMapping(value = "/api/user")
  21. public class UserApiController extends BaseController{
  22. @Resource
  23. private UserService userService;
  24. @Resource
  25. private ProjectService projectService;
  26. @Resource
  27. private OrderService orderService;
  28. @Resource
  29. private WxService wxService;
  30. @RequestMapping(value = "/wxPush", method = RequestMethod.POST)
  31. public Result wxPush(Integer id) {
  32. Result res=new Result();
  33. if (id==null) {
  34. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"id","id"));
  35. return res;
  36. }
  37. Project p=projectService.get(id);
  38. if (p==null) {
  39. res.getError().add(buildError("","项目不存在"));
  40. return res;
  41. }
  42. if (!projectService.checkBuy(id,0)) {
  43. res.getError().add(buildError("","订单已存在"));
  44. return res;
  45. }
  46. Map<String, String> map=wxService.pushUnifiedOrder(p);
  47. return res.data(map);
  48. }
  49. @RequestMapping(value = "/wxClose", method = RequestMethod.GET)
  50. public Result pushWxClose(String orderNo) {
  51. Result res=new Result();
  52. if (StringUtils.isBlank(orderNo)) {
  53. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"订单编号","订单编号"));
  54. return res;
  55. }
  56. Order o=orderService.selectByOrderNo(orderNo);
  57. if (o==null) {
  58. res.getError().add(buildError("订单不存在","订单不存在"));
  59. return res;
  60. }
  61. if(o.getPayStatus()!=0) {
  62. res.getError().add(buildError("订单只在未支付状态可以撤销","订单只在未支付状态可以撤销"));
  63. return res;
  64. }
  65. res.data(wxService.pushWxClose(o));
  66. return res;
  67. }
  68. @RequestMapping(value = "/wxQuery", method = RequestMethod.GET)
  69. public Result pushOrderQuery(String orderNo) {
  70. Result res=new Result();
  71. res.data(wxService.pushOrderQuery(orderNo));
  72. return res;
  73. }
  74. @RequestMapping(value = "/order/list" ,method = RequestMethod.GET)
  75. public Result list(String name,Integer type,Integer payStatus ,String startTime,String endTime,Integer pageNo,Integer pageSize) {
  76. Result res =new Result();
  77. res.data(orderService.list( name,1,payStatus , startTime, endTime, pageNo, pageSize));
  78. return res;
  79. }
  80. @RequestMapping(value = "/getliveinfo" ,method = RequestMethod.GET)
  81. public Result getliveinfo(Integer pageNo,Integer pageSize){
  82. Result res =new Result();
  83. res.data(wxService.getliveinfo(pageNo, pageSize));
  84. return res;
  85. }
  86. @RequestMapping(value = "/decryptData", method = RequestMethod.POST)
  87. public String decryptData(String encryptedData, String iv) {
  88. String sessionKey=(String) TokenManager.getVal2Session("sessionKey");
  89. JSONObject js=wxService.pushDecryptData(sessionKey, encryptedData, iv);
  90. return js.toJSONString();
  91. }
  92. }