| package com.xzx.gc.order.service;  | 
|   | 
| import cn.hutool.core.convert.Convert;  | 
| import cn.hutool.core.util.NumberUtil;  | 
| import com.xzx.gc.common.constant.CommonEnum;  | 
| import com.xzx.gc.common.constant.Constants;  | 
| import com.xzx.gc.common.constant.OrderEnum;  | 
| import com.xzx.gc.common.exception.RestException;  | 
| import com.xzx.gc.common.utils.BusinessUtil;  | 
| import com.xzx.gc.entity.CityPartner;  | 
| import com.xzx.gc.entity.PartnerAccount;  | 
| import com.xzx.gc.entity.PartnerAccountLog;  | 
| import com.xzx.gc.model.admin.PartnerAccountLogModel;  | 
| import com.xzx.gc.model.admin.PartnerAccountModel;  | 
| import com.xzx.gc.order.mapper.PartnerAccountMapper;  | 
| import com.xzx.gc.util.DoubleUtil;  | 
| import lombok.extern.slf4j.Slf4j;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.stereotype.Service;  | 
| import org.springframework.transaction.annotation.Transactional;  | 
| import tk.mybatis.mapper.entity.Example;  | 
|   | 
| import java.math.BigDecimal;  | 
| import java.util.List;  | 
|   | 
| @Service  | 
| @Transactional  | 
| @Slf4j  | 
| public class PartnerAccountService {  | 
|   | 
|     @Autowired  | 
|     private PartnerAccountMapper partnerAccountMapper;  | 
|   | 
|     @Autowired  | 
|     private PartnerAccountLogService partnerAccountLogService;  | 
|   | 
|   | 
|     public PartnerAccount findByPartnerId(String partnerId){  | 
|         PartnerAccount partnerAccount=new PartnerAccount();  | 
|         partnerAccount.setPartnerId(partnerId);  | 
|         partnerAccount.setDelFlag(Constants.DEL_NOT_FLAG);  | 
|         PartnerAccount partnerAccount1 = partnerAccountMapper.selectOne(partnerAccount);  | 
|         return partnerAccount1;  | 
|     }  | 
|   | 
|   | 
|   | 
|     public PartnerAccount findByAccount(String accountId){  | 
|         PartnerAccount partnerAccount=new PartnerAccount();  | 
|         partnerAccount.setAccount(accountId);  | 
|         partnerAccount.setDelFlag(0);  | 
|         return partnerAccountMapper.selectOne(partnerAccount);  | 
|     }  | 
|   | 
|     public List<PartnerAccount> findByType(String type){  | 
|         PartnerAccount partnerAccount=new PartnerAccount();  | 
|         partnerAccount.setDelFlag(Constants.DEL_NOT_FLAG);  | 
|         partnerAccount.setType(type);  | 
|         return partnerAccountMapper.select(partnerAccount);  | 
|     }  | 
|   | 
|   | 
|   | 
|   | 
|     public void updateReduceMoneyByPartnerId(String partnerId,BigDecimal money){  | 
|         //判断合伙人账户的钱是否足够  | 
|         PartnerAccount byPartnerId = findByPartnerId(partnerId);  | 
|         BigDecimal bigDecimal = Convert.toBigDecimal(byPartnerId.getHbb(),Constants.MONEY_INIT);  | 
|         if(bigDecimal.compareTo(money)<0){  | 
|             throw new RestException(-1,"合伙人账户余额不足,支付失败");  | 
|         }  | 
|         partnerAccountMapper.updateReduceMoneyByPartnerId(partnerId,money);  | 
|     }  | 
|   | 
|     public void updateAddMoneyByPartnerId(String partnerId,BigDecimal money){  | 
|         partnerAccountMapper.updateAddMoneyByPartnerId(partnerId,money);  | 
|     }  | 
|   | 
|     public void addPartnerAccountLog(String money, CityPartner partner, String settleId){  | 
|         PartnerAccountLog partnerAccountLog = new PartnerAccountLog();  | 
|         partnerAccountLog.setPartnerId(partner.getId().toString());  | 
|         partnerAccountLog.setFlowNo(settleId);  | 
|         partnerAccountLog.setType(OrderEnum.结算提成.getValue());  | 
|         partnerAccountLog.setMoney("-" + money);  | 
|         partnerAccountLog.setAccountId(partner.getAccountNo());  | 
|         partnerAccountLog.setUserName(partner.getPartnerName());  | 
|         partnerAccountLog.setUserPhone(partner.getMobilePhone());  | 
|         partnerAccountLog.setRoleName("城市合伙人");  | 
|         partnerAccountLogService.add(partnerAccountLog);  | 
|   | 
|         //扣除  | 
|         updateReduceMoneyByPartnerId(partner.getId().toString(),Convert.toBigDecimal(money));  | 
|   | 
|     }  | 
| }  |