YqPayController.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package com.ym.mec.collectfee.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ym.mec.collectfee.common.web.BaseController;
  5. import com.ym.mec.collectfee.entity.*;
  6. import com.ym.mec.collectfee.service.*;
  7. import com.ym.mec.collectfee.utils.GenerateNum;
  8. import com.ym.mec.collectfee.utils.yqpay.Intfc;
  9. import com.ym.mec.collectfee.utils.yqpay.Msg;
  10. import com.ym.mec.collectfee.utils.yqpay.NotifyMsg;
  11. import com.ym.mec.collectfee.utils.yqpay.YqPayUtil;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.apache.commons.io.IOUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.core.io.ClassPathResource;
  16. import org.springframework.scheduling.annotation.EnableScheduling;
  17. import org.springframework.scheduling.annotation.Scheduled;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import org.springframework.validation.annotation.Validated;
  20. import org.springframework.web.bind.annotation.ModelAttribute;
  21. import org.springframework.web.bind.annotation.PostMapping;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import java.io.InputStreamReader;
  25. import java.math.BigDecimal;
  26. import java.time.LocalDateTime;
  27. import java.util.*;
  28. //@Api("支付")
  29. @Slf4j
  30. @RestController
  31. @RequestMapping("yqpay")
  32. @EnableScheduling // 2.开启定时任务
  33. public class YqPayController extends BaseController {
  34. @Autowired
  35. private YqPayService yqPayService;
  36. @Autowired
  37. private YqQueryService yqQueryService;
  38. @Autowired
  39. private OrderService orderService;
  40. @Autowired
  41. private AccountService accountService;
  42. @Autowired
  43. private CourseGroupInfoService CourseGroupInfoService;
  44. @Autowired
  45. private ApplyInfoService applyInfoService;
  46. @Autowired
  47. private RenewalsService renewalsService;
  48. @Autowired
  49. private SchoolService schoolService;
  50. /**
  51. * 统一下单(乐团缴费)
  52. *
  53. * @return String
  54. * @throws Exception
  55. */
  56. // @ApiOperation(value = "提交支付", notes = "易乾支付统一下单")
  57. @PostMapping("/toPay")
  58. @Transactional
  59. public Object toPay(@ModelAttribute @Validated Order order) throws Exception {
  60. BigDecimal amount = new BigDecimal("0");
  61. //1、判断已报名人数
  62. CourseGroupInfo courseGroupInfo = CourseGroupInfoService.get(order.getCourseId());
  63. if (courseGroupInfo.getRegNum() >= courseGroupInfo.getPlanNum()) {
  64. return failed("乐团人数暂时已满,请稍后再试");
  65. }
  66. //课程组价格
  67. BigDecimal courseFee = courseGroupInfo.getFeeAmount();
  68. amount = amount.add(courseFee);
  69. ClassPathResource classPathResource = new ClassPathResource("instruments.json");
  70. BigDecimal instrumentPrice = new BigDecimal("0");//乐器价格
  71. String instrumentName = "";//乐器名称
  72. //获取乐器的价格
  73. String instrumentId = order.getInstrument();
  74. String jsonString = IOUtils.toString(new InputStreamReader(classPathResource.getInputStream(), "UTF-8"));
  75. Instrument instrument = JSONObject.parseObject(jsonString, Instrument.class);
  76. if (order.getInstrument() != null && !order.getInstrument().isEmpty()) {
  77. instrumentPrice = new BigDecimal(instrument.getInstruments().get(instrumentId).get("referencePrice"));
  78. instrumentName = (String) instrument.getInstruments().get(instrumentId).get("index") + "-" +
  79. (String) instrument.getInstruments().get(instrumentId).get("name");
  80. }
  81. //2 版本为3.0( 26),不收乐器费用,收押金800放乐器费用
  82. if (courseGroupInfo.getFeeType().equals(26)) {
  83. instrumentPrice = new BigDecimal("800");
  84. }
  85. amount = amount.add(instrumentPrice);
  86. //辅件价格
  87. String adjunctIds = order.getAdjunct();
  88. BigDecimal adjunctPrice = new BigDecimal("0");//辅件价格
  89. String adjunctName = "";//辅件名称
  90. if (adjunctIds != null && !adjunctIds.isEmpty()) {
  91. String[] adjunctIdArr = adjunctIds.split(",");
  92. for (String adjunctId : adjunctIdArr) {
  93. adjunctPrice = adjunctPrice.add(new BigDecimal(instrument.getAuxiliaries().get(adjunctId).get("referencePrice")));
  94. adjunctName += (String) instrument.getAuxiliaries().get(adjunctId).get("name") + "|";
  95. }
  96. }
  97. amount = amount.add(adjunctPrice);
  98. order.setGroupId(courseGroupInfo.getId());
  99. order.setAmount(amount);
  100. order.setRemark(instrumentName);
  101. order.setTuiFee(courseFee);
  102. order.setGoodsFee(instrumentPrice);
  103. order.setSdName(adjunctName + "教材|琴谱");
  104. order.setSdFee(adjunctPrice);
  105. School school = schoolService.get(order.getClassId());
  106. String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //异步通知地址
  107. String returnUrl = "http://pay.dayaedu.com/login?schoolId=" + school.getId() + "&classId=" + order.getClassId() + "&cityId=" + school.getCityId();//支付后返回页面
  108. String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付跳转页
  109. String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
  110. String orderNo = GenerateNum.getInstance().GenerateOrderNo(); //自己系统订单号
  111. order.setOrderNo(orderNo);
  112. order.setCreateTime(new Date()); //订单提交时间
  113. order.setStatus(1); //订单状态
  114. //获取支付成功跟支付中的订单数
  115. int branchId = order.getBranchId();
  116. int payOrderNums = orderService.getPayOrderNums();
  117. //分佣账户(1、每10笔,前四笔收入私户 2、私户每个商户最多收款400万)
  118. if ((payOrderNums + 1) % 10 <= 4) { //私人账户
  119. branchId = 0;
  120. }
  121. //获取分佣账户
  122. Account account = accountService.getAccountByBranchId(branchId);
  123. if (account == null) {
  124. return failed("机构没有设置收款账户");
  125. }
  126. String routingMerNo = account.getSellerNo();
  127. BigDecimal HasRouting = account.getHasRouting().add(order.getAmount());
  128. account.setHasRouting(HasRouting);
  129. Map<String, Object> routingList = new LinkedHashMap<String, Object>();
  130. routingList.put("routingMerNo", routingMerNo);//分佣账户
  131. routingList.put("routingFee", order.getAmount()); //分佣金额
  132. List<Map> tempRoutingList = new ArrayList();
  133. tempRoutingList.add(routingList);
  134. order.setUAccount(account.getId().toString());
  135. order.setAccount(routingMerNo);
  136. //1、插入订单
  137. orderService.insert(order);
  138. //2、修改已报名人数
  139. courseGroupInfo.setRegNum(courseGroupInfo.getRegNum() + 1);
  140. CourseGroupInfoService.upByIdAndVersion(courseGroupInfo);
  141. //3、修改分佣账户已收金额
  142. accountService.upByIdAndVersion(account);
  143. /*订单信息*/
  144. String orderBody = "大雅乐盟培训课程";
  145. /*订单标题*/
  146. String orderSubject = "培训订单";
  147. order.setAmount(new BigDecimal("2")); //测试设置金额
  148. Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
  149. resultMap.put("sellerNo", "0021677"); //收款商户号
  150. resultMap.put("payChannels", payChannels); //支付方式
  151. resultMap.put("orderBody", orderBody); //订单信息
  152. resultMap.put("payAmount", order.getAmount()); //支付金额
  153. resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
  154. resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
  155. resultMap.put("merMerOrderNo", orderNo); //商户订单号
  156. resultMap.put("orderSubject", orderSubject); //订单标题
  157. resultMap.put("returnUrl", returnUrl); //前台页面地址
  158. resultMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
  159. Map rqMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  160. rqMap.put("host", payUrl);
  161. return succeed(rqMap);
  162. }
  163. /**
  164. * 续费支付
  165. *
  166. * @return String
  167. * @throws Exception
  168. */
  169. // @ApiOperation(value = "续费支付", notes = "续费支付")
  170. @PostMapping("/renewalsPay")
  171. public Object renewalsPay(@ModelAttribute @Validated Renewals renewals) throws Exception {
  172. MecUser mecUser = applyInfoService.findMecUser(renewals.getUserId());
  173. if (mecUser == null) {
  174. return failed("续费用户不存在");
  175. }
  176. renewals.setBranchId(mecUser.getBranchId());
  177. //课程组价格
  178. List<MecCourse> courses = applyInfoService.queryUserCourse(renewals.getUserId());//获取续费课程
  179. if (courses == null) {
  180. return failed("您没有续费的课程");
  181. }
  182. MecCourse mecCourse4json = JSON.parseObject(renewals.getCourses(), MecCourse.class);
  183. if (mecCourse4json == null) {
  184. return failed("请选择续费课程");
  185. }
  186. //classType 小课1 大课2
  187. Integer buyCount = mecCourse4json.getBuyCount();
  188. BigDecimal amount = new BigDecimal("0"); //课程总价
  189. String remark = "";
  190. List<MecCourse> pickCourses = new ArrayList<>();
  191. for (int i = 0; i < courses.size(); i++) {
  192. MecCourse course = courses.get(i);
  193. if (mecCourse4json.getCourseId().equals(course.getCourseId().intValue())) {
  194. BigDecimal price = course.getClassType().equals(1) ? course.getPrice().multiply(BigDecimal.valueOf(buyCount)) : course.getPrice().multiply(BigDecimal.valueOf(course.getBuyCount()));
  195. amount = amount.add(price);
  196. remark += course.getClassName();
  197. if (course.getClassType().equals(1)) {
  198. course.setBuyCount(buyCount);
  199. }
  200. pickCourses.add(course);
  201. }
  202. }
  203. if (pickCourses.size() == 0) {
  204. return failed("请选择续费课程");
  205. }
  206. School school = schoolService.get(pickCourses.get(0).getClassId());
  207. if (school ==null){
  208. return failed("报名学校不存在");
  209. }
  210. String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //异步通知地址
  211. String returnUrl = "http://pay.dayaedu.com/login?schoolId=" + school.getId() + "&classId=" + pickCourses.get(0).getClassId() + "&cityId=" + school.getCityId();//支付后返回页面
  212. String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付跳转页
  213. String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
  214. String orderNo = GenerateNum.getInstance().GenerateOrderNo(); //自己系统订单号
  215. //获取支付成功跟支付中的订单数
  216. int branchId = renewals.getBranchId();
  217. int payOrderNums = orderService.getPayOrderNums();
  218. //分佣账户(1、每10笔,前四笔收入私户 2、私户每个商户最多收款400万)
  219. if ((payOrderNums + 1) % 10 <= 4) { //私人账户
  220. branchId = 0;
  221. }
  222. //获取分佣账户
  223. Account account = accountService.getAccountByBranchId(branchId);
  224. if (account == null) {
  225. return failed("机构没有设置收款账户");
  226. }
  227. String routingMerNo = account.getSellerNo();
  228. BigDecimal HasRouting = account.getHasRouting().add(amount);
  229. account.setHasRouting(HasRouting);
  230. Map<String, Object> routingList = new LinkedHashMap<String, Object>();
  231. routingList.put("routingMerNo", routingMerNo);//分佣账户
  232. routingList.put("routingFee", amount); //分佣金额
  233. List<Map> tempRoutingList = new ArrayList();
  234. tempRoutingList.add(routingList);
  235. renewalsService.addRenewalsOrder(renewals, amount, orderNo, pickCourses, routingMerNo,account.getId(), remark);
  236. /*订单信息*/
  237. String orderBody = "大雅乐盟培训课程";
  238. /*订单标题*/
  239. String orderSubject = "培训订单";
  240. //测试用
  241. amount = new BigDecimal("2");
  242. Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
  243. resultMap.put("sellerNo", "0021677"); //收款商户号
  244. resultMap.put("payChannels", payChannels); //支付方式
  245. resultMap.put("orderBody", orderBody); //订单信息
  246. resultMap.put("payAmount", amount); //支付金额
  247. resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
  248. resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
  249. resultMap.put("merMerOrderNo", orderNo); //商户订单号
  250. resultMap.put("orderSubject", orderSubject); //订单标题
  251. resultMap.put("returnUrl", returnUrl); //前台页面地址
  252. resultMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
  253. Map rqMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  254. rqMap.put("host", payUrl);
  255. return succeed(rqMap);
  256. }
  257. /**
  258. * 交易查询
  259. *
  260. * @param merOrderNoList 用户订单号
  261. * @return
  262. * @throws Exception
  263. */
  264. //@PostMapping("/query")
  265. //@Scheduled(cron = "0/3 40 11 * * ?")
  266. public Object query(String merOrderNoList) throws Exception {
  267. String notifyUrl = ""; //回调地址
  268. Map<String, Object> resultMap = new LinkedHashMap<>();
  269. resultMap.put("merOrderNoList", merOrderNoList);
  270. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  271. return yqQueryService.orderQuery(requestMap);
  272. }
  273. /**
  274. * 用户信息(商户)查询
  275. *
  276. * @param sonMerNo 子商户号
  277. * @return
  278. * @throws Exception
  279. */
  280. @PostMapping("/queryaccount")
  281. public String queryAccount(String sonMerNo) throws Exception {
  282. String notifyUrl = ""; //回调地址
  283. Map<String, Object> resultMap = new LinkedHashMap<>();
  284. resultMap.put("merOrderNoList", sonMerNo);
  285. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  286. return yqQueryService.queryAccount(requestMap);
  287. }
  288. /**
  289. * 对账查询(定时任务每天对账)
  290. *
  291. * @return
  292. */
  293. public String queryBill() throws Exception {
  294. String notifyUrl = ""; //回调地址
  295. Map<String, Object> resultMap = new LinkedHashMap<>();
  296. resultMap.put("tradeDate", ""); //交易日期
  297. resultMap.put("payState", ""); //订单状态
  298. resultMap.put("tradeType", ""); //交易类型,不填为全部
  299. resultMap.put("channelType", ""); //通道类型,不填为全部
  300. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  301. return yqQueryService.billQuery(requestMap);
  302. }
  303. /**
  304. * 平台转账
  305. *
  306. * @return
  307. * @throws Exception
  308. */
  309. @PostMapping("/platformtransferacc")
  310. public String platformTransferAcc() throws Exception {
  311. String notifyUrl = ""; //回调地址
  312. Map<String, Object> resultMap = new LinkedHashMap<>();
  313. resultMap.put("payeeNo", ""); //收款方商户号
  314. resultMap.put("payeeName", ""); //收款方姓名
  315. resultMap.put("amount", ""); //金额
  316. resultMap.put("merOrderNo", ""); //商户订单号
  317. resultMap.put("remarks", ""); //备注
  318. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  319. return yqPayService.platformTransferAcc(requestMap);
  320. }
  321. /**
  322. * 提现短信
  323. *
  324. * @return
  325. * @throws Exception
  326. */
  327. @PostMapping("/sendsms")
  328. public Msg sendSms(@ModelAttribute Intfc intfc) throws Exception {
  329. String notifyUrl = ""; //回调地址
  330. String merMerOrderNo = GenerateNum.getInstance().GenerateOrderNo();
  331. Map<String, Object> resultMap = new LinkedHashMap<>();
  332. resultMap.put("wdMerNo", intfc.getWdMerNo()); //提现商户号
  333. resultMap.put("merMerOrderNo", merMerOrderNo); //商户订单号
  334. resultMap.put("amount", intfc.getAmount()); //提现金额
  335. resultMap.put("cardNo", intfc.getCardNo()); //提现银行卡号
  336. // resultMap.put("phone", intfc.getPhone()); //预留手机号(选填)
  337. // resultMap.put("cardType", intfc.getCardType()); //卡类型 0-个人银行卡,1-企业银行卡。(选填)
  338. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  339. return yqPayService.intfc(requestMap);
  340. }
  341. /**
  342. * 提现
  343. *
  344. * @return
  345. * @throws Exception
  346. */
  347. @PostMapping("/intfc")
  348. public Msg intfc(@ModelAttribute Intfc intfc) throws Exception {
  349. String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //回调地址
  350. String merMerOrderNo = GenerateNum.getInstance().GenerateOrderNo();
  351. Map<String, Object> resultMap = new LinkedHashMap<>();
  352. resultMap.put("wdMerNo", intfc.getWdMerNo()); //提现商户号
  353. resultMap.put("merMerOrderNo", merMerOrderNo); //商户订单号
  354. resultMap.put("amount", intfc.getAmount()); //提现金额
  355. resultMap.put("cardNo", intfc.getCardNo()); //提现银行卡号
  356. // resultMap.put("phone", intfc.getPhone()); //预留手机号(选填)
  357. // resultMap.put("cardType", intfc.getCardType()); //卡类型 0-个人银行卡,1-企业银行卡。(选填)
  358. resultMap.put("seqNo", ""); //流水号(选填)
  359. resultMap.put("smsCode", ""); //验证码(选填)
  360. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  361. return yqPayService.intfc(requestMap);
  362. }
  363. /**
  364. * 易乾异步通知接口
  365. *
  366. * @param msg
  367. * @return String
  368. * @throws Exception
  369. */
  370. @PostMapping("/notify")
  371. public Msg notify(@ModelAttribute Msg msg) throws Exception {
  372. // log.info(msg.toString());
  373. Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
  374. rqMap.put("code", msg.getCode());
  375. rqMap.put("msg", msg.getMsg());
  376. rqMap.put("responseType", msg.getResponseType());
  377. rqMap.put("responseParameters", msg.getResponseParameters());
  378. rqMap.put("sign", msg.getSign());
  379. boolean rs = YqPayUtil.verify(rqMap);
  380. msg.setCode("");
  381. msg.setMsg("fail");
  382. Order order = null;
  383. NotifyMsg notifyMsg = null;
  384. if (rs) {
  385. notifyMsg = JSON.parseObject(msg.getResponseParameters(), NotifyMsg.class);
  386. String merMerOrderNo = notifyMsg.getMerMerOrderNo(); //自己系统订单号
  387. order = orderService.getOrderByOrderNo(merMerOrderNo);
  388. }
  389. //支付中订单存在,更新状态
  390. if (order != null && msg.getResponseType().equals("1")) {
  391. //更新订单状态
  392. int status = msg.getCode().equals("88") ? 2 : 0;
  393. order.setStatus(status);
  394. if (order.getOrderNo().isEmpty()) {
  395. order.setPayId(notifyMsg.getOrderNo()); //更新易乾付订单号
  396. }
  397. if (status == 2) {
  398. order.setPay(notifyMsg.getPayAmount());
  399. order.setPayTime(new Date());
  400. }
  401. orderService.update(order);
  402. ApplyInfo applyInfo = applyInfoService.get(order.getUserId());
  403. applyInfoService.userRegister(applyInfo.getPatriarchPhone(), order.getId()); //推送mec
  404. msg.setCode("000000");
  405. msg.setMsg("success");
  406. }
  407. return msg;
  408. }
  409. @Scheduled(cron = "0/5 * * * * ?")
  410. //@RequestMapping("/getOrderStatus")
  411. public void getOrderStatus() throws Exception {
  412. System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
  413. List<Order> payingOrders = orderService.findPayingOrders();
  414. String merOrderNos = ""; //
  415. for (int i = 0; i < payingOrders.size(); i++) {
  416. merOrderNos += payingOrders.get(i).getOrderNo() + ",";
  417. }
  418. if (merOrderNos.isEmpty()) {
  419. return;
  420. }
  421. merOrderNos = merOrderNos.substring(0, merOrderNos.length() - 1);
  422. String notifyUrl = ""; //回调地址
  423. Map<String, Object> resultMap = new LinkedHashMap<>();
  424. resultMap.put("merOrderNoList", merOrderNos);
  425. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  426. Msg queryRs = yqQueryService.orderQuery(requestMap);
  427. if (queryRs.getCode().equals("88")) {
  428. //更新订单状态
  429. String[] statusArr = {"0", "1", "7"};
  430. String responseParameters = queryRs.getResponseParameters();
  431. List<Map<String, String>> responseList = JSON.parseObject(responseParameters, List.class);
  432. for (int i = 0; i < responseList.size(); i++) {
  433. Map<String, String> rpMap = responseList.get(i);
  434. if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
  435. this.updateOrder(rpMap);
  436. }
  437. }
  438. }
  439. }
  440. @Transactional
  441. public void updateOrder(Map<String, String> rpMap) {
  442. int status = rpMap.get("tradeState").equals("1") ? 2 : 0;
  443. Order order = orderService.getOrderByOrderNo(rpMap.get("merOrderNo"));
  444. order.setStatus(status);
  445. order.setBank(rpMap.get("channelType"));
  446. if (order.getPayId() == null) {
  447. order.setPayId(rpMap.get("orderNo")); //更新易乾付订单号
  448. }
  449. if (status == 2) {
  450. order.setPay(order.getAmount());
  451. order.setPayTime(new Date());
  452. //推送mec
  453. if (order.getTuiFee() != null) { //乐团报名
  454. ApplyInfo applyInfo = applyInfoService.get(order.getUserId());
  455. applyInfo.setStatus(1);
  456. applyInfoService.update(applyInfo);
  457. applyInfoService.userRegister(applyInfo.getPatriarchPhone(), order.getId()); //推送mec
  458. } else {
  459. Renewals renewals = renewalsService.getRenewalsByOrderId(order.getId());
  460. RenewBean renewBean = new RenewBean();
  461. renewBean.setUserId(renewals.getUserId());
  462. renewBean.setClassId(renewals.getClassId());
  463. renewBean.setWay(renewals.getWay());
  464. renewBean.setPay(renewals.getPay());
  465. renewBean.setChargeMode(renewals.getChangeMode());
  466. renewBean.setBuy(new BigDecimal(renewals.getBuy()));
  467. renewBean.setPrice(renewals.getPrice());
  468. applyInfoService.pushRenew(renewBean);
  469. }
  470. }
  471. //失败减去已收款金额,减去报名人数
  472. if (status == 0 && order.getTuiFee() != null) {
  473. CourseGroupInfo courseGroupInfo = CourseGroupInfoService.get(order.getGroupId());
  474. courseGroupInfo.setRegNum(courseGroupInfo.getRegNum() - 1);
  475. CourseGroupInfoService.upByIdAndVersion(courseGroupInfo);
  476. }
  477. orderService.update(order);
  478. }
  479. }