| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.model.dtos.community.wallet.ComActWalletDetailDTO; |
| | | import com.panzhihua.common.model.dtos.community.wallet.ComActWalletSettlementAdminDTO; |
| | | import com.panzhihua.common.model.dtos.community.wallet.PageComActWalletAdminDTO; |
| | | import com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.wallet.ComActWalletVO; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.service_community.dao.ComActEasyPhotoActivityMapper; |
| | | import com.panzhihua.service_community.dao.ComActEasyPhotoDAO; |
| | | import com.panzhihua.service_community.dao.ComActUserWalletMapper; |
| | | import com.panzhihua.service_community.model.dos.ComActEasyPhotoActivityDO; |
| | | import com.panzhihua.service_community.model.dos.ComActEasyPhotoDO; |
| | | import com.panzhihua.service_community.model.dos.ComActUserWalletDO; |
| | | import com.panzhihua.service_community.model.dos.ComActUserWalletTradeDO; |
| | | import com.panzhihua.service_community.service.ComActUserWalletChangeService; |
| | | import com.panzhihua.service_community.service.ComActUserWalletService; |
| | | import com.panzhihua.service_community.service.ComActUserWalletTradeService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class ComActUserWalletServiceImpl extends ServiceImpl<ComActUserWalletMapper, ComActUserWalletDO> implements ComActUserWalletService { |
| | | |
| | | @Resource |
| | | private ComActEasyPhotoDAO comActEasyPhotoDAO; |
| | | @Resource |
| | | private ComActEasyPhotoActivityMapper comActEasyPhotoActivityMapper; |
| | | @Resource |
| | | private ComActUserWalletMapper comActUserWalletMapper; |
| | | @Resource |
| | | private ComActUserWalletTradeService comActUserWalletTradeService; |
| | | @Resource |
| | | private ComActUserWalletChangeService comActUserWalletChangeService; |
| | | |
| | | /** |
| | | * 查询用户钱包信息 |
| | |
| | | Map<String,String> resultMap = this.baseMapper.getCommunityName(walletDetailDTO.getCommunityId()); |
| | | if(!resultMap.isEmpty()){ |
| | | comActWalletVO.setCommunityName(resultMap.get("name")); |
| | | comActWalletVO.setAgreement(resultMap.get("content")); |
| | | if(StringUtils.isEmpty(resultMap.get("content"))){ |
| | | this.baseMapper.insertSysAgreement(Constants.PROFIT_EXPLAIN,walletDetailDTO.getCommunityId()); |
| | | comActWalletVO.setAgreement(Constants.PROFIT_EXPLAIN); |
| | | }else{ |
| | | comActWalletVO.setAgreement(resultMap.get("content")); |
| | | } |
| | | |
| | | } |
| | | |
| | | Integer easyCount = 0; |
| | | //查询用户发布随手拍数量 |
| | | easyCount = comActEasyPhotoDAO.selectCount(new QueryWrapper<ComActEasyPhotoDO>().lambda() |
| | | .eq(ComActEasyPhotoDO::getSponsorId,walletDetailDTO.getUserId()) |
| | | .eq(ComActEasyPhotoDO::getCommunityId,walletDetailDTO.getCommunityId())); |
| | | comActWalletVO.setEasyCount(easyCount); |
| | | |
| | | return R.ok(comActWalletVO); |
| | | } |
| | | |
| | |
| | | return R.ok(this.baseMapper.getWalletRanking(new Page(walletTradeDTO.getPageNum(),walletTradeDTO.getPageSize()),walletTradeDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 随手拍审核通过给用户添加收益 |
| | | * @param easyPhotoId 随手拍id |
| | | */ |
| | | @Override |
| | | public void examineAddMoney(Integer activityType,Long easyPhotoId,Long userId){ |
| | | |
| | | //查询随手拍信息 |
| | | ComActEasyPhotoDO easyPhotoDO = comActEasyPhotoDAO.selectById(easyPhotoId); |
| | | if(easyPhotoDO == null){ |
| | | log.error("给用户添加收益失败,原因:未查到随手拍记录,随手拍id:" + easyPhotoId); |
| | | return; |
| | | } |
| | | |
| | | if(easyPhotoDO.getActivityId() == null){//用户未参加活动,无需添加收益 |
| | | log.error("给用户添加收益失败,原因:用户未参加活动,无需添加收益,随手拍id:" + easyPhotoId); |
| | | return; |
| | | } |
| | | |
| | | //查询随手拍活动 |
| | | ComActEasyPhotoActivityDO photoActivityDO = comActEasyPhotoActivityMapper.selectById(easyPhotoDO.getActivityId()); |
| | | if(photoActivityDO == null){ |
| | | log.error("给用户添加收益失败,原因:未查到活动记录,活动id:" + easyPhotoDO.getActivityId()); |
| | | return; |
| | | } |
| | | |
| | | // if(photoActivityDO.getStatus() != ComActEasyPhotoActivityDO.status.jxz){ |
| | | // log.error("给用户添加收益失败,原因:活动未在进行中,活动id:" + easyPhotoDO.getActivityId()); |
| | | // return; |
| | | // } |
| | | |
| | | |
| | | // Date nowDate = new Date(); |
| | | //查询用户钱包 |
| | | ComActUserWalletDO userWalletDO = comActUserWalletMapper.selectOne(new QueryWrapper<ComActUserWalletDO>() |
| | | .lambda().eq(ComActUserWalletDO::getUserId,easyPhotoDO.getSponsorId()).eq(ComActUserWalletDO::getCommunityId,easyPhotoDO.getCommunityId())); |
| | | if(userWalletDO == null){ |
| | | userWalletDO = new ComActUserWalletDO(); |
| | | userWalletDO.setIncomeAmount(BigDecimal.ZERO); |
| | | userWalletDO.setAvailableAmount(BigDecimal.ZERO); |
| | | userWalletDO.setSettlementAmount(BigDecimal.ZERO); |
| | | userWalletDO.setUserId(easyPhotoDO.getSponsorId()); |
| | | userWalletDO.setCommunityId(easyPhotoDO.getCommunityId()); |
| | | userWalletDO.setEasyCount(0); |
| | | userWalletDO.setCreateAt(new Date()); |
| | | this.baseMapper.insert(userWalletDO); |
| | | } |
| | | |
| | | //计算收益 |
| | | BigDecimal profitAmount = BigDecimal.ZERO; |
| | | if(activityType.equals(ComActEasyPhotoDO.activityType.yz)){ |
| | | profitAmount = photoActivityDO.getGoodReward(); |
| | | }else if(activityType.equals(ComActEasyPhotoDO.activityType.jl)){ |
| | | profitAmount = photoActivityDO.getExcellentReward(); |
| | | }else if(activityType.equals(ComActEasyPhotoDO.activityType.pt)){ |
| | | profitAmount = photoActivityDO.getOrdinaryReward(); |
| | | } |
| | | |
| | | if(profitAmount.compareTo(BigDecimal.ZERO) == 0){ |
| | | log.error("此次参加活动的随手拍收益为0,不记录本次交易"); |
| | | return; |
| | | }else{ |
| | | //记录钱包变动前金额 |
| | | BigDecimal oldIncomeAmount = userWalletDO.getIncomeAmount(); |
| | | BigDecimal oldAvailableAmount = userWalletDO.getAvailableAmount(); |
| | | BigDecimal oldSettlementAmount = userWalletDO.getSettlementAmount(); |
| | | |
| | | //更新钱包金额 |
| | | userWalletDO.setIncomeAmount(userWalletDO.getIncomeAmount().add(profitAmount)); |
| | | userWalletDO.setAvailableAmount(userWalletDO.getAvailableAmount().add(profitAmount)); |
| | | comActUserWalletMapper.updateById(userWalletDO); |
| | | |
| | | //新增钱包资金交易记录 |
| | | Long tradeId = comActUserWalletTradeService.addWalletTrade(easyPhotoDO.getSponsorId(),easyPhotoDO.getCommunityId() |
| | | ,easyPhotoDO.getId(),profitAmount, ComActUserWalletTradeDO.type.fb,"发布随手拍" |
| | | ,userId,userWalletDO.getId(),ComActUserWalletTradeDO.changeType.add); |
| | | |
| | | //新增钱包资金变动记录 |
| | | comActUserWalletChangeService.addWalletChange(easyPhotoDO.getSponsorId(),easyPhotoDO.getCommunityId(),userWalletDO.getId() |
| | | ,oldIncomeAmount,userWalletDO.getIncomeAmount(),oldAvailableAmount,userWalletDO.getAvailableAmount() |
| | | ,oldSettlementAmount,userWalletDO.getSettlementAmount(),tradeId); |
| | | } |
| | | //更新随手拍活动信息 |
| | | easyPhotoDO.setActivityType(activityType); |
| | | easyPhotoDO.setActivityAmount(profitAmount); |
| | | comActEasyPhotoDAO.updateById(easyPhotoDO); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询收益结算列表 |
| | | * @param pageWalletAdminDTO 请求参数 |
| | | * @return 收益结算列表 |
| | | */ |
| | | @Override |
| | | public R pageUserWalletAdmin(PageComActWalletAdminDTO pageWalletAdminDTO){ |
| | | return R.ok(this.baseMapper.getUserWalletList(new Page(pageWalletAdminDTO.getPageNum(),pageWalletAdminDTO.getPageSize()),pageWalletAdminDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 用户结算收益 |
| | | * @param settlementAdminDTO 请求参数 |
| | | * @return 结算结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R userWalletSettlementAdmin(ComActWalletSettlementAdminDTO settlementAdminDTO){ |
| | | //查询用户钱包 |
| | | ComActUserWalletDO userWalletDO = this.baseMapper.selectById(settlementAdminDTO.getId()); |
| | | if(userWalletDO == null){ |
| | | return R.fail("未查询到用户钱包"); |
| | | } |
| | | if(userWalletDO.getAvailableAmount().compareTo(settlementAdminDTO.getSettlementAmount()) < 0){ |
| | | return R.fail("结算金额不能高于钱包可结算金额"); |
| | | } |
| | | try { |
| | | BigDecimal oldIncomeAmount = userWalletDO.getIncomeAmount(); |
| | | BigDecimal oldAvailableAmount = userWalletDO.getAvailableAmount(); |
| | | BigDecimal oldSettlementAmount = userWalletDO.getSettlementAmount(); |
| | | userWalletDO.setAvailableAmount(userWalletDO.getAvailableAmount().subtract(settlementAdminDTO.getSettlementAmount())); |
| | | userWalletDO.setSettlementAmount(userWalletDO.getSettlementAmount().add(settlementAdminDTO.getSettlementAmount())); |
| | | userWalletDO.setUpdateAt(new Date()); |
| | | this.baseMapper.updateById(userWalletDO); |
| | | //添加钱包交易记录 |
| | | Long tradeServiceId = comActUserWalletTradeService.addWalletTrade(userWalletDO.getUserId(),userWalletDO.getCommunityId() |
| | | ,null,settlementAdminDTO.getSettlementAmount(),ComActUserWalletTradeDO.type.js |
| | | ,settlementAdminDTO.getRemark(),settlementAdminDTO.getUserId(),userWalletDO.getId(),ComActUserWalletTradeDO.changeType.reduce); |
| | | //添加钱包变动记录 |
| | | comActUserWalletChangeService.addWalletChange(userWalletDO.getUserId(),userWalletDO.getCommunityId(),userWalletDO.getId() |
| | | ,oldIncomeAmount,userWalletDO.getIncomeAmount(),oldAvailableAmount,userWalletDO.getAvailableAmount() |
| | | ,oldSettlementAmount,userWalletDO.getSettlementAmount(),tradeServiceId); |
| | | |
| | | return R.ok(); |
| | | }catch (Exception e){ |
| | | log.error("给用户结算收益失败,原因:" + e.getMessage()); |
| | | return R.fail("结算失败"); |
| | | } |
| | | } |
| | | |
| | | } |