New file |
| | |
| | | package com.matrix; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.bean.BusParameterSettings; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.fenxiao.constant.FenxiaoSettingConstant; |
| | | import com.matrix.system.fenxiao.dao.ShopSalesmanGradeDao; |
| | | import com.matrix.system.fenxiao.dao.ShopSalesmanOrderDao; |
| | | import com.matrix.system.fenxiao.entity.ShopSalesmanGrade; |
| | | import com.matrix.system.fenxiao.entity.ShopSalesmanOrder; |
| | | import com.matrix.system.hive.dao.SysOrderDao; |
| | | import com.matrix.system.hive.dao.SysOrderItemDao; |
| | | import com.matrix.system.hive.dao.SysVipInfoDao; |
| | | 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.shopXcx.bean.ShopOrder; |
| | | import com.matrix.system.shopXcx.bean.ShopOrderDetails; |
| | | import com.matrix.system.shopXcx.bean.ShopProduct; |
| | | import com.matrix.system.shopXcx.bean.ShopSku; |
| | | import com.matrix.system.shopXcx.dao.ShopOrderDao; |
| | | import com.matrix.system.shopXcx.dao.ShopOrderDetailsDao; |
| | | import com.matrix.system.shopXcx.dao.ShopSkuDao; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @RunWith(SpringRunner.class) |
| | | @SpringBootTest(classes = {ZqErpApplication.class},webEnvironment =SpringBootTest.WebEnvironment.RANDOM_PORT) |
| | | public class SalesOrderTaskTest { |
| | | |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | ShopOrderDao shopOrderDao; |
| | | @Autowired |
| | | ShopOrderDetailsDao shopOrderDetailsDao; |
| | | |
| | | @Autowired |
| | | BizUserService bizUserService; |
| | | |
| | | |
| | | @Autowired |
| | | SysVipInfoDao vipDap; |
| | | |
| | | @Autowired |
| | | SysVipInfoDao vipDao; |
| | | |
| | | @Autowired |
| | | CodeService codeService; |
| | | |
| | | @Autowired |
| | | SysOrderDao sysOrderDao; |
| | | |
| | | @Autowired |
| | | ShoppingGoodsService shoppingGoodsService; |
| | | |
| | | @Autowired |
| | | SysOrderItemDao orderItemDao; |
| | | |
| | | @Autowired |
| | | SysOrderService orderService; |
| | | |
| | | @Autowired |
| | | ShopSkuDao shopSkuDao; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao parameterSettingsDao; |
| | | |
| | | |
| | | @Autowired |
| | | private ShopSalesmanOrderDao shopSalesmanOrderDao; |
| | | |
| | | @Autowired |
| | | private ShopSalesmanGradeDao shopSalesmanGradeDao; |
| | | |
| | | /** |
| | | * 处理分销订单 |
| | | * @param order |
| | | */ |
| | | @Test |
| | | public void handleExtensionOrder() { |
| | | ShopOrder order = new ShopOrder(); |
| | | order.setUserId("oJkRK4_pWN2kjp75B_G6oGSWawj0"); |
| | | order.setId(1190); |
| | | order.setCompanyId(36L); |
| | | |
| | | List<ShopOrderDetails> details = new ArrayList<ShopOrderDetails>(); |
| | | ShopOrderDetails shopOrderDetails = new ShopOrderDetails(); |
| | | shopOrderDetails.setTotalPrice(new BigDecimal(0.01)); |
| | | |
| | | ShopProduct shopProduct = new ShopProduct(); |
| | | shopProduct.setAttrValues("测试"); |
| | | shopProduct.setAbleSales(1); |
| | | |
| | | ShopSku shopSku = new ShopSku(); |
| | | shopOrderDetails.setShopSku(shopSku); |
| | | shopOrderDetails.setShopProduct(shopProduct); |
| | | shopOrderDetails.setCount(1); |
| | | details.add(shopOrderDetails); |
| | | |
| | | order.setDetails(details); |
| | | order.setOrderMoney(new BigDecimal(0.01)); |
| | | //判读客户是否存在上级,存在则产生上级的收益 |
| | | BizUser bizUser = bizUserService.findByOpenId(order.getUserId()); |
| | | LogUtil.debug("处理分销订单userOpid={}",bizUser.getOpenId()); |
| | | //判断是否重复生成 |
| | | QueryWrapper queryWrapper=new QueryWrapper(); |
| | | queryWrapper.eq("order_id",order.getId()); |
| | | Integer orderCount = shopSalesmanOrderDao.selectCount(queryWrapper); |
| | | if(orderCount==0){ |
| | | ShopSalesmanOrder salesmanOrder=new ShopSalesmanOrder(); |
| | | salesmanOrder.setCompanyId(order.getCompanyId()); |
| | | salesmanOrder.setCreateBy(MatrixConstance.SYSTEM_USER); |
| | | salesmanOrder.setUpdateBy(MatrixConstance.SYSTEM_USER); |
| | | salesmanOrder.setCreateTime(new Date()); |
| | | salesmanOrder.setUpdateTime(new Date()); |
| | | salesmanOrder.setOrderId(Long.parseLong(order.getId()+"")); |
| | | salesmanOrder.setUserId(order.getUserId()); |
| | | salesmanOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_SALES); |
| | | salesmanOrder.setOrderStatus(ShopSalesmanOrder.STATUS_DJS); |
| | | Double selfAmount=0D; |
| | | Double zk=1D; |
| | | //分销订单总额 |
| | | Double orderTotal=0D; |
| | | for (ShopOrderDetails item:order.getDetails() ){ |
| | | if(StringUtils.isNotBlank(item.getShopProduct().getAttrValues()) |
| | | && item.getShopProduct().getAbleSales()==ShopProduct.ABLE_SALES){ |
| | | orderTotal+=item.getTotalPrice().doubleValue(); |
| | | } |
| | | } |
| | | //自购返佣 |
| | | for (ShopOrderDetails item:order.getDetails() ){ |
| | | if(StringUtils.isNotBlank(item.getShopProduct().getAttrValues()) |
| | | && item.getShopProduct().getAbleSales()==ShopProduct.ABLE_SALES){ |
| | | //分销规则是否开启自购返佣 |
| | | BusParameterSettings zgfy = parameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_ZGFY, bizUser.getCompanyId()); |
| | | //按分销等级计算 |
| | | ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectById(bizUser.getSalesmanGrade()); |
| | | if(ObjectUtil.isNotEmpty(zgfy)) { |
| | | //获取商品的自购返佣价格,如果没有设置,在去获取当前推广人的等级的自购返佣比例 |
| | | if(StrUtil.isNotEmpty(zgfy.getParamValue()) && |
| | | FenxiaoSettingConstant.FX_ZGFY_YES.equals(zgfy.getParamValue())) { |
| | | if(item.getShopSku().getSelfPrice() == null |
| | | ||item.getShopSku().getSealesPrice().doubleValue() == 0){ |
| | | selfAmount+=item.getTotalPrice().doubleValue()*(shopSalesmanGrade.getSelfCommission()/100); |
| | | }else { |
| | | //按产品设置的自购返佣金额计算 |
| | | selfAmount+=item.getShopSku().getSelfPrice().doubleValue()*item.getCount(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //自购返佣记录 |
| | | if(selfAmount > 0) { |
| | | //整体的优惠金额折算成折扣,* 佣金 |
| | | zk=order.getOrderMoney().doubleValue()/orderTotal; |
| | | selfAmount=selfAmount*zk; |
| | | salesmanOrder.setAmount(selfAmount); |
| | | salesmanOrder.setSalesUserId(order.getUserId()); |
| | | shopSalesmanOrderDao.insert(salesmanOrder); |
| | | } |
| | | //存在上级 |
| | | if(StringUtils.isNotBlank(bizUser.getParentOpenId())) { |
| | | BizUser salesMan=bizUserService.findByOpenId(bizUser.getParentOpenId()); |
| | | Double salesAmount=0D; |
| | | Double invitationAmount=0D; |
| | | BizUser invitationMan=null; |
| | | ShopSalesmanOrder invitationOrder=null; |
| | | boolean hasInvitationMan=StringUtils.isNotBlank(salesMan.getParentOpenId()); |
| | | //判断推广员是否还存在上级,存在则计算邀请收益 |
| | | if(hasInvitationMan){ |
| | | invitationMan=bizUserService.findByOpenId(salesMan.getParentOpenId()); |
| | | invitationOrder=new ShopSalesmanOrder(); |
| | | BeanUtils.copyProperties(salesmanOrder,invitationOrder); |
| | | invitationOrder.setSalesUserId(invitationMan.getOpenId()); |
| | | invitationOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_INVITATION); |
| | | } |
| | | //收益计算 |
| | | for (ShopOrderDetails item:order.getDetails() ){ |
| | | if(StringUtils.isNotBlank(item.getShopProduct().getAttrValues()) |
| | | && item.getShopProduct().getAbleSales()==ShopProduct.ABLE_SALES){ |
| | | //按分销等级计算 |
| | | ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectById(salesMan.getSalesmanGrade()); |
| | | //推广提成,按分销等级计算或者按产品设置的推广金额计算 |
| | | if(item.getShopSku().getSealesPrice()==null |
| | | ||item.getShopSku().getSealesPrice().doubleValue()==0){ |
| | | salesAmount+=item.getTotalPrice().doubleValue()*(shopSalesmanGrade.getSealesCommission()/100); |
| | | }else{ |
| | | salesAmount+=item.getShopSku().getSealesPrice().doubleValue()*item.getCount(); |
| | | } |
| | | //邀请提成,获取商品的邀请提成价格和是否有上级推广人,如果没有设置,在去获取当前推广人的等级的自购返佣比例 |
| | | if(hasInvitationMan) { |
| | | if(item.getShopSku().getInvitationPrice() == null |
| | | ||item.getShopSku().getInvitationPrice().doubleValue() == 0){ |
| | | //获取上级的推广等级设置 |
| | | ShopSalesmanGrade invitationManGrade = shopSalesmanGradeDao.selectById(invitationMan.getSalesmanGrade()); |
| | | invitationAmount+=item.getTotalPrice().doubleValue()*(invitationManGrade.getInvitationCommission()/100); |
| | | }else { |
| | | //按产品设置的邀请提成价格计算 |
| | | invitationAmount+=item.getShopSku().getInvitationPrice().doubleValue()*item.getCount(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //推广提成记录 |
| | | if(salesAmount>0){ |
| | | //整体的优惠金额折算成折扣,* 佣金 |
| | | zk=order.getOrderMoney().doubleValue()/orderTotal; |
| | | salesAmount=salesAmount*zk; |
| | | salesmanOrder.setAmount(salesAmount); |
| | | salesmanOrder.setSalesUserId(bizUser.getParentOpenId()); |
| | | shopSalesmanOrderDao.insert(salesmanOrder); |
| | | } |
| | | //邀请提成记录 |
| | | if(invitationAmount > 0) { |
| | | //整体的优惠金额折算成折扣,* 佣金 |
| | | invitationAmount=invitationAmount*zk; |
| | | invitationOrder.setAmount(invitationAmount); |
| | | shopSalesmanOrderDao.insert(invitationOrder); |
| | | } |
| | | }else{ |
| | | LogUtil.debug("不存在父级userOpid={}",bizUser.getOpenId()); |
| | | } |
| | | }else{ |
| | | LogUtil.debug("重复订单id={}",order.getId()); |
| | | } |
| | | } |
| | | |
| | | } |