UserApiController.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /**
  31. * 微信下单
  32. * @param id
  33. * @return
  34. */
  35. @RequestMapping(value = "/wxPush", method = RequestMethod.POST)
  36. public Result wxPush(Integer id) {
  37. Result res=new Result();
  38. if (id==null) {
  39. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"id","id"));
  40. return res;
  41. }
  42. Project p=projectService.get(id);
  43. if (p==null) {
  44. res.getError().add(buildError("","项目不存在"));
  45. return res;
  46. }
  47. if (!projectService.checkBuy(id,0)) {
  48. res.getError().add(buildError("","订单已存在"));
  49. return res;
  50. }
  51. Map<String, String> map=wxService.pushUnifiedOrder(p);
  52. return res.data(map);
  53. }
  54. /**
  55. * 撤销订单
  56. *
  57. * @param orderNo
  58. * @return
  59. */
  60. @RequestMapping(value = "/wxClose", method = RequestMethod.GET)
  61. public Result pushWxClose(String orderNo) {
  62. Result res=new Result();
  63. if (StringUtils.isBlank(orderNo)) {
  64. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"订单编号","订单编号"));
  65. return res;
  66. }
  67. Order o=orderService.selectByOrderNo(orderNo);
  68. if (o==null) {
  69. res.getError().add(buildError("订单不存在","订单不存在"));
  70. return res;
  71. }
  72. if(o.getPayStatus()!=0) {
  73. res.getError().add(buildError("订单只在未支付状态可以撤销","订单只在未支付状态可以撤销"));
  74. return res;
  75. }
  76. res.data(wxService.pushWxClose(o));
  77. return res;
  78. }
  79. @RequestMapping(value = "/wxQuery", method = RequestMethod.GET)
  80. public Result pushOrderQuery(String orderNo) {
  81. Result res=new Result();
  82. res.data(wxService.pushOrderQuery(orderNo));
  83. return res;
  84. }
  85. @RequestMapping(value = "/order/list" ,method = RequestMethod.GET)
  86. public Result list(String name,Integer type,Integer payStatus ,String startTime,String endTime,Integer pageNo,Integer pageSize) {
  87. Result res =new Result();
  88. res.data(orderService.list( name,1,payStatus , startTime, endTime, pageNo, pageSize));
  89. return res;
  90. }
  91. @RequestMapping(value = "/getliveinfo" ,method = RequestMethod.GET)
  92. public Result getliveinfo(Integer pageNo,Integer pageSize){
  93. Result res =new Result();
  94. res.data(wxService.getliveinfo(pageNo, pageSize));
  95. return res;
  96. }
  97. @RequestMapping(value = "/decryptData", method = RequestMethod.POST)
  98. public String decryptData(String encryptedData, String iv) {
  99. String sessionKey=(String) TokenManager.getVal2Session("sessionKey");
  100. JSONObject js=wxService.pushDecryptData(sessionKey, encryptedData, iv);
  101. return js.toJSONString();
  102. }
  103. }