DeliveryAction.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. package com.minpay.shouhuo.deliveryaction;
  2. import com.min.base64.Base64;
  3. import com.min.des.DesUtils;
  4. import com.min.util.OffSetUtil;
  5. import com.minpay.common.bean.DrawDto;
  6. import com.minpay.common.bean.User;
  7. import com.minpay.common.exception.BusinessCodeException;
  8. import com.minpay.common.format.IFormatService;
  9. import com.minpay.common.service.IPropertiesService;
  10. import com.minpay.common.service.IPublicService;
  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.db.table.mapper.VmDeliveryInfMapper;
  15. import com.minpay.db.table.mapper.VmOrderDetailsMapper;
  16. import com.minpay.db.table.mapper.VmOrderInfMapper;
  17. import com.minpay.db.table.mapper.VmProEquRelMapper;
  18. import com.minpay.db.table.model.*;
  19. import com.minpay.db.table.own.mapper.DeliveryMapper;
  20. import com.startup.minpay.frame.business.IMINAction;
  21. import com.startup.minpay.frame.business.res.MINActionResult;
  22. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  23. import com.startup.minpay.frame.data.format.MINCopyFormat;
  24. import com.startup.minpay.frame.exception.MINBusinessException;
  25. import com.startup.minpay.frame.jdbc.MINRowBounds;
  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 com.startup.minpay.util.Log;
  33. import net.sf.json.JSONObject;
  34. import javax.servlet.http.HttpServletResponse;
  35. import java.io.IOException;
  36. import java.util.HashMap;
  37. import java.util.List;
  38. import java.util.Map;
  39. /**
  40. * 售货机提货相关接口
  41. * @author Zhumq
  42. *
  43. */
  44. @MINComponent
  45. public class DeliveryAction implements IMINAction{
  46. /**查询提货信息*/
  47. public static final String QUERY_DELIVERY_INFO = "queryDeliveryInfo";
  48. /**修改提货信息*/
  49. public static final String MODIFY_DELIVERY_INFO = "modifyDeliveryInfo";
  50. /**提货接口*/
  51. public static final String MAKE_DELIVERY_FOR_MACHINE = "makeDeliveryForMachine";
  52. /**提货回调*/
  53. public static final String BACK_DELIVERY_FOR_MACHINE = "backDeliveryForMachine";
  54. /**
  55. * 查询提货信息
  56. * @param equNo 售货机编号
  57. * @param dates 创建时间
  58. * @param userNo 商户编号
  59. * @param status 提货状态
  60. * @param orderNo 订单编号
  61. * @param personNo 会员编号
  62. * @param page
  63. * @param limit
  64. * @param session
  65. * @return
  66. * @throws MINBusinessException
  67. */
  68. @MINAction(value = QUERY_DELIVERY_INFO)
  69. public MINActionResult queryDeliveryInfo(
  70. @MINParam(key = "equNo")String equNo,
  71. @MINParam(key = "dates")String dates,
  72. @MINParam(key = "userNo")String userNo,
  73. @MINParam(key = "status")String status,
  74. @MINParam(key = "orderNo")String orderNo,
  75. @MINParam(key = "personNo")String personNo,
  76. @MINParam(key = "page",defaultValue = "1")int page,
  77. @MINParam(key = "limit",defaultValue = "10")int limit,
  78. MINSession session) throws MINBusinessException{
  79. MINActionResult res = new MINActionResult();
  80. if(CommonUtil.isEmpty(equNo)){
  81. throw new BusinessCodeException("JINM1101");//售货机异常,请联系工作人员
  82. }
  83. //解密售货机编号
  84. String equNoNew = OffSetUtil.deScanCode(equNo);
  85. //获取操作员信息
  86. User user = session.getUser();
  87. //创建分页对象
  88. MINRowBounds row = new MINRowBounds(page, limit);
  89. //初始化查询条件
  90. Map<String,String> map = new HashMap<String,String>();
  91. map.put("orderNo", orderNo);//订单编号
  92. map.put("status", status);//提货状态
  93. map.put("userNo", userNo);//商户编号
  94. map.put("equNo", equNoNew);//售货机编号
  95. if(CommonUtil.isEmpty(personNo)){
  96. personNo = user.getId();
  97. }
  98. map.put("personNo", personNo);//会员编号
  99. map.put("dates", dates);//创建时间
  100. //传入渠道验证
  101. map.put("channel", user.getChannel());
  102. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  103. .getMybatisMapper(DeliveryMapper.class)
  104. .queryDeliveryInfo(map,row);
  105. //格式花时间和状态
  106. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime");
  107. list = new MINCopyFormat("{status:'statusDesc',proType:'proTypeDesc'}").format(list);
  108. list = Service.lookup(IFormatService.class).formatEnum(list,"{statusDesc:'VM_DELIVERY_STATUS',proTypeDesc:'PRO_TYPE'}");
  109. //传递返回值
  110. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  111. res.set(IMINBusinessConstant.F_PAGING_COUNT, row.getMaxRows());
  112. return res;
  113. }
  114. /**
  115. * 提货接口
  116. * @param orderNo 订单编号
  117. * @param deliveryNo 提货单编号
  118. * @param session
  119. * @return
  120. * @throws Exception
  121. */
  122. @MINAction(value = MAKE_DELIVERY_FOR_MACHINE)
  123. public MINActionResult makeDeliveryForMachine(
  124. @MINParam ( key = "orderNo")String orderNo,
  125. @MINParam ( key = "deliveryNo")String deliveryNo,
  126. MINSession session) throws Exception{
  127. MINActionResult res = new MINActionResult();
  128. User user = session.getUser();
  129. //获取售货机推送地址
  130. String url = Service.lookup(IPropertiesService.class)
  131. .getSystemProperties().get(user.getChannel() + "_GET_MACHINE_ADDRESS").getKey();
  132. String retUrl = Service.lookup(IPropertiesService.class)
  133. .getSystemProperties().get(user.getChannel() + "_RETURN_MACHINE_ADDRESS").getKey();
  134. //组装推送接口
  135. String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON");
  136. String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine");
  137. //组装传送参数
  138. //初始化查询条件
  139. Map<String,String> map = new HashMap<String,String>();
  140. map.put("deliveryNo", deliveryNo);//提货编号
  141. map.put("orderNo", orderNo);//订单编号
  142. //传入渠道验证
  143. map.put("channel", user.getChannel());
  144. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  145. .getMybatisMapper(DeliveryMapper.class)
  146. .queryDeliverys(map);
  147. if(CommonUtil.isEmpty(deliveryNo)){
  148. VmOrderInf orderInf = Service.lookup(IMINDataBaseService.class)
  149. .getMybatisMapper(VmOrderInfMapper.class)
  150. .selectByPrimaryKey(orderNo);
  151. //如果直接购买选择存入卡包则不进行推货
  152. if(orderInf.getProState().equals("01")){
  153. return res;
  154. }
  155. }
  156. // //未创建提货信息的执行新增
  157. // if(list == null || list.size() == 0){
  158. // MINActionResult result = createDeliveryInfoTwo(orderNo);
  159. // deliveryNo = result.get("dlId");
  160. // map.put("deliveryNo", deliveryNo);//提货编号
  161. // list = Service.lookup(IMINDataBaseService.class)
  162. // .getMybatisMapper(DeliveryMapper.class)
  163. // .queryDeliverys(map);
  164. // }
  165. if(list == null || list.size() == 0){
  166. throw new MINBusinessException("没有提货信息!");
  167. }
  168. if(CommonUtil.isEmpty(deliveryNo)){
  169. deliveryNo = list.get(0).get("deliveryNo");
  170. }
  171. VmDeliveryInf deliveryInf = Service.lookup(IMINDataBaseService.class)
  172. .getMybatisMapper(VmDeliveryInfMapper.class)
  173. .selectByPrimaryKey(deliveryNo);
  174. if(deliveryInf == null){
  175. throw new MINBusinessException("没有提货信息!");
  176. }
  177. if(deliveryInf.getProNums().equals(deliveryInf.getDeliveryNums())){
  178. throw new MINBusinessException("提货已完成!");
  179. }
  180. if(!deliveryInf.getStatus().equals("0")
  181. && !deliveryInf.getStatus().equals("1")){
  182. throw new MINBusinessException("提货处理中,请稍后!");
  183. }
  184. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  185. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo);
  186. //改变提货状态为5处理中....
  187. delInf.setStatus("5");
  188. //处理提货状态
  189. Service.lookup(IMINDataBaseService.class)
  190. .getMybatisMapper(VmDeliveryInfMapper.class)
  191. .updateByPrimaryKeySelective(delInf);
  192. Map<String,String> mapNew = new HashMap<String,String>();
  193. mapNew.put("imeiAddr", list.get(0).get("equIMEI"));
  194. mapNew.put("cargoNo", list.get(0).get("cargoWay"));
  195. mapNew.put("deliveryNo", deliveryNo);
  196. mapNew.put("channel", user.getChannel());
  197. mapNew.put("returnUrl", returnUrl);
  198. mapNew.put("orderNo", orderNo);
  199. mapNew.put("MINView", "JSON");
  200. JSONObject jsonOb = JSONObject.fromObject(mapNew);
  201. String str = jsonOb.toString();
  202. Log.info("通知售货机推货:".concat(str));
  203. String passwardKey = Service.lookup(IPropertiesService.class)
  204. .getSystemProperties().get(user.getChannel() +"_TO_MACHINE_PASSWORD_KEY").getKey();
  205. //数据加密
  206. String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null));
  207. // new Thread() {
  208. // public void run() {
  209. // HttpPostUtil.sendPostFormachine(sendUrl, desDe);
  210. // }
  211. // }.start();
  212. // //获取转义后响应信息
  213. // JSONObject detail = JSONObject.fromObject(results);
  214. // String code = String.valueOf(detail.get("code"));
  215. //
  216. // if(!"0".equals(code)){
  217. // Log.info("售货机退货失败:".concat(code));
  218. // //改变提货状态为3卡货(提货失败)....
  219. // delInf.setStatus("3");
  220. // //处理提货状态
  221. // Service.lookup(IMINDataBaseService.class)
  222. // .getMybatisMapper(VmDeliveryInfMapper.class)
  223. // .updateByPrimaryKeySelective(delInf);
  224. // throw new BusinessCodeException("JINM0011");//操作失败!
  225. // }
  226. //
  227. // //获取处理状态
  228. // String state = String.valueOf(detail.get("returnData"));
  229. // JSONObject stateNew = JSONObject.fromObject(state);
  230. // if(stateNew != null
  231. // && !"200".equals(String.valueOf(stateNew.get("code")))){
  232. // Log.info("售货机退货卡货:".concat(CommonUtil.objToString(stateNew.get("msg"))));
  233. // //改变提货状态为3卡货....
  234. // delInf.setStatus("3");
  235. // //处理提货状态
  236. // Service.lookup(IMINDataBaseService.class)
  237. // .getMybatisMapper(VmDeliveryInfMapper.class)
  238. // .updateByPrimaryKeySelective(delInf);
  239. // String msg = String.valueOf(stateNew.get("msg"));
  240. // throw new MINBusinessException(msg);//操作失败!
  241. // }
  242. String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe);
  243. // //获取转义后响应信息
  244. JSONObject detail = JSONObject.fromObject(results);
  245. String code = String.valueOf(detail.get("code"));
  246. if(!"0".equals(code)){
  247. Log.info("售货机退货失败:".concat(code));
  248. //改变提货状态为3卡货(提货失败)....
  249. delInf.setStatus("3");
  250. //处理提货状态
  251. Service.lookup(IMINDataBaseService.class)
  252. .getMybatisMapper(VmDeliveryInfMapper.class)
  253. .updateByPrimaryKeySelective(delInf);
  254. throw new BusinessCodeException("JINM0011");//操作失败!
  255. }
  256. //获取处理状态
  257. String state = String.valueOf(detail.get("returnData"));
  258. JSONObject stateNew = JSONObject.fromObject(state);
  259. if(stateNew != null
  260. && !"200".equals(String.valueOf(stateNew.get("code")))){
  261. Log.info("售货机退货卡货:".concat(CommonUtil.objToString(stateNew.get("msg"))));
  262. //改变提货状态为3卡货....
  263. delInf.setStatus("3");
  264. //处理提货状态
  265. Service.lookup(IMINDataBaseService.class)
  266. .getMybatisMapper(VmDeliveryInfMapper.class)
  267. .updateByPrimaryKeySelective(delInf);
  268. String msg = String.valueOf(stateNew.get("msg"));
  269. throw new MINBusinessException(msg);//操作失败!
  270. }else if("200".equals(String.valueOf(stateNew.get("code")))){
  271. //改变提货状态为2成功....
  272. delInf.setStatus("2");
  273. //处理提货状态
  274. Service.lookup(IMINDataBaseService.class)
  275. .getMybatisMapper(VmDeliveryInfMapper.class)
  276. .updateByPrimaryKeySelective(delInf);
  277. //修改货道商品数量
  278. String proEquRelId = delInf.getProEquRelId();
  279. VmProEquRel vmProEquRel = Service.lookup(IMINDataBaseService.class)
  280. .getMybatisMapper(VmProEquRelMapper.class)
  281. .selectByPrimaryKey(proEquRelId);
  282. String nums = vmProEquRel.getProductNums();
  283. nums = CommonUtil.add(nums,delInf.getDeliveryNums());
  284. vmProEquRel.setProductNums(nums);
  285. Service.lookup(IMINDataBaseService.class)
  286. .getMybatisMapper(VmProEquRelMapper.class)
  287. .updateByPrimaryKeySelective(vmProEquRel);
  288. VmOrderDetails vmOrderDetails = new VmOrderDetails();
  289. vmOrderDetails.setDetailsId(delInf.getOrdDetId());
  290. vmOrderDetails.setIsDelivery("01");
  291. Service.lookup(IMINDataBaseService.class)
  292. .getMybatisMapper(VmOrderDetailsMapper.class)
  293. .updateByPrimaryKeySelective(vmOrderDetails);
  294. //查询订单是否都提货
  295. VmOrderDetailsExample vmOrderDetailsExample = new VmOrderDetailsExample();
  296. vmOrderDetailsExample.createCriteria().andOrderIdEqualTo(orderNo).andDeliveryIdIsNotNull().andIsDeliveryEqualTo("00");
  297. List<VmOrderDetails> vmOrderDetailsList = Service.lookup(IMINDataBaseService.class)
  298. .getMybatisMapper(VmOrderDetailsMapper.class)
  299. .selectByExample(vmOrderDetailsExample);
  300. if(vmOrderDetailsList.size() == 0){
  301. VmOrderInf vmOrderInf = new VmOrderInf();
  302. vmOrderInf.setId(orderNo);
  303. vmOrderInf.setPickupStt("01");
  304. Service.lookup(IMINDataBaseService.class)
  305. .getMybatisMapper(VmOrderInfMapper.class)
  306. .updateByPrimaryKeySelective(vmOrderInf);
  307. }
  308. }
  309. return res;
  310. }
  311. /**
  312. * 提货回调
  313. * @param response
  314. * @param deliveryNo
  315. * @param outNums
  316. * @param status
  317. * @param failReason
  318. * @throws MINBusinessException
  319. */
  320. @MINAction(value = BACK_DELIVERY_FOR_MACHINE,session = false)
  321. public void backDeliveryForMachine(HttpServletResponse response,
  322. String deliveryNo,
  323. String outNums,
  324. String status,
  325. String failReason) throws MINBusinessException {
  326. // 给第三方传递回调成功信息
  327. try {
  328. if(response != null) {
  329. response.getOutputStream().write("Success".getBytes());
  330. response.flushBuffer();
  331. }
  332. } catch (IOException e) {
  333. e.printStackTrace();
  334. }
  335. // 出货后维护销量
  336. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  337. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo);
  338. //处理数量
  339. if(CommonUtil.isEmpty(outNums)){
  340. outNums = "0";
  341. }
  342. String newDelNUms = CommonUtil.add(delInf.getDeliveryNums(), outNums);
  343. int compare = CommonUtil.compare(delInf.getProNums(), newDelNUms);
  344. if(0 == compare ){
  345. delInf.setStatus("2");//已出货
  346. }else if(compare > 0){
  347. delInf.setStatus("1");//部分出货
  348. }
  349. delInf.setDeliveryNums(newDelNUms);
  350. //维护出货状态和数量
  351. Service.lookup(IMINDataBaseService.class)
  352. .getMybatisMapper(VmDeliveryInfMapper.class)
  353. .updateByPrimaryKeySelective(delInf);
  354. }
  355. /**
  356. * 创建提货信息
  357. * @return
  358. * @throws BusinessCodeException
  359. * @throws MINBusinessException
  360. */
  361. //@MINAction(value = "createDeliveryInfo",session = false)
  362. public static void createDeliveryInfo(
  363. List<DrawDto> drawDtoList
  364. ) throws BusinessCodeException, MINBusinessException{
  365. String nowTime = DateUtil.getCurrentDateTimeString();
  366. for (int i = 0; i < drawDtoList.size(); i++) {
  367. DrawDto drawDto = drawDtoList.get(i);
  368. String orderId = drawDto.getOrderId();
  369. String orderDetailsId = drawDto.getOrderDetailsId();
  370. //获取订单信息
  371. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class)
  372. .getMybatisMapper(VmOrderInfMapper.class)
  373. .selectByPrimaryKey(orderId);
  374. if(ordInf == null){
  375. throw new BusinessCodeException("JINM0114");//订单信息不存在
  376. }else{
  377. if(!"00".equals(ordInf.getState())){
  378. throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货
  379. }
  380. }
  381. VmOrderDetails detInf = Service.lookup(IMINDataBaseService.class)
  382. .getMybatisMapper(VmOrderDetailsMapper.class)
  383. .selectByPrimaryKey(orderDetailsId);
  384. //中奖的
  385. if(drawDto.isDraw()){
  386. //创建提货对象
  387. VmDeliveryInf dlInf = new VmDeliveryInf();
  388. //获取提货表主键
  389. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID");
  390. dlInf.setDeliveryId(dlId); //提货编号
  391. dlInf.setChannel(ordInf.getChannel()); //渠道
  392. dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号
  393. dlInf.setPersonId(ordInf.getPersonId()); //会员编号
  394. dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号
  395. dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品
  396. dlInf.setProName(detInf.getProName()); //商品名称
  397. dlInf.setProPrice(detInf.getProPrice()); //单价
  398. dlInf.setProNums(detInf.getProNums()); //为空取订单中的数量
  399. dlInf.setAmount(detInf.getAmount()); //金额
  400. dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零
  401. dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0
  402. dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道
  403. dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注
  404. dlInf.setCreateUser(ordInf.getPersonId()); //创建人
  405. dlInf.setCreateTime(nowTime); //创建时间
  406. dlInf.setModifyUser(ordInf.getPersonId()); //修改人
  407. dlInf.setModifyTime(nowTime); //修改时间
  408. dlInf.setBranchid(ordInf.getBranchid());
  409. dlInf.setProEquRelId(detInf.getProEquRelId());
  410. //执行新增提货信息
  411. Service.lookup(IMINDataBaseService.class)
  412. .getMybatisMapper(VmDeliveryInfMapper.class)
  413. .insertSelective(dlInf);
  414. //更新订单详情
  415. detInf.setDeliveryId(dlId);
  416. ordInf.setIsDraw("01");
  417. detInf.setIsWinning("01");
  418. Service.lookup(IMINDataBaseService.class)
  419. .getMybatisMapper(VmOrderDetailsMapper.class)
  420. .updateByPrimaryKeySelective(detInf);
  421. if(!ordInf.equals("01") && !ordInf.equals("02")){
  422. Service.lookup(IMINDataBaseService.class)
  423. .getMybatisMapper(VmOrderInfMapper.class)
  424. .updateByPrimaryKeySelective(ordInf);
  425. }
  426. /**没有中奖的*/
  427. }else{
  428. ordInf.setIsDraw("00");
  429. detInf.setIsWinning("02");
  430. Service.lookup(IMINDataBaseService.class)
  431. .getMybatisMapper(VmOrderDetailsMapper.class)
  432. .updateByPrimaryKeySelective(detInf);
  433. }
  434. }
  435. }
  436. /**
  437. * 创建提货信息
  438. * @param orderNo 订单编号
  439. * @return
  440. * @throws BusinessCodeException
  441. * @throws MINBusinessException
  442. */
  443. //@MINAction(value = "createDeliveryInfo",session = false)
  444. public MINActionResult createDeliveryInfoTwo(
  445. // @MINParam(key = "orderNo")
  446. String orderNo
  447. ) throws BusinessCodeException, MINBusinessException{
  448. MINActionResult res = new MINActionResult();
  449. String nowTime = DateUtil.getCurrentDateTimeString();
  450. //获取订单信息
  451. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class)
  452. .getMybatisMapper(VmOrderInfMapper.class)
  453. .selectByPrimaryKey(orderNo);
  454. if(ordInf == null){
  455. throw new BusinessCodeException("JINM0114");//订单信息不存在
  456. }else{
  457. if(!"00".equals(ordInf.getState())){
  458. throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货
  459. }
  460. }
  461. //获取已支付的,待提货的订单商品信息
  462. VmOrderDetailsExample examp = new VmOrderDetailsExample();
  463. examp.createCriteria().andChannelEqualTo(ordInf.getChannel()).andOrderIdEqualTo(orderNo);
  464. List<VmOrderDetails> ordetList = Service.lookup(IMINDataBaseService.class)
  465. .getMybatisMapper(VmOrderDetailsMapper.class)
  466. .selectByExample(examp);
  467. for (int i = 0; i < ordetList.size(); i++) {
  468. VmOrderDetails detInf = ordetList.get(i);
  469. if(detInf != null){
  470. //创建提货对象
  471. VmDeliveryInf dlInf = new VmDeliveryInf();
  472. //获取提货表主键
  473. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID");
  474. res.set("dlId", dlId);
  475. dlInf.setDeliveryId(dlId); //提货编号
  476. dlInf.setChannel(ordInf.getChannel()); //渠道
  477. dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号
  478. dlInf.setPersonId(ordInf.getPersonId()); //会员编号
  479. dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号
  480. dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品
  481. dlInf.setProName(detInf.getProName()); //商品名称
  482. dlInf.setProPrice(detInf.getProPrice()); //单价
  483. dlInf.setProNums(detInf.getProNums()); //数量
  484. dlInf.setAmount(detInf.getAmount()); //金额
  485. dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零
  486. dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0
  487. dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道
  488. dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注
  489. dlInf.setCreateUser(ordInf.getPersonId()); //创建人
  490. dlInf.setCreateTime(nowTime); //创建时间
  491. dlInf.setModifyUser(ordInf.getPersonId()); //修改人
  492. dlInf.setModifyTime(nowTime); //修改时间
  493. //执行新增提货信息
  494. Service.lookup(IMINDataBaseService.class)
  495. .getMybatisMapper(VmDeliveryInfMapper.class)
  496. .insert(dlInf);
  497. }
  498. }
  499. return res;
  500. }
  501. /**
  502. * 创建提货信息
  503. * @param orderNo 订单编号
  504. * @return
  505. * @throws BusinessCodeException
  506. * @throws MINBusinessException
  507. */
  508. //@MINAction(value = "createDeliveryInfo",session = false)
  509. public static void purchaseCreateDeliveryInfo(
  510. String orderNo,String drawNumber
  511. ) throws BusinessCodeException, MINBusinessException{
  512. String nowTime = DateUtil.getCurrentDateTimeString();
  513. //获取订单信息
  514. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class)
  515. .getMybatisMapper(VmOrderInfMapper.class)
  516. .selectByPrimaryKey(orderNo);
  517. if(ordInf == null){
  518. throw new BusinessCodeException("JINM0114");//订单信息不存在
  519. }else{
  520. if(!"00".equals(ordInf.getState())){
  521. throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货
  522. }
  523. }
  524. //获取已支付的,待提货的订单商品信息
  525. VmOrderDetailsExample examp = new VmOrderDetailsExample();
  526. examp.createCriteria().andChannelEqualTo(ordInf.getChannel()).andOrderIdEqualTo(orderNo);
  527. List<VmOrderDetails> ordetList = Service.lookup(IMINDataBaseService.class)
  528. .getMybatisMapper(VmOrderDetailsMapper.class)
  529. .selectByExample(examp);
  530. for (int i = 0; i < ordetList.size(); i++) {
  531. VmOrderDetails detInf = ordetList.get(i);
  532. if(detInf != null){
  533. //创建提货对象
  534. VmDeliveryInf dlInf = new VmDeliveryInf();
  535. //获取提货表主键
  536. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID");
  537. dlInf.setDeliveryId(dlId); //提货编号
  538. dlInf.setChannel(ordInf.getChannel()); //渠道
  539. dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号
  540. dlInf.setPersonId(ordInf.getPersonId()); //会员编号
  541. dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号
  542. dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品
  543. dlInf.setProName(detInf.getProName()); //商品名称
  544. dlInf.setProPrice(detInf.getProPrice()); //单价
  545. if(!CommonUtil.isEmpty(drawNumber)){
  546. dlInf.setProNums(drawNumber); //数量
  547. }else{
  548. dlInf.setProNums(detInf.getProNums()); //为空取订单中的数量
  549. }
  550. dlInf.setAmount(detInf.getAmount()); //金额
  551. dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零
  552. dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0
  553. dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道
  554. dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注
  555. dlInf.setCreateUser(ordInf.getPersonId()); //创建人
  556. dlInf.setCreateTime(nowTime); //创建时间
  557. dlInf.setModifyUser(ordInf.getPersonId()); //修改人
  558. dlInf.setModifyTime(nowTime); //修改时间
  559. dlInf.setProEquRelId(detInf.getProEquRelId()); //货道编号
  560. //执行新增提货信息
  561. Service.lookup(IMINDataBaseService.class)
  562. .getMybatisMapper(VmDeliveryInfMapper.class)
  563. .insert(dlInf);
  564. //订单明细表set提货单编号
  565. detInf.setDeliveryId(dlId);
  566. Service.lookup(IMINDataBaseService.class)
  567. .getMybatisMapper(VmOrderDetailsMapper.class)
  568. .updateByPrimaryKeySelective(detInf);
  569. }
  570. }
  571. }
  572. }