| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- package com.minpay.common.service.impl;
- import java.util.Map;
- import com.min.util.CommonUtil;
- import com.minpay.common.bean.User;
- import com.minpay.common.exception.BusinessCodeException;
- import com.minpay.common.service.IOrderService;
- import com.minpay.common.service.IPublicService;
- import com.minpay.common.util.DateUtil;
- import com.minpay.db.table.mapper.VmEquipmentInfMapper;
- import com.minpay.db.table.mapper.VmOrderDetailsMapper;
- import com.minpay.db.table.mapper.VmOrderInfMapper;
- import com.minpay.db.table.mapper.VmProEquRelMapper;
- import com.minpay.db.table.model.VmEquipmentInf;
- import com.minpay.db.table.model.VmOrderDetails;
- import com.minpay.db.table.model.VmOrderInf;
- import com.minpay.db.table.model.VmPersonInf;
- import com.minpay.db.table.model.VmProEquRel;
- import com.startup.minpay.frame.exception.MINBusinessException;
- import com.startup.minpay.frame.service.base.IMINDataBaseService;
- import com.startup.minpay.frame.service.base.Service;
- import com.startup.minpay.frame.session.MINSession;
- import com.startup.minpay.frame.target.MINComponent;
- import net.sf.json.JSONArray;
- /**
- * 订单服务
- * @author ZHANGZZ
- */
- @MINComponent
- public class OrderServiceImpl implements IOrderService {
- @Override
- public void init() throws MINBusinessException {
-
- }
- @Override
- public String createOrderInf(String equNo, String proType, String proState, String payType, String payNumber, String detData, MINSession session,String gameRule) throws MINBusinessException {
- VmPersonInf newPerson = new VmPersonInf();
- //获取操作员
- User user = session.getUser();
- //获取当前时间--yyyyMMddHHmmss
- String nowTime = DateUtil.getCurrentDateTimeString();
- //验证售货机基本信息
- VmEquipmentInf equInf = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmEquipmentInfMapper.class)
- .selectByPrimaryKey(equNo);
- if(equInf == null){
- throw new BusinessCodeException("JINM1101");//售货机异常,请联系工作人员
- }
-
- if(!"00".equals(equInf.getState())){
- throw new BusinessCodeException("JINM1102");//售货机运行异常,请联系工作人员
- }
- //获取购买商品信息--验证
- if(CommonUtil.isEmpty(detData)){
- throw new BusinessCodeException("JINM0121");//商品信息异常
- }
-
- //获取订单主键
- String ordId = Service.lookup(IPublicService.class).getSequence("VM_ORDER_INF_ID");
- //初始化订单数据
- VmOrderInf ordInf = new VmOrderInf();
- ordInf.setId(ordId); //订单编号
- ordInf.setChannel(user.getChannel()); //渠道:V01售货机
- ordInf.setPersonId(user.getId()); //下单人编号
- ordInf.setEquipmentId(equNo); //售货机编号
- ordInf.setState("91"); //91未支付
- ordInf.setRemarks("会员下单,售货机编号:"+equNo); //备注
- ordInf.setIsDraw("00"); //是否中奖:00未中奖01中奖
- ordInf.setIsUsed("01"); //是否使用:00已使用01未使用
- ordInf.setProType(proType); //商品交易类别:00正常商品01抽奖商品
- ordInf.setRecordId(""); //结算编号
- ordInf.setProState(proState); //取货方式 00立即取货01放入卡包
- ordInf.setPayType(payType); //支付类型 1:1倍支付 3:3倍支付 5:5倍支付
- ordInf.setNumber(payNumber); //抽奖次数
- ordInf.setCreateUser(user.getId()); //创建人
- ordInf.setCreateTime(nowTime); //创建时间
- ordInf.setModifyUser(user.getId()); //修改人
- ordInf.setModifyTime(nowTime); //修改时间
- ordInf.setBranchid(equInf.getBranchid());
- ordInf.setGameRule(gameRule);
- //定义订单总金额
- String orderAmt = "0.00";
- //定义订单详情初始化详情编号的flag
- int flag = 0;
- //获取购买商品信息--转换对象
- JSONArray list = JSONArray.fromObject(detData);
- //循环新增订单详情
- for (int i = 0; i < list.size(); i++) {
- //获取map对象(商品下单信息)
- Map<String, String> map = (Map<String, String>)list.get(i);
- //获取商户商品编号
- String proRel = map.get("proRel");
- //获取下单商品数量
- String proNums = String.valueOf(map.get("proNums"));
- //获取下单商品数量及次数
- String proNumsAndPayNum = proNums;
- //验证下单数量
- if(!CommonUtil.isEmpty(proNums)){
- int proNum = Integer.valueOf(proNums);
- if(proNum > 0){
- //验证下单商品信息
- if(!CommonUtil.isEmpty(proRel)){
- //获取去商品基本信息
- VmProEquRel proInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmProEquRelMapper.class).selectByPrimaryKey(proRel);
- if(proInf == null) {
- throw new MINBusinessException("无此货");
- }
- //验证商品数量
- String oldNums = proInf.getProductNums();
- if(proNum > Integer.valueOf(oldNums)){
- throw new BusinessCodeException("JINM1103");//售货机当前商品余量不足,请联系工作人员
- }
- //组装商品货道
- String cargoWay = null;
- //判断货道指令,为空的用货道行列代替
- if(CommonUtil.isEmpty(proInf.getAisle())){
- cargoWay = proInf.getCargoWayRow().concat(proInf.getCargoWayLine());
- } else {
- cargoWay = proInf.getAisle();
- }
- // 订单详情表主键生成
- String detailId = null;
- if (flag < 10) {
- detailId = "0" + flag;
- } else {
- detailId = "" + flag;
- }
- detailId = ordId.concat(detailId);
- //获取商品单价--00正常商品01抽奖商品
- String proPrice = "0.00";
- if("00".equals(proType)){
- // //判断是否促销商品
- // String isPromotion = proInf.getIsPromotion();
- // //促销商品用促销价格
- // if("0".equals(isPromotion)){
- // proPrice = String.valueOf(proInf.getPromotionPrice());
- // }else{
- // //非促销商品用销售价
- // proPrice = String.valueOf(proInf.getSallPrice());
- // }
- proPrice = String.valueOf(proInf.getSallPrice());
- }else if("01".equals(proType)){
- //proNumsAndPayNum = CommonUtil.multiply(proNumsAndPayNum, payNumber);
- if(!CommonUtil.isEmpty(map.get("proPrice"))){
- //抽奖价格不为空的用抽奖价
- proPrice = String.valueOf(map.get("proPrice"));
- }else{
- //抽奖商品用游戏价
- proPrice = String.valueOf(proInf.getGamePrice());
- }
- }
- // 计算总金额
- String amount = CommonUtil.multiply(proPrice, proNumsAndPayNum);
- //初始化订单详情信息
- VmOrderDetails ordetInf = new VmOrderDetails();
- ordetInf.setDetailsId(detailId); //订单详情编号
- ordetInf.setChannel(user.getChannel()); //渠道V01售货机
- ordetInf.setOrderId(ordId); //订单编号
- ordetInf.setProEquRelId(proRel); //商户商品编号
- ordetInf.setProductId(proInf.getProductId()); //商品编号
- ordetInf.setCargoWay(cargoWay); //商品所在售货机货道编号
- ordetInf.setProType(proType); //商品类型:00正常商品01抽奖商品
- ordetInf.setProName(map.get("proName")); //尚品名称
- ordetInf.setProPrice(proPrice); //商品单价
- ordetInf.setProNums(proNums); //下单数量
- ordetInf.setAmount(amount); //总金额
- ordetInf.setRecordId(""); //结算编号
- ordetInf.setRemarks("会员下单,售货机编号:"+equNo+"商品编号:"+proRel);//备注
- ordetInf.setCreateUser(user.getId()); //创建人
- ordetInf.setCreateTime(nowTime); //创建时间
- ordetInf.setModifyUser(user.getId()); //修改人
- ordetInf.setModifyTime(nowTime); //修改时间
- //执行新增订单详情数据
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderDetailsMapper.class).insertSelective(ordetInf);
- //累加订单总金额
- orderAmt = CommonUtil.add(orderAmt, amount);
- flag ++;
- }
- }
- }else{
- continue;
- }
- }
- if(!CommonUtil.isEmpty(payType)){
- orderAmt = CommonUtil.multiply(orderAmt, payType);
- }
- ordInf.setOrderAmt(orderAmt); //订单总金额
- ordInf.setBranchid(equInf.getBranchid());
- //执行新增订单数据
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderInfMapper.class).insertSelective(ordInf);
- return ordId;
- }
- }
|