|  |  |  | 
|---|
|  |  |  | package com.matrix.system.shopXcx.mqTask; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.biz.bean.BizUser; | 
|---|
|  |  |  | import com.matrix.biz.service.BizUserService; | 
|---|
|  |  |  | import com.matrix.core.constance.MatrixConstance; | 
|---|
|  |  |  | import com.matrix.core.tools.LogUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.system.common.constance.AppConstance; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.matrix.system.constance.Dictionary; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dao.ShopSalesmanGradeDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dao.ShopSalesmanOrderDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.entity.ShopSalesmanOrder; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.*; | 
|---|
|  |  |  | import com.matrix.system.hive.dao.*; | 
|---|
|  |  |  | import com.matrix.system.hive.service.CodeService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.ShoppingGoodsService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysOrderService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysVipInfoService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopOrder; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopOrderDetails; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopSku; | 
|---|
|  |  |  | 
|---|
|  |  |  | ShopOrderDetailsDao shopOrderDetailsDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | BizUserService bizUserService; | 
|---|
|  |  |  | SysVipInfoService sysVipInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(needTb){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BizUser bizUser = bizUserService.findByOpenId(orderDto.getUserId()); | 
|---|
|  |  |  | SysVipInfo vipInfo = sysVipInfoService.findById(orderDto.getUserId()); | 
|---|
|  |  |  | SysOrder order = new SysOrder(); | 
|---|
|  |  |  | //TODO 根据公司id区分 | 
|---|
|  |  |  | SysVipInfo vipInfo = vipDao.selectByPhone(bizUser.getPhoneNumber()); | 
|---|
|  |  |  | if(SysVipInfo.UNDEAL_VIP==vipInfo.getIsDeal()){ | 
|---|
|  |  |  | //非成交客户下单更新客户为成交客户 | 
|---|
|  |  |  | vipInfo.setIsDeal(SysVipInfo.DEAL_VIP); | 
|---|
|  |  |  | 
|---|
|  |  |  | order.setTotal(orderDto.getOrderMoney().doubleValue()); | 
|---|
|  |  |  | order.setZkTotal(orderDto.getOrderMoney().doubleValue()); | 
|---|
|  |  |  | order.setPayTime(new Date()); | 
|---|
|  |  |  | order.setArrears(0); | 
|---|
|  |  |  | order.setArrears(0D); | 
|---|
|  |  |  | int i = sysOrderDao.insert(order); | 
|---|
|  |  |  | // 创建订单明细,并计算总价与折扣总价 | 
|---|
|  |  |  | int count = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | order.setDetails(orderDetails); | 
|---|
|  |  |  | //同步订单到erp | 
|---|
|  |  |  | synchronizationOrderToErp(order); | 
|---|
|  |  |  | //处理分销订单 | 
|---|
|  |  |  | handleExtensionOrder(order); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 处理分销订单 | 
|---|
|  |  |  | * @param order | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | void handleExtensionOrder(ShopOrder order) { | 
|---|
|  |  |  | //判读客户是否存在上级,存在则产生上级的收益 | 
|---|
|  |  |  | BizUser bizUser = bizUserService.findByOpenId(order.getUserId()); | 
|---|
|  |  |  | if(StringUtils.isNotBlank(bizUser.getParentOpenId())){ | 
|---|
|  |  |  | LogUtil.debug("处理分销订单userOpid={}",bizUser.getOpenId()); | 
|---|
|  |  |  | //存在上级 | 
|---|
|  |  |  | ShopSalesmanOrder shopSalesmanOrder=new ShopSalesmanOrder(); | 
|---|
|  |  |  | shopSalesmanOrder.setCompanyId(order.getCompanyId()); | 
|---|
|  |  |  | shopSalesmanOrder.setCreateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | shopSalesmanOrder.setUpdateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | shopSalesmanOrder.setCreateTime(new Date()); | 
|---|
|  |  |  | shopSalesmanOrder.setUpdateTime(new Date()); | 
|---|
|  |  |  | shopSalesmanOrder.setOrderId(Long.parseLong(order.getId()+"")); | 
|---|
|  |  |  | shopSalesmanOrder.setUserId(order.getUserId()); | 
|---|
|  |  |  | shopSalesmanOrder.setSalesUserId(bizUser.getParentOpenId()); | 
|---|
|  |  |  | shopSalesmanOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_SALES); | 
|---|
|  |  |  | shopSalesmanOrder.setOrderStatus(ShopSalesmanOrder.STATUS_DJS); | 
|---|
|  |  |  | Double amount=0D; | 
|---|
|  |  |  | for (ShopOrderDetails item:order.getDetails() ){ | 
|---|
|  |  |  | if(StringUtils.isNotBlank(item.getShopProduct().getAttrValues()) | 
|---|
|  |  |  | && item.getShopProduct().getAttrValues().contains("分销商城")){ | 
|---|
|  |  |  | if(item.getShopSku().getSealesPrice()==null | 
|---|
|  |  |  | ||item.getShopSku().getSealesPrice().doubleValue()==0){ | 
|---|
|  |  |  | //按分销等级计算 | 
|---|
|  |  |  | BizUser salesMan=bizUserService.findByOpenId(bizUser.getParentOpenId()); | 
|---|
|  |  |  | shopSalesmanGradeDao.selectById(salesMan.getSalesmanGrade()) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //按产品设置的金额计算 | 
|---|
|  |  |  | amount+=item.getShopSku().getSealesPrice().doubleValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | LogUtil.debug("不存在父级userOpid={}",bizUser.getOpenId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|