ShouhuoPay.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. package com.minpay.common.pay;
  2. import com.huilian.api.open.huilianjavademo.XmlUtil;
  3. import com.min.base64.Base64;
  4. import com.min.des.DesUtils;
  5. import com.minpay.common.bean.User;
  6. import com.minpay.common.exception.BusinessCodeException;
  7. import com.minpay.common.pay.bean.Huilianpay;
  8. import com.minpay.common.service.*;
  9. import com.minpay.common.service.impl.DrawServiceImpl;
  10. import com.minpay.common.service.impl.HuilianPayServiceImpl;
  11. import com.minpay.common.util.CommonUtil;
  12. import com.minpay.common.util.DateUtil;
  13. import com.minpay.common.util.HttpPostUtil;
  14. import com.minpay.common.util.PayCommonUtil;
  15. import com.minpay.db.table.mapper.*;
  16. import com.minpay.db.table.model.*;
  17. import com.minpay.db.table.own.mapper.DeliveryMapper;
  18. import com.minpay.shouhuo.deliveryaction.DeliveryAction;
  19. import com.minpay.shouhuo.orderdrawaction.OrderDrawAction;
  20. import com.startup.minpay.frame.business.IMINAction;
  21. import com.startup.minpay.frame.business.MINHttpServletRequestContext;
  22. import com.startup.minpay.frame.business.res.MINActionResult;
  23. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  24. import com.startup.minpay.frame.exception.MINBusinessException;
  25. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  26. import com.startup.minpay.frame.service.base.Service;
  27. import com.startup.minpay.frame.session.MINSession;
  28. import com.startup.minpay.frame.target.MINAction;
  29. import com.startup.minpay.frame.target.MINComponent;
  30. import com.startup.minpay.frame.target.MINParam;
  31. import io.netty.util.internal.StringUtil;
  32. import net.sf.json.JSONObject;
  33. import org.apache.commons.lang.StringUtils;
  34. import javax.servlet.http.HttpServletRequest;
  35. import javax.servlet.http.HttpServletResponse;
  36. import java.io.BufferedReader;
  37. import java.io.InputStream;
  38. import java.io.InputStreamReader;
  39. import java.io.PrintWriter;
  40. import java.util.*;
  41. /**
  42. * 售货机支付通用接口
  43. * @author Zhumq
  44. *
  45. */
  46. @MINComponent
  47. public class ShouhuoPay implements IMINAction{
  48. /** 通用支付 */
  49. public final static String MIN_COMMMON_PAY = "minCommmonPay";
  50. /** PersonalPay支付回调 */
  51. public final static String PERSONALPAY_CALL_BACK = "personalPayCallBack";
  52. /** 查询PersonalPay的订单状态 */
  53. public final static String QUERY_PERSONALPAY_ORDERSTT = "queryPersonalpayOrderstt";
  54. /**
  55. * 通用支付
  56. * @param payAmt 支付总金额
  57. * @param orderId 支付订单号
  58. * @param payType 支付方式(01 账户支付、02 预付卡支付、03 网银支付、04快捷支付 91微信支付92支付宝支付 93钱包支付)
  59. * @param session
  60. * @param fapRequest
  61. * @return
  62. * @throws Exception
  63. */
  64. @MINAction(value = MIN_COMMMON_PAY, transaction = IMINTransactionEnum.CMT)
  65. public MINActionResult minCommmonPay(
  66. @MINParam(key = "payAmt") String payAmt,
  67. @MINParam(key = "orderId") String orderId,
  68. @MINParam(key = "payType", defaultValue = "91") String payType,
  69. MINSession session,
  70. MINHttpServletRequestContext fapRequest
  71. ) throws Exception {
  72. MINActionResult res = new MINActionResult();
  73. //获取操作员信息
  74. User user = session.getUser();
  75. //获取当前时间
  76. String nowTime = DateUtil.getCurrentDateTimeString();
  77. String oldID = orderId;
  78. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).selectByPrimaryKey(oldID);
  79. if(CommonUtil.compare(payAmt, ordInf.getOrderAmt()) != 0){
  80. throw new MINBusinessException("交易异常");//支付金额不对
  81. }
  82. VmPaymentInfExample paymentExp = new VmPaymentInfExample();
  83. paymentExp.createCriteria().andChannelEqualTo(user.getChannel()).andTranflownoEqualTo(orderId);
  84. List<VmPaymentInf> paymenList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).selectByExample(paymentExp);
  85. // 如果已经支付过一次
  86. if(paymenList.size() > 0) {
  87. // 0 初始状态,1成功,2失败,3在途,4待审核,5已审核
  88. if(!"0".equals(paymenList.get(0).getStatus())
  89. && !"3".equals(paymenList.get(0).getStatus())) {
  90. throw new MINBusinessException("订单已经在支付中!");
  91. }
  92. // 再次支付
  93. if("3".equals(paymenList.get(0).getStatus())) {
  94. // 复制订单明细/订单/支付流水
  95. // 支付状态修改
  96. ordInf.setState("80"); // 支付状态 80:已重新支付
  97. VmOrderInfExample orderExp = new VmOrderInfExample();
  98. orderExp.createCriteria().andIdEqualTo(oldID);
  99. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByExampleSelective(ordInf, orderExp);
  100. // 产生新的订单号
  101. orderId = DateUtil.getDifferentTimeByFormat("MMddHHmmss").concat(StringUtils.substring(orderId, 10));
  102. ordInf.setId(orderId);
  103. ordInf.setState("91");
  104. ordInf.setPayMode(payType);
  105. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).insert(ordInf);
  106. //获取订单下的详情信息
  107. VmOrderDetailsExample examp = new VmOrderDetailsExample();
  108. examp.createCriteria().andChannelEqualTo(user.getChannel()).andOrderIdEqualTo(oldID);
  109. List<VmOrderDetails> detailList = Service.lookup(IMINDataBaseService.class)
  110. .getMybatisMapper(VmOrderDetailsMapper.class)
  111. .selectByExample(examp);
  112. int flags = 0;
  113. // 循环插入明细表
  114. for(VmOrderDetails detDto : detailList) {
  115. String att = null;
  116. if(flags < 10){
  117. att = "0"+flags;
  118. }else{
  119. att = flags +"";
  120. }
  121. // 订单号
  122. detDto.setDetailsId(orderId.concat(att));
  123. detDto.setOrderId(orderId);
  124. detDto.setModifyUser(user.getId());
  125. detDto.setModifyTime(nowTime);
  126. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderDetailsMapper.class).insert(detDto);
  127. flags ++;
  128. }
  129. // 循环插入支付明细
  130. String flowno = Service.lookup(IPublicService.class).getSequence("VM_PAYMENT_INF_ID");
  131. for(VmPaymentInf payMentInf : paymenList) {
  132. //收支类型:00供应商收款01订单退款02平台分润03代理分润
  133. if("00".equals(payMentInf.getType())){
  134. payMentInf.setFlowno(nowTime.concat(flowno).concat("sh"));
  135. }else if("01".equals(payMentInf.getType())){
  136. payMentInf.setFlowno(nowTime.concat(flowno).concat("tk"));
  137. }else if("02".equals(payMentInf.getType())){
  138. payMentInf.setFlowno(nowTime.concat(flowno).concat("pt"));
  139. }else if("03".equals(payMentInf.getType())){
  140. payMentInf.setFlowno(nowTime.concat(flowno).concat("dl"));
  141. }
  142. payMentInf.setTranflowno(orderId);
  143. payMentInf.setTranmissiondatetime(nowTime);
  144. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  145. payMentInf.setStatus("3");
  146. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).insert(payMentInf);
  147. }
  148. }
  149. else {
  150. //修改支付方式
  151. ordInf.setPayMode(payType);
  152. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByPrimaryKeySelective(ordInf);
  153. VmPaymentInf paymentInf = new VmPaymentInf();
  154. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  155. paymentInf.setStatus("3");
  156. paymentInf.setTranflowno(orderId);
  157. paymentInf.setTranmissiondatetime(DateUtil.getCurrentDateTimeString());
  158. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).updateByExampleSelective(paymentInf, paymentExp);
  159. }
  160. }else{
  161. //修改支付方式
  162. ordInf.setPayMode(payType);
  163. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByPrimaryKeySelective(ordInf);
  164. }
  165. Map<String, Object> resMap = null;
  166. try {
  167. VmPaymentInf paymentInf = new VmPaymentInf();
  168. // 支付通道
  169. String payChannel = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() +"_PERSONALPAY_PAY_CHANNEL");
  170. //汇联
  171. if("HLZF".equals(payChannel)) {
  172. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByPrimaryKey(ordInf.getEquipmentId());
  173. if(equipmentInf == null) {
  174. throw new MINBusinessException("没有找到此售货机");
  175. }
  176. String payeeNo = equipmentInf.getPayeeNo();//收款账号
  177. VmHlAccount vmHlAccount = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmHlAccountMapper.class).selectByPrimaryKey(payeeNo);
  178. if(vmHlAccount == null || StringUtil.isNullOrEmpty(vmHlAccount.getNumber())){
  179. throw new MINBusinessException("商户收款账户异常");
  180. }
  181. //查询商户开通了那个支付渠道
  182. String pay_channel = vmHlAccount.getType();
  183. String accNo = vmHlAccount.getNumber();
  184. //支付后台回调地址
  185. String notify_url = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_SHOUHUO_NOTIFY_URL");
  186. //notify_url = "http://xubing2.minpay.cc/services";
  187. notify_url = notify_url + "/ShouhuoPay/personalPayCallBack";
  188. String turntablePage = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_SHOUHUO_TURNTABLE_PAGE");
  189. String turnPage ="";
  190. String gameRule = ordInf.getGameRule(); //游戏规则
  191. String proType = ordInf.getProType(); //交易类型
  192. if("00".equals(proType)){ //商品交易类别:00正常商品,01抽奖商品,02:充值
  193. turnPage = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_SHOUHUO_DIRECTBUY_PAGE");
  194. }else if("01".equals(proType)){
  195. if("0".equals(gameRule)){ //幸运购
  196. turnPage = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_SHOUHUO_LUCKYBUY_PAGE");
  197. }else if("1".equals(gameRule)){ //游戏购(老虎)
  198. turnPage = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_SHOUHUO_GAMEBUYING_PAGE");
  199. } else{
  200. throw new MINBusinessException("游戏类型异常");
  201. }
  202. }else{
  203. throw new MINBusinessException("交易类型异常");
  204. }
  205. turntablePage = turntablePage.concat("orderId="+orderId).concat("&equId="+ordInf.getEquipmentId()).concat(turnPage);
  206. Huilianpay prePay = new Huilianpay();
  207. IHuilianPayService huilianPayService = new HuilianPayServiceImpl();
  208. if("91".equals(payType)){
  209. payType = "WX";
  210. }
  211. if("92".equals(payType)){
  212. payType = "ALI";
  213. }
  214. prePay.setChannel(payType);
  215. prePay.setNotifyUrl(notify_url);
  216. prePay.setOpenId(user.getOpenid());
  217. prePay.setOutTradeNo(orderId);
  218. prePay.setProviderType(pay_channel);
  219. prePay.setTotalAmount(payAmt);
  220. prePay.setHlMerchantId(accNo);
  221. prePay.setGoodName(orderId);
  222. prePay.setSucUrl(turntablePage);
  223. resMap = huilianPayService.prePay(prePay);
  224. }
  225. } catch (Exception e) {
  226. throw new MINBusinessException("调用支付失败");
  227. }
  228. // 抽奖订单
  229. /*if("01".equals(ordInf.getProType())) {
  230. // 减余额
  231. // 创建用户基本账户
  232. IAccountService accservice = Service.lookup(IAccountService.class);
  233. // 41:消费
  234. accservice.modfiyAccount(ordInf.getChannel(), ordInf.getPersonId(), "01",
  235. CommonUtil.multiply(ordInf.getOrderAmt(), "-1"), "41", ordInf.getId(), "游戏消费");
  236. //调用真实回调
  237. backEx(ordInf.getId(), "0000000000", "TRADE_SUCCESS", ordInf.getOrderAmt(), "000000", "", "93");
  238. // 正常商品购买、但是选择的是钱包支付
  239. } if("00".equals(ordInf.getProType()) && "09".equals(payType)) {
  240. // 减余额
  241. // 创建用户基本账户
  242. IAccountService accservice = Service.lookup(IAccountService.class);
  243. // 41:消费
  244. accservice.modfiyAccount(ordInf.getChannel(), ordInf.getPersonId(), "01",
  245. CommonUtil.multiply(ordInf.getOrderAmt(), "-1"), "41", ordInf.getId(), "购买商品");
  246. //调用真实回调
  247. backEx(ordInf.getId(), "0000000000", "TRADE_SUCCESS", ordInf.getOrderAmt(), "000000", "", "93");
  248. }*/
  249. res.set("payMap",resMap);
  250. return res;
  251. }
  252. /**
  253. * 查询PersonalPay的订单状态
  254. * @param orderId 订单号
  255. * @param session
  256. * @return
  257. * @throws MINBusinessException
  258. */
  259. @MINAction(value = QUERY_PERSONALPAY_ORDERSTT)
  260. public MINActionResult queryPersonalpayOrderstt(
  261. @MINParam(key = "orderId") String orderId,
  262. MINSession session ) throws MINBusinessException {
  263. MINActionResult res = new MINActionResult();
  264. //获取操作员信息
  265. User user = session.getUser();
  266. try {
  267. VmOrderInf listch = Service.lookup(IMINDataBaseService.class)
  268. .getMybatisMapper(VmOrderInfMapper.class)
  269. .selectByPrimaryKey(orderId);
  270. if(listch.getState().equals("00")){
  271. res.set("orderId", orderId);
  272. res.set("stt", listch.getState());
  273. res.set("code", "200");
  274. // 00正常商品,01抽奖商品,02:充值',
  275. res.set("proType", listch.getProType());
  276. return res;
  277. }
  278. // 支付通道
  279. String payChannel = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() +"_PERSONALPAY_PAY_CHANNEL");
  280. String appSecret = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_PERSONALPAY_APP_SECRET");
  281. if("PEP".equals(payChannel)) {
  282. String appid = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_PERSONALPAY_APP_ID");
  283. String mchid = Service.lookup(IPublicService.class).getSysParValue(user.getChannel() + "_PERSONALPAY_MCH_ID");
  284. //创建PersonalPay订单对象
  285. SortedMap<Object, Object> perPay = new TreeMap<Object, Object>();
  286. perPay.put("mchid",mchid);//商户号
  287. perPay.put("appid", appid);//appId
  288. perPay.put("orderno",orderId);//交易订单号
  289. perPay.put("sysorderno","");//交易订单号
  290. perPay.put("signtype","MD5");//加密类型
  291. String paySign = PayCommonUtil.createSign("UTF-8", perPay, appSecret);
  292. perPay.put("sign",paySign);//加密后字符串
  293. /**
  294. * 返回值信息
  295. * 10:创建订单 80:已重新支付 90:已取消 91:未支付 92:支付中 00 :已支付, 01 :手动通知(掉单后可手动通知)
  296. * "stt":"10",
  297. * "code":0
  298. */
  299. //获取请求PersonalPay的路径"http://api.personalpay.net/api/";
  300. String url = Service.lookup(IPropertiesService.class)
  301. .getSystemProperties().get(user.getChannel() + "_PERSONALPAY_PAY_ADDRESS").getKey();
  302. String str = PayCommonUtil.getRequestJSON(perPay);
  303. String results = HttpPostUtil.sendPostFormachine(url.concat("/OrderAction/queryOrderStt"), str);
  304. //获取转义后响应信息
  305. JSONObject detail = JSONObject.fromObject(results);
  306. //获取code,用来判断是否认证成功
  307. String code = String.valueOf(detail.get("code"));
  308. if(!"0".equals(code)){
  309. throw new BusinessCodeException("JINM0115");//操作失败!
  310. }
  311. res.set("code", detail.get("code"));
  312. res.set("orderId", orderId);
  313. res.set("stt", detail.get("stt"));
  314. // 00正常商品,01抽奖商品,02:充值',
  315. res.set("proType", listch.getProType());
  316. }
  317. } catch (Exception e) {
  318. throw new MINBusinessException("调用支付查询失败");
  319. }
  320. return res;
  321. }
  322. /**
  323. * personalPay支付回调
  324. * @return
  325. * @throws Exception
  326. */
  327. @MINAction(value = PERSONALPAY_CALL_BACK, session = false)
  328. public MINActionResult personalPayCallBack(
  329. HttpServletRequest request,
  330. HttpServletResponse response
  331. ) throws Exception {
  332. MINActionResult res = new MINActionResult();
  333. /*StringBuffer sb = new StringBuffer() ;
  334. InputStream is = request.getInputStream();
  335. InputStreamReader isr = new InputStreamReader(is, "UTF-8");
  336. BufferedReader br = new BufferedReader(isr, 1024*1024);
  337. String s = "" ;
  338. while((s=br.readLine())!=null){
  339. System.out.println("数据解析:" + s);
  340. sb.append(s) ;
  341. }
  342. br.close();
  343. is.close(); //第一次关闭inputStream
  344. isr.close();
  345. PrintWriter printWriter = response.getWriter();
  346. printWriter.write("SUCCESS");
  347. printWriter.flush();//没有该句也是报一样错.
  348. printWriter.close();
  349. String result = sb.toString();
  350. XmlUtil xmlUtil = new XmlUtil();
  351. Map<String, Object> resMap = xmlUtil.parseb(result, "ant.mybank.bkmerchanttrade.prePayNotice");
  352. System.out.println("通知报文:" + resMap.toString());
  353. //支付宝或微信订单号 PayChannelOrderNo
  354. String payOrderno = resMap.get("PayChannelOrderNo").toString();
  355. //我方订单号 OutTradeNo
  356. String orderno = resMap.get("OutTradeNo").toString();
  357. //实付金额 BuyerPayAmount TotalAmount
  358. String amt = resMap.get("TotalAmount").toString();
  359. amt = CommonUtil.divide(amt,"100");
  360. //第三方订单号 OrderNo
  361. String sysorderno = resMap.get("OrderNo").toString();
  362. //查询订单如果已支付状态表示已经回调过*/
  363. String payOrderno = "123";
  364. String orderno = "1000000543";
  365. //实付金额 BuyerPayAmount TotalAmount
  366. String amt = "0.02";
  367. amt = CommonUtil.divide(amt,"100");
  368. //第三方订单号 OrderNo
  369. String sysorderno = "1233";
  370. //调用真实回调
  371. IDrawService drawService = new DrawServiceImpl();
  372. drawService.backEx(orderno, sysorderno, "TRADE_SUCCESS", amt,payOrderno, "", "");
  373. return res;
  374. }
  375. /**
  376. * 回调真实执行方法
  377. * @param orderno 商户流水号(订单)
  378. * @param sysorderno 交易流水号
  379. * @param status 状态
  380. * @param amt 交易金额
  381. * @param failReason 失败原因
  382. * @param payChannel 支付通道(04快捷支付 91微信支付92支付宝支付 93钱包支付)
  383. * @throws Exception
  384. */
  385. private void backEx(
  386. String orderno,
  387. String sysorderno,
  388. String status,
  389. String amt,
  390. String payOrderno,
  391. String failReason,
  392. String payChannel) throws Exception {
  393. // 交易流水号
  394. VmPaymentInfExample paymentExp = new VmPaymentInfExample();
  395. paymentExp.createCriteria().andTranflownoEqualTo(orderno);
  396. List<VmPaymentInf> payMentList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).selectByExample(paymentExp);
  397. if(payMentList.size() == 0) {
  398. throw new MINBusinessException("error");
  399. }
  400. // 0 初始状态 --如果已经通知过返回
  401. // 3在途
  402. if(!"0".equals(payMentList.get(0).getStatus())
  403. && !"3".equals(payMentList.get(0).getStatus())) {
  404. throw new MINBusinessException("error");
  405. }
  406. VmPaymentInf payMentInf = new VmPaymentInf();
  407. payMentInf.setBankflowno(sysorderno);
  408. // 支付方式(01 账户支付、02 预付卡支付、03 网银支付、04快捷支付 91微信支付92支付宝支付)
  409. if(CommonUtil.isNotEmpty(payChannel)) {
  410. payMentInf.setPaytype(payChannel);
  411. }
  412. VmOrderInf orderInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).selectByPrimaryKey(orderno);
  413. orderInf.setState("92"); // 92:支付中
  414. // TRADE_SUCCESS:交易成功,用户付款成功
  415. // TRADE_FINISHED:交易结束,付款金额已结算给商户
  416. // TRADE_CLOSED:交易关闭,交易失败
  417. if("TRADE_SUCCESS".equals(status)
  418. || "TRADE_FINISHED".equals(status)) {
  419. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  420. payMentInf.setStatus("1");
  421. payMentInf.setSuccamount(amt);//支付成功返还金额
  422. //支付成功时间
  423. payMentInf.setSucctime(DateUtil.getCurrentDateTimeString());
  424. orderInf.setState("00"); // 00:已支付
  425. orderInf.setPayOrderno(payOrderno); // 支付平台订单号(微信、支付宝订单号)
  426. }
  427. else if("TRADE_CLOSED".equals(status)) {
  428. // 交易状态(0 初始状态,1成功,2失败,3在途,4待审核,5已审核)
  429. payMentInf.setStatus("2");
  430. orderInf.setState("93"); // 93:支付失败
  431. }
  432. // 不是空
  433. if(!CommonUtil.isEmpty(failReason)) {
  434. payMentInf.setRemarktwo(failReason);
  435. }
  436. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPaymentInfMapper.class).updateByExampleSelective(payMentInf, paymentExp);
  437. // 变更待结算账户
  438. IAccountService service = Service.lookup(IAccountService.class);
  439. orderInf.setId(orderno);
  440. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmOrderInfMapper.class).updateByPrimaryKeySelective(orderInf);
  441. if("00".equals(orderInf.getState())){
  442. if("01".equals(orderInf.getProType())){
  443. //抽奖的商品走这里
  444. OrderDrawAction drawAction = new OrderDrawAction();
  445. drawAction.editOrderDraw(orderInf,sysorderno);
  446. }else if("00".equals(orderInf.getProType())){
  447. //购买商品走这里
  448. DeliveryAction.purchaseCreateDeliveryInfo(orderno,"");
  449. //执行推货
  450. // toMachine(orderInf.getChannel(), orderno);
  451. }
  452. // 充值
  453. else if("02".equals(orderInf.getProType())) {
  454. /**查询调账金额*/
  455. VmRechargeRule vmRechargeRule = Service.lookup(IMINDataBaseService.class)
  456. .getMybatisMapper(VmRechargeRuleMapper.class).selectByPrimaryKey(orderInf.getRechareRuleId());
  457. if(vmRechargeRule != null){
  458. }
  459. String giveAmt = vmRechargeRule.getGiveAmt();
  460. String rechargeAmt = vmRechargeRule.getRechargeAmt();
  461. String allAmt = CommonUtil.add(giveAmt, rechargeAmt);
  462. // 00充值(CZ)
  463. //todo 添加机器编号
  464. service.modfiyAccount(orderInf.getChannel(), orderInf.getPersonId(), "01", allAmt, "00", payMentList.get(0).getFlowno(), "充值",orderInf.getEquipmentId());
  465. }
  466. }
  467. }
  468. //推货方法
  469. private void toMachine(String channel , String orderNo) throws Exception{
  470. String url = Service.lookup(IPropertiesService.class)
  471. .getSystemProperties().get(channel + "_GET_MACHINE_ADDRESS").getKey();
  472. String retUrl = Service.lookup(IPropertiesService.class)
  473. .getSystemProperties().get(channel + "_RETURN_MACHINE_ADDRESS").getKey();
  474. //组装推送接口
  475. String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON");
  476. String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine");
  477. //组装传送参数
  478. //初始化查询条件
  479. Map<String,String> map = new HashMap<String,String>();
  480. map.put("orderNo", orderNo);//订单编号
  481. //传入渠道验证
  482. map.put("channel", channel);
  483. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  484. .getMybatisMapper(DeliveryMapper.class)
  485. .queryDeliverys(map);
  486. if(list != null && list.size() > 0){
  487. Map<String,String> mapNew = new HashMap<String,String>();
  488. mapNew.put("imeiAddr", list.get(0).get("equIMEI"));
  489. mapNew.put("cargoNo", list.get(0).get("cargoWay"));
  490. mapNew.put("deliveryNo", list.get(0).get("delveryNo"));
  491. mapNew.put("channel", channel);
  492. mapNew.put("returnUrl", returnUrl);
  493. mapNew.put("MINView", "JSON");
  494. JSONObject jsonOb = JSONObject.fromObject(mapNew);
  495. String str = jsonOb.toString();
  496. String passwardKey = Service.lookup(IPropertiesService.class)
  497. .getSystemProperties().get(channel +"_TO_MACHINE_PASSWORD_KEY").getKey();
  498. //数据加密
  499. String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null));
  500. //调用通用通讯接口
  501. String results = HttpPostUtil.sendPostFormachine(sendUrl,desDe);
  502. //获取转义后响应信息
  503. JSONObject detail = JSONObject.fromObject(results);
  504. String code = String.valueOf(detail.get("code"));
  505. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  506. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(list.get(0).get("delveryNo"));
  507. if(!"0".equals(code)){
  508. //改变提货状态为3卡货(提货失败)....
  509. delInf.setStatus("3");
  510. //throw new BusinessCodeException("JINM0011");//操作失败!
  511. }else{
  512. //获取处理状态
  513. String state = String.valueOf(detail.get("returnData"));
  514. JSONObject stateNew = JSONObject.fromObject(state);
  515. if("200".equals(stateNew.get("code"))){
  516. //改变提货状态为5处理中....
  517. delInf.setStatus("5");
  518. }else{
  519. //改变提货状态为3处理中....
  520. delInf.setStatus("3");
  521. //String msg = String.valueOf(stateNew.get("msg"));
  522. //throw new MINBusinessException(msg);//操作失败!
  523. }
  524. }
  525. //处理提货状态
  526. Service.lookup(IMINDataBaseService.class)
  527. .getMybatisMapper(VmDeliveryInfMapper.class)
  528. .updateByPrimaryKeySelective(delInf);
  529. }else{
  530. throw new MINBusinessException("没有提货信息!");
  531. }
  532. }
  533. }