RefundController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package com.wechat.controller;
  2. import java.io.IOException;
  3. import java.math.BigDecimal;
  4. import javax.annotation.Resource;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import com.alibaba.fastjson.JSON;
  13. import com.wechat.common.Constants;
  14. import com.wechat.common.utils.MvcUtil;
  15. import com.wechat.common.utils.StringsUtils;
  16. import com.wechat.global.base.BaseController;
  17. import com.wechat.global.message.InfoMsg;
  18. import com.wechat.model.dbEntity.TdtgGoodsRejected;
  19. import com.wechat.model.responseDto.JsonResp;
  20. import com.wechat.service.WeiXinService;
  21. /**
  22. * FAQ问答
  23. *
  24. */
  25. @Controller
  26. @RequestMapping("refund")
  27. public class RefundController extends BaseController {
  28. //域名
  29. @Value("#{configProperties['url.base']}")
  30. private String baseUrl;
  31. //图片根目录
  32. @Value("#{configProperties['url.img.base']}")
  33. private String imgUrl;
  34. //退款图片路径
  35. @Value("#{configProperties['upload.refund.path']}")
  36. private String refoundUrl;
  37. @Resource
  38. private WeiXinService wxService;
  39. /**
  40. * 获取下载图片信息(jpg)
  41. *
  42. * @param mediaId 文件的id
  43. * @throws Exception
  44. */
  45. @RequestMapping(value = "saveGoodsRejected", method = RequestMethod.POST)
  46. public void saveGoodsRejected(@RequestParam String orderNo, @RequestParam String refundReason,@RequestParam BigDecimal refundAmount,@RequestParam String mobile,@RequestParam String imgList, @RequestParam String oldImgList, HttpServletRequest request, HttpServletResponse response) throws Exception {
  47. TdtgGoodsRejected rejected = new TdtgGoodsRejected();
  48. JsonResp<String> ret = new JsonResp<String>();
  49. int imgLength = 0;
  50. if(StringsUtils.isEmpty(orderNo))
  51. {
  52. ret.setMsg(InfoMsg.ERROR_SAVE_FIELD);
  53. }
  54. else
  55. {
  56. //mediaid 获取微信服务器图片
  57. if(!StringsUtils.isEmpty(imgList))
  58. {
  59. String[] imgArray = StringsUtils.split(imgList, ";");
  60. imgLength = imgArray.length;
  61. for(int i=0; i<imgArray.length; i++ )
  62. {
  63. String mediaId = imgArray[i];
  64. String fileName = "";
  65. if(!StringsUtils.isEmpty(mediaId))
  66. {
  67. //从微信服务器上获取图片至本地
  68. fileName = wxService.saveImageToDisk(mediaId,"");
  69. if(StringsUtils.isEmpty(fileName))
  70. {
  71. //系统异常
  72. throw new Exception();
  73. }
  74. switch (i)
  75. {
  76. case 0 :
  77. rejected.setVoucherImg1(fileName);
  78. break;
  79. case 1 :
  80. rejected.setVoucherImg2(fileName);
  81. break;
  82. case 2 :
  83. rejected.setVoucherImg3(fileName);
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. // 原已上传的服务器图片
  90. if (!StringsUtils.isEmpty(oldImgList)) {
  91. String[] oldImgArray = StringsUtils.split(oldImgList, ";");
  92. for (int i = 0; i < oldImgArray.length; i++) {
  93. String fileName = oldImgArray[i];
  94. if (StringsUtils.isEmpty(fileName)) {
  95. // 系统异常
  96. throw new Exception();
  97. }
  98. switch (i+imgLength) {
  99. case 0:
  100. rejected.setVoucherImg1(fileName);
  101. break;
  102. case 1:
  103. rejected.setVoucherImg2(fileName);
  104. break;
  105. case 2:
  106. rejected.setVoucherImg3(fileName);
  107. break;
  108. }
  109. }
  110. }
  111. rejected.setOrderNo(orderNo);
  112. rejected.setRefundReason(refundReason);
  113. rejected.setRefundAmount(refundAmount);
  114. rejected.setMobile(mobile);
  115. //已申请
  116. rejected.setStatus(1);
  117. }
  118. String json = JSON.toJSONString(ret, true);
  119. try {
  120. MvcUtil.writeJson(request, response, json);
  121. } catch (IOException e) {
  122. log.error(e);
  123. }
  124. }
  125. }