OrderServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.minpay.common.service.impl;
  2. import java.util.Map;
  3. import com.min.util.CommonUtil;
  4. import com.minpay.common.bean.User;
  5. import com.minpay.common.exception.BusinessCodeException;
  6. import com.minpay.common.service.IOrderService;
  7. import com.minpay.common.service.IPublicService;
  8. import com.minpay.common.util.DateUtil;
  9. import com.minpay.db.table.mapper.VmEquipmentInfMapper;
  10. import com.minpay.db.table.mapper.VmOrderDetailsMapper;
  11. import com.minpay.db.table.mapper.VmOrderInfMapper;
  12. import com.minpay.db.table.mapper.VmProEquRelMapper;
  13. import com.minpay.db.table.model.VmEquipmentInf;
  14. import com.minpay.db.table.model.VmOrderDetails;
  15. import com.minpay.db.table.model.VmOrderInf;
  16. import com.minpay.db.table.model.VmPersonInf;
  17. import com.minpay.db.table.model.VmProEquRel;
  18. import com.startup.minpay.frame.exception.MINBusinessException;
  19. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  20. import com.startup.minpay.frame.service.base.Service;
  21. import com.startup.minpay.frame.session.MINSession;
  22. import com.startup.minpay.frame.target.MINComponent;
  23. import net.sf.json.JSONArray;
  24. /**
  25. * 订单服务
  26. * @author ZHANGZZ
  27. */
  28. @MINComponent
  29. public class OrderServiceImpl implements IOrderService {
  30. @Override
  31. public void init() throws MINBusinessException {
  32. }
  33. @Override
  34. public String createOrderInf(String equNo, String proType, String proState, String payType, String payNumber, String detData, MINSession session,String gameRule) throws MINBusinessException {
  35. VmPersonInf newPerson = new VmPersonInf();
  36. //获取操作员
  37. User user = session.getUser();
  38. //获取当前时间--yyyyMMddHHmmss
  39. String nowTime = DateUtil.getCurrentDateTimeString();
  40. //验证售货机基本信息
  41. VmEquipmentInf equInf = Service.lookup(IMINDataBaseService.class)
  42. .getMybatisMapper(VmEquipmentInfMapper.class)
  43. .selectByPrimaryKey(equNo);
  44. if(equInf == null){
  45. throw new BusinessCodeException("JINM1101");//售货机异常,请联系工作人员
  46. }
  47. if(!"00".equals(equInf.getState())){
  48. throw new BusinessCodeException("JINM1102");//售货机运行异常,请联系工作人员
  49. }
  50. //获取购买商品信息--验证
  51. if(CommonUtil.isEmpty(detData)){
  52. throw new BusinessCodeException("JINM0121");//商品信息异常
  53. }
  54. //获取订单主键
  55. String ordId = Service.lookup(IPublicService.class).getSequence("VM_ORDER_INF_ID");
  56. //初始化订单数据
  57. VmOrderInf ordInf = new VmOrderInf();
  58. ordInf.setId(ordId); //订单编号
  59. ordInf.setChannel(user.getChannel()); //渠道:V01售货机
  60. ordInf.setPersonId(user.getId()); //下单人编号
  61. ordInf.setEquipmentId(equNo); //售货机编号
  62. ordInf.setState("91"); //91未支付
  63. ordInf.setRemarks("会员下单,售货机编号:"+equNo); //备注
  64. ordInf.setIsDraw("00"); //是否中奖:00未中奖01中奖
  65. ordInf.setIsUsed("01"); //是否使用:00已使用01未使用
  66. ordInf.setProType(proType); //商品交易类别:00正常商品01抽奖商品
  67. ordInf.setRecordId(""); //结算编号
  68. ordInf.setProState(proState); //取货方式 00立即取货01放入卡包
  69. ordInf.setPayType(payType); //支付类型 1:1倍支付 3:3倍支付 5:5倍支付
  70. ordInf.setNumber(payNumber); //抽奖次数
  71. ordInf.setCreateUser(user.getId()); //创建人
  72. ordInf.setCreateTime(nowTime); //创建时间
  73. ordInf.setModifyUser(user.getId()); //修改人
  74. ordInf.setModifyTime(nowTime); //修改时间
  75. ordInf.setBranchid(equInf.getBranchid());
  76. ordInf.setGameRule(gameRule);
  77. //定义订单总金额
  78. String orderAmt = "0.00";
  79. //定义订单详情初始化详情编号的flag
  80. int flag = 0;
  81. //获取购买商品信息--转换对象
  82. JSONArray list = JSONArray.fromObject(detData);
  83. //循环新增订单详情
  84. for (int i = 0; i < list.size(); i++) {
  85. //获取map对象(商品下单信息)
  86. Map<String, String> map = (Map<String, String>)list.get(i);
  87. //获取商户商品编号
  88. String proRel = map.get("proRel");
  89. //获取下单商品数量
  90. String proNums = String.valueOf(map.get("proNums"));
  91. //获取下单商品数量及次数
  92. String proNumsAndPayNum = proNums;
  93. //验证下单数量
  94. if(!CommonUtil.isEmpty(proNums)){
  95. int proNum = Integer.valueOf(proNums);
  96. if(proNum > 0){
  97. //验证下单商品信息
  98. if(!CommonUtil.isEmpty(proRel)){
  99. //获取去商品基本信息
  100. VmProEquRel proInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmProEquRelMapper.class).selectByPrimaryKey(proRel);
  101. if(proInf == null) {
  102. throw new MINBusinessException("无此货");
  103. }
  104. //验证商品数量
  105. String oldNums = proInf.getProductNums();
  106. if(proNum > Integer.valueOf(oldNums)){
  107. throw new BusinessCodeException("JINM1103");//售货机当前商品余量不足,请联系工作人员
  108. }
  109. //组装商品货道
  110. String cargoWay = null;
  111. //判断货道指令,为空的用货道行列代替
  112. if(CommonUtil.isEmpty(proInf.getAisle())){
  113. cargoWay = proInf.getCargoWayRow().concat(proInf.getCargoWayLine());
  114. } else {
  115. cargoWay = proInf.getAisle();
  116. }
  117. // 订单详情表主键生成
  118. String detailId = null;
  119. if (flag < 10) {
  120. detailId = "0" + flag;
  121. } else {
  122. detailId = "" + flag;
  123. }
  124. detailId = ordId.concat(detailId);
  125. //获取商品单价--00正常商品01抽奖商品
  126. String proPrice = "0.00";
  127. if("00".equals(proType)){
  128. // //判断是否促销商品
  129. // String isPromotion = proInf.getIsPromotion();
  130. // //促销商品用促销价格
  131. // if("0".equals(isPromotion)){
  132. // proPrice = String.valueOf(proInf.getPromotionPrice());
  133. // }else{
  134. // //非促销商品用销售价
  135. // proPrice = String.valueOf(proInf.getSallPrice());
  136. // }
  137. proPrice = String.valueOf(proInf.getSallPrice());
  138. }else if("01".equals(proType)){
  139. //proNumsAndPayNum = CommonUtil.multiply(proNumsAndPayNum, payNumber);
  140. if(!CommonUtil.isEmpty(map.get("proPrice"))){
  141. //抽奖价格不为空的用抽奖价
  142. proPrice = String.valueOf(map.get("proPrice"));
  143. }else{
  144. //抽奖商品用游戏价
  145. proPrice = String.valueOf(proInf.getGamePrice());
  146. }
  147. }
  148. // 计算总金额
  149. String amount = CommonUtil.multiply(proPrice, proNumsAndPayNum);
  150. //初始化订单详情信息
  151. VmOrderDetails ordetInf = new VmOrderDetails();
  152. ordetInf.setDetailsId(detailId); //订单详情编号
  153. ordetInf.setChannel(user.getChannel()); //渠道V01售货机
  154. ordetInf.setOrderId(ordId); //订单编号
  155. ordetInf.setProEquRelId(proRel); //商户商品编号
  156. ordetInf.setProductId(proInf.getProductId()); //商品编号
  157. ordetInf.setCargoWay(cargoWay); //商品所在售货机货道编号
  158. ordetInf.setProType(proType); //商品类型:00正常商品01抽奖商品
  159. ordetInf.setProName(map.get("proName")); //尚品名称
  160. ordetInf.setProPrice(proPrice); //商品单价
  161. ordetInf.setProNums(proNums); //下单数量
  162. ordetInf.setAmount(amount); //总金额
  163. ordetInf.setRecordId(""); //结算编号
  164. ordetInf.setRemarks("会员下单,售货机编号:"+equNo+"商品编号:"+proRel);//备注
  165. ordetInf.setCreateUser(user.getId()); //创建人
  166. ordetInf.setCreateTime(nowTime); //创建时间
  167. ordetInf.setModifyUser(user.getId()); //修改人
  168. ordetInf.setModifyTime(nowTime); //修改时间
  169. //执行新增订单详情数据
  170. Service.lookup(IMINDataBaseService.class)
  171. .getMybatisMapper(VmOrderDetailsMapper.class).insertSelective(ordetInf);
  172. //累加订单总金额
  173. orderAmt = CommonUtil.add(orderAmt, amount);
  174. flag ++;
  175. }
  176. }
  177. }else{
  178. continue;
  179. }
  180. }
  181. if(!CommonUtil.isEmpty(payType)){
  182. orderAmt = CommonUtil.multiply(orderAmt, payType);
  183. }
  184. ordInf.setOrderAmt(orderAmt); //订单总金额
  185. ordInf.setBranchid(equInf.getBranchid());
  186. //执行新增订单数据
  187. Service.lookup(IMINDataBaseService.class)
  188. .getMybatisMapper(VmOrderInfMapper.class).insertSelective(ordInf);
  189. return ordId;
  190. }
  191. }