ShouhuoPay.java 22 KB

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