|  |  |  | 
|---|
|  |  |  | package com.matrix.system.fenxiao.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.StrUtil; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysVipInfo; | 
|---|
|  |  |  | import com.matrix.system.hive.dao.SysVipInfoDao; | 
|---|
|  |  |  | import com.matrix.core.constance.MatrixConstance; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.core.tools.WebUtil; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SysUsers; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dao.ShopRevenueFlowDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dao.ShopSalemanSettlementDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dao.ShopSalesmanOrderDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dto.LoadFenxiaoOrderBasicDto; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dto.LoadFenxiaoOrderListDto; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dto.LoadSetOrderListDtoDto; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dto.UpdateSetOrderDoneDto; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.entity.ShopRevenueFlow; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.entity.ShopSalemanSettlement; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.entity.ShopSalesmanOrder; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.vo.LoadFenxiaoOrderBasicVo; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.vo.LoadFenxiaoOrderListVo; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.vo.LoadSetOrderListDtoVo; | 
|---|
|  |  |  | import com.matrix.system.hive.action.util.QueryUtil; | 
|---|
|  |  |  | import com.matrix.system.hive.service.CodeService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopOrder; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopOrderDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @description 分销订单 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopSalesmanOrderDao shopSalesmanOrderDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | CodeService codeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopSalemanSettlementDao shopSalemanSettlementDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopRevenueFlowDao shopRevenueFlowDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopOrderDao shopOrderDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | SysVipInfoDao sysVipInfoDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public AjaxResult loadFenxiaoOrderBasic(LoadFenxiaoOrderBasicDto loadFenxiaoOrderBasicDto) { | 
|---|
|  |  |  | //设置用户公司ID | 
|---|
|  |  |  | 
|---|
|  |  |  | public AjaxResult updateSetOrderDone(UpdateSetOrderDoneDto updateSetOrderDoneDto) { | 
|---|
|  |  |  | //设置用户公司ID | 
|---|
|  |  |  | QueryUtil.setQueryLimitCom(updateSetOrderDoneDto); | 
|---|
|  |  |  | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  | Long companyId = updateSetOrderDoneDto.getCompanyId(); | 
|---|
|  |  |  | Integer setType = updateSetOrderDoneDto.getSetType(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String orderIds = updateSetOrderDoneDto.getOrderIds(); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | if(StrUtil.isNotEmpty(orderIds)){ | 
|---|
|  |  |  | List<Integer> idsList = new ArrayList<>(); | 
|---|
|  |  |  | List<String> idsStringList = Arrays.asList(orderIds.split(",")); | 
|---|
|  |  |  | if(CollUtil.isEmpty(idsStringList)) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("请至少选择一条记录"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //产生订单结算记录 | 
|---|
|  |  |  | ShopSalemanSettlement shopSalemanSettlement = new ShopSalemanSettlement(); | 
|---|
|  |  |  | shopSalemanSettlement.setCompanyId(companyId); | 
|---|
|  |  |  | shopSalemanSettlement.setCreateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | shopSalemanSettlement.setUpdateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | shopSalemanSettlement.setCreateTime(new Date()); | 
|---|
|  |  |  | shopSalemanSettlement.setUpdateTime(new Date()); | 
|---|
|  |  |  | shopSalemanSettlement.setOrderNo(codeService.getCodeByTyle(ShopSalemanSettlement.ORDERNO_START)); | 
|---|
|  |  |  | shopSalemanSettlement.setSettlementWay(setType); | 
|---|
|  |  |  | shopSalemanSettlement.setManCount(updateSetOrderDoneDto.getManCount()); | 
|---|
|  |  |  | shopSalemanSettlement.setOrderCount(updateSetOrderDoneDto.getOrderCount()); | 
|---|
|  |  |  | shopSalemanSettlement.setUserId(user.getSuId().intValue()); | 
|---|
|  |  |  | shopSalemanSettlement.setAmount(updateSetOrderDoneDto.getAmount()); | 
|---|
|  |  |  | shopSalemanSettlement.setRemark(updateSetOrderDoneDto.getRemark()); | 
|---|
|  |  |  | shopSalemanSettlement.setCompanyId(companyId); | 
|---|
|  |  |  | shopSalemanSettlementDao.insert(shopSalemanSettlement); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //记录收益流水 | 
|---|
|  |  |  | //         ShopRevenueFlow salesRevenueFlow=new ShopRevenueFlow(); | 
|---|
|  |  |  | //         salesRevenueFlow.setCompanyId(order.getCompanyId()); | 
|---|
|  |  |  | //         salesRevenueFlow.setCreateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | //         salesRevenueFlow.setUpdateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | //         salesRevenueFlow.setCreateTime(new Date()); | 
|---|
|  |  |  | //         salesRevenueFlow.setUpdateTime(new Date()); | 
|---|
|  |  |  | //         salesRevenueFlow.setAmount(salesAmount); | 
|---|
|  |  |  | //         salesRevenueFlow.setUserId(salesmanOrder.getSalesUserId()); | 
|---|
|  |  |  | //         salesRevenueFlow.setRevenueContent("推广收益"); | 
|---|
|  |  |  | //         salesRevenueFlow.setBusinessId(salesmanOrder.getOrderId()); | 
|---|
|  |  |  | //         shopRevenueFlowDao.insert(salesRevenueFlow); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //收益流水 | 
|---|
|  |  |  | //         ShopRevenueFlow invitationRevenueFlow=new ShopRevenueFlow(); | 
|---|
|  |  |  | //         invitationRevenueFlow.setCompanyId(order.getCompanyId()); | 
|---|
|  |  |  | //         invitationRevenueFlow.setCreateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | //         invitationRevenueFlow.setUpdateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | //         invitationRevenueFlow.setCreateTime(new Date()); | 
|---|
|  |  |  | //         invitationRevenueFlow.setUpdateTime(new Date()); | 
|---|
|  |  |  | //         invitationRevenueFlow.setAmount(salesAmount); | 
|---|
|  |  |  | //         invitationRevenueFlow.setUserId(invitationOrder.getSalesUserId()); | 
|---|
|  |  |  | //         invitationRevenueFlow.setRevenueContent("邀请收益"); | 
|---|
|  |  |  | //         invitationRevenueFlow.setBusinessId(invitationOrder.getOrderId()); | 
|---|
|  |  |  | //         shopRevenueFlowDao.insert(invitationRevenueFlow); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("操作成功"); | 
|---|
|  |  |  | for(String idString : idsStringList) { | 
|---|
|  |  |  | long id = Long.parseLong(idString); | 
|---|
|  |  |  | //更新分销订单 | 
|---|
|  |  |  | ShopSalesmanOrder shopSalesmanOrder = shopSalesmanOrderDao.selectById(id); | 
|---|
|  |  |  | if(!ShopSalesmanOrder.STATUS_DJS.equals(shopSalesmanOrder.getOrderStatus())) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("选中记录中存在【已结算】的记录"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //判断原始订单的状态【4=待评价, 5=已评价】才能结算 | 
|---|
|  |  |  | ShopOrder shopOrder = shopOrderDao.selectById(shopSalesmanOrder.getOrderId().intValue()); | 
|---|
|  |  |  | if(ShopOrder.ORDER_STATUS_WAIT_REMARK != shopOrder.getOrderStatus() && | 
|---|
|  |  |  | ShopOrder.ORDER_STATUS_ALREADY_REMARK != shopOrder.getOrderStatus()) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("未收货订单不允许结算"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | shopSalesmanOrder.setOrderStatus(ShopSalesmanOrder.STATUS_YJS); | 
|---|
|  |  |  | shopSalesmanOrder.setSettlementId(shopSalemanSettlement.getId()); | 
|---|
|  |  |  | shopSalesmanOrderDao.updateById(shopSalesmanOrder); | 
|---|
|  |  |  | //记录流水 | 
|---|
|  |  |  | ShopRevenueFlow salesRevenueFlow=new ShopRevenueFlow(); | 
|---|
|  |  |  | salesRevenueFlow.setCompanyId(companyId); | 
|---|
|  |  |  | salesRevenueFlow.setCreateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | salesRevenueFlow.setUpdateBy(MatrixConstance.SYSTEM_USER); | 
|---|
|  |  |  | salesRevenueFlow.setCreateTime(new Date()); | 
|---|
|  |  |  | salesRevenueFlow.setUpdateTime(new Date()); | 
|---|
|  |  |  | salesRevenueFlow.setAmount(shopSalesmanOrder.getAmount()); | 
|---|
|  |  |  | salesRevenueFlow.setUserId(shopSalesmanOrder.getSalesUserId()); | 
|---|
|  |  |  | if(ShopSalesmanOrder.REVENUE_TYPE_SALES.equals(shopSalesmanOrder.getRevenueType())) { | 
|---|
|  |  |  | salesRevenueFlow.setRevenueContent(ShopRevenueFlow.TYPE_TGSY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(ShopSalesmanOrder.REVENUE_TYPE_INVITATION.equals(shopSalesmanOrder.getRevenueType())) { | 
|---|
|  |  |  | salesRevenueFlow.setRevenueContent(ShopRevenueFlow.TYPE_YQSY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | salesRevenueFlow.setBusinessId(shopSalesmanOrder.getId()); | 
|---|
|  |  |  | shopRevenueFlowDao.insert(salesRevenueFlow); | 
|---|
|  |  |  | //选择微信余额支付,更新用户的金额 | 
|---|
|  |  |  | if(ShopSalemanSettlement.SETTLEMENTWAY_YEJS == updateSetOrderDoneDto.getSetType()) { | 
|---|
|  |  |  | SysVipInfo vipInfo = sysVipInfoDao.selectById(shopSalesmanOrder.getSalesUserId()); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(vipInfo)) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("收益人信息不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Double withdrawalCash = vipInfo.getWithdrawalCash(); | 
|---|
|  |  |  | Double amount = shopSalesmanOrder.getAmount(); | 
|---|
|  |  |  | withdrawalCash = (withdrawalCash == null?0:withdrawalCash)+(amount== null?0:amount); | 
|---|
|  |  |  | vipInfo.setWithdrawalCash(withdrawalCash); | 
|---|
|  |  |  | sysVipInfoDao.update(vipInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return AjaxResult.buildSuccessInstance("操作成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|