| | |
| | | package com.xzx.gc.user.service; |
| | | |
| | | import com.xzx.gc.user.vo.ViewSettingVo; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.xzx.gc.common.exception.RestException; |
| | | import com.xzx.gc.common.utils.StringUtils; |
| | | import com.xzx.gc.entity.AccountInfo; |
| | | import com.xzx.gc.entity.SysMessage; |
| | | import com.xzx.gc.entity.UserHeadRelate; |
| | | import com.xzx.gc.entity.UserShareInfo; |
| | | import com.xzx.gc.user.dto.HeadProfitLitDto; |
| | | import com.xzx.gc.user.dto.HeadTeamDto; |
| | | import com.xzx.gc.user.mapper.*; |
| | | import com.xzx.gc.user.vo.HeadInfoVo; |
| | | import com.xzx.gc.user.vo.HeadProfitListVo; |
| | | import com.xzx.gc.user.vo.HeadTeamVo; |
| | | import com.xzx.gc.user.dto.AdddistribDto; |
| | | import com.xzx.gc.user.dto.DistribInfoListDto; |
| | | import com.xzx.gc.user.dto.DistribListDto; |
| | | import com.xzx.gc.user.mapper.AccountMapper; |
| | | import com.xzx.gc.user.mapper.SysMessageMapper; |
| | | import com.xzx.gc.user.mapper.UserHeadRelateMapper; |
| | | import com.xzx.gc.user.mapper.UserShareInfoMapper; |
| | | import com.xzx.gc.user.vo.*; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xzx.gc.entity.RedPaperRule; |
| | | import com.xzx.gc.model.JsonResult; |
| | | import com.xzx.gc.user.dto.UpdateSettingDto; |
| | | import com.xzx.gc.user.mapper.RedPaperRuleMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class DistribService { |
| | | |
| | | @Resource |
| | | private RedPaperRuleMapper redPaperRuleMapper; |
| | | @Autowired |
| | | private UserHeadRelateMapper userHeadRelateMapper; |
| | | @Autowired |
| | | private UserHeadDetailsMapper userHeadDetailsMapper; |
| | | @Autowired |
| | | private AccountMapper accountMapper; |
| | | @Autowired |
| | | private UserShareInfoMapper userShareInfoMapper; |
| | | @Autowired |
| | | private SysMessageMapper sysMessageMapper; |
| | | |
| | | public ViewSettingVo viewSetting(Long id) { |
| | | public ViewSettingVo viewSetting(String ruleStr) { |
| | | ViewSettingVo viewSettingVo = new ViewSettingVo(); |
| | | RedPaperRule redPaperRule = redPaperRuleMapper.selectByRuleName(ruleStr); |
| | | if(ObjectUtil.isEmpty(redPaperRule)){ |
| | | viewSettingVo.setFristReward(BigDecimal.ZERO); |
| | | viewSettingVo.setOrderNumFrist(0); |
| | | viewSettingVo.setRegularPoint(0); |
| | | viewSettingVo.setRegularMoneyPercent(BigDecimal.ZERO); |
| | | viewSettingVo.setFinishOrderNum(0); |
| | | viewSettingVo.setPointReward(0); |
| | | viewSettingVo.setStatus((short) 0); |
| | | }else{ |
| | | String shareRatio = redPaperRule.getShareRatio(); |
| | | if(StrUtil.isNotEmpty(shareRatio)){ |
| | | List<String> shareRatios = StrUtil.split(shareRatio,',',false,false); |
| | | if(ObjectUtil.isNotEmpty(shareRatios)){ |
| | | viewSettingVo.setId(redPaperRule.getId()); |
| | | viewSettingVo.setFristReward(StrUtil.isEmpty(shareRatios.get(0))?BigDecimal.ZERO:new BigDecimal(shareRatios.get(0))); |
| | | viewSettingVo.setOrderNumFrist(StrUtil.isEmpty(shareRatios.get(1))?0:Integer.parseInt(shareRatios.get(1))); |
| | | viewSettingVo.setRegularPoint(StrUtil.isEmpty(shareRatios.get(2))?0:Integer.parseInt(shareRatios.get(2))); |
| | | viewSettingVo.setRegularMoneyPercent(StrUtil.isEmpty(shareRatios.get(3))?BigDecimal.ZERO:new BigDecimal(shareRatios.get(3))); |
| | | viewSettingVo.setFinishOrderNum(StrUtil.isEmpty(shareRatios.get(4))?0:Integer.parseInt(shareRatios.get(4))); |
| | | viewSettingVo.setPointReward(StrUtil.isEmpty(shareRatios.get(5))?0:Integer.parseInt(shareRatios.get(5))); |
| | | viewSettingVo.setStatus(redPaperRule.getStatus()); |
| | | } |
| | | }else{ |
| | | viewSettingVo.setId(redPaperRule.getId()); |
| | | viewSettingVo.setFristReward(BigDecimal.ZERO); |
| | | viewSettingVo.setOrderNumFrist(0); |
| | | viewSettingVo.setRegularPoint(0); |
| | | viewSettingVo.setRegularMoneyPercent(BigDecimal.ZERO); |
| | | viewSettingVo.setFinishOrderNum(0); |
| | | viewSettingVo.setPointReward(0); |
| | | viewSettingVo.setStatus((short) 0); |
| | | } |
| | | } |
| | | return viewSettingVo; |
| | | } |
| | | |
| | | |
| | | public void join(String headId, String userId) { |
| | | AccountInfo headInfo = accountMapper.selectOneByUserId(headId); |
| | | if (AccountInfo.IS_HEAD_N.equals(headInfo.getIsHead())) { |
| | | throw new RestException(-3, "不是团长"); |
| | | } |
| | | |
| | | if (AccountInfo.IS_PROHIBIT_Y.equals(headInfo.getIsProhibit())) { |
| | | throw new RestException(-3, "该用户被冻结"); |
| | | } |
| | | |
| | | UserHeadRelate existHeadRelate = userHeadRelateMapper.selectMemberByUserId(userId); |
| | | if (existHeadRelate != null) { |
| | | throw new RestException(-3, "已加入其他团队"); |
| | | } |
| | | |
| | | AccountInfo accountInfo = accountMapper.selectOneByUserId(userId); |
| | | UserShareInfo userShareInfo = userShareInfoMapper.selectByRegistPhone(accountInfo.getAccountName()); |
| | | if (userShareInfo != null) { |
| | | throw new RestException(-3, "您已与推广员绑定, 无法加入"); |
| | | } |
| | | |
| | | UserHeadRelate userHeadRelate = new UserHeadRelate(); |
| | | userHeadRelate.setHeadUserId(headId); |
| | | userHeadRelate.setUserId(userId); |
| | | userHeadRelate.setScore(BigDecimal.ZERO); |
| | | userHeadRelate.setAmount(BigDecimal.ZERO); |
| | | userHeadRelateMapper.insert(userHeadRelate); |
| | | |
| | | SysMessage sysMessage = new SysMessage(); |
| | | sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); |
| | | sysMessage.setCreateUserId(userId); |
| | | sysMessage.setMobilePhone(accountInfo.getAccountName()); |
| | | sysMessage.setMessageType("4"); |
| | | sysMessage.setMessage("手机号:" + accountInfo.getAccountName() + "的用户, 成功加入您的团队"); |
| | | sysMessage.setFlag("2"); |
| | | sysMessageMapper.insert(sysMessage); |
| | | } |
| | | |
| | | public HeadInfoVo findHeadInfo(String userId) { |
| | | AccountInfo accountInfo = accountMapper.selectOneByUserId(userId); |
| | | |
| | | HeadInfoVo headInfoVo = userHeadRelateMapper.selectHeadStatisticsData(userId); |
| | | if (headInfoVo == null) { |
| | | headInfoVo = new HeadInfoVo(); |
| | | } |
| | | |
| | | headInfoVo.setIsHead(accountInfo.getIsHead()); |
| | | return headInfoVo; |
| | | } |
| | | |
| | | public List<HeadProfitListVo> findHeadProfitListInPage(HeadProfitLitDto profitLitDto) { |
| | | PageHelper.startPage(profitLitDto.getPage(), profitLitDto.getLimit()); |
| | | return userHeadDetailsMapper.selectHeadProfitListInPage(profitLitDto.getUserId()); |
| | | } |
| | | |
| | | public List<HeadTeamVo> findHeadTeamListInPage(HeadTeamDto teamDto) { |
| | | PageHelper.startPage(teamDto.getPage(), teamDto.getLimit()); |
| | | return userHeadRelateMapper.selectHeadTeamListInPage(teamDto.getUserId()); |
| | | } |
| | | |
| | | public void addSetting(UpdateSettingDto model) { |
| | | RedPaperRule redPaperRule = new RedPaperRule(); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | BigDecimal fristReward = ObjectUtil.isEmpty(model.getFristReward()) ? BigDecimal.ZERO : model.getFristReward(); |
| | | stringBuffer.append(fristReward+","); |
| | | int orderNumFrist = ObjectUtil.isEmpty(model.getOrderNumFrist()) ? 0 : model.getOrderNumFrist(); |
| | | stringBuffer.append(orderNumFrist+","); |
| | | int regularPoint = ObjectUtil.isEmpty(model.getRegularPoint()) ? 0 : model.getRegularPoint(); |
| | | stringBuffer.append(regularPoint+","); |
| | | BigDecimal regularMoneyPercent = ObjectUtil.isEmpty(model.getRegularMoneyPercent()) ? BigDecimal.ZERO : model.getRegularMoneyPercent(); |
| | | stringBuffer.append(regularMoneyPercent+","); |
| | | int finishOrderNum = ObjectUtil.isEmpty(model.getFinishOrderNum()) ? 0 : model.getFinishOrderNum(); |
| | | stringBuffer.append(finishOrderNum+","); |
| | | int pointReward = ObjectUtil.isEmpty(model.getPointReward()) ? 0 : model.getPointReward(); |
| | | stringBuffer.append(pointReward); |
| | | redPaperRule.setStatus((short) 0); |
| | | redPaperRule.setRuleName("分销规则"); |
| | | redPaperRule.setSharingProfitType("frist_reward,order_num_frist,regular_point,regular_money_percent,finish_order_num,point_reward"); |
| | | redPaperRule.setShareRatio(stringBuffer.toString()); |
| | | redPaperRuleMapper.insert(redPaperRule); |
| | | } |
| | | |
| | | public void updateSetting(UpdateSettingDto model) { |
| | | RedPaperRule redPaperRule = redPaperRuleMapper.selectByPrimaryKey(model.getId()); |
| | | if(ObjectUtil.isNotEmpty(redPaperRule)){ |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | BigDecimal fristReward = ObjectUtil.isEmpty(model.getFristReward()) ? BigDecimal.ZERO : model.getFristReward(); |
| | | stringBuffer.append(fristReward+","); |
| | | int orderNumFrist = ObjectUtil.isEmpty(model.getOrderNumFrist()) ? 0 : model.getOrderNumFrist(); |
| | | stringBuffer.append(orderNumFrist+","); |
| | | int regularPoint = ObjectUtil.isEmpty(model.getRegularPoint()) ? 0 : model.getRegularPoint(); |
| | | stringBuffer.append(regularPoint+","); |
| | | BigDecimal regularMoneyPercent = ObjectUtil.isEmpty(model.getRegularMoneyPercent()) ? BigDecimal.ZERO : model.getRegularMoneyPercent(); |
| | | stringBuffer.append(regularMoneyPercent+","); |
| | | int finishOrderNum = ObjectUtil.isEmpty(model.getFinishOrderNum()) ? 0 : model.getFinishOrderNum(); |
| | | stringBuffer.append(finishOrderNum+","); |
| | | int pointReward = ObjectUtil.isEmpty(model.getPointReward()) ? 0 : model.getPointReward(); |
| | | stringBuffer.append(pointReward); |
| | | redPaperRule.setStatus(model.getStatus()); |
| | | redPaperRule.setSharingProfitType("frist_reward,order_num_frist,regular_point,regular_money_percent,finish_order_num,point_reward"); |
| | | redPaperRule.setShareRatio(stringBuffer.toString()); |
| | | redPaperRuleMapper.updateByPrimaryKey(redPaperRule); |
| | | } |
| | | } |
| | | |
| | | public Map<String, Object> distribList(DistribListDto distribListDto) { |
| | | PageHelper.startPage(distribListDto.getPage(), distribListDto.getLimit()); |
| | | if(StrUtil.isNotEmpty(distribListDto.getQueryCol())){ |
| | | String decode = StringUtils.encode(distribListDto.getQueryCol()); |
| | | distribListDto.setName(decode); |
| | | distribListDto.setPhone(distribListDto.getQueryCol()); |
| | | } |
| | | List<DistribListVo> distribListVos = accountMapper.selectDsitribListByQueryCol(distribListDto); |
| | | if(CollUtil.isNotEmpty(distribListVos)){ |
| | | for(DistribListVo distribListVo : distribListVos){ |
| | | String nickname = distribListVo.getNickname(); |
| | | String decode = StringUtils.decode(nickname); |
| | | distribListVo.setNickname(decode); |
| | | } |
| | | } |
| | | PageInfo<DistribListVo> pageInfo = new PageInfo<>(distribListVos); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | int count = Convert.toInt(pageInfo.getTotal()); |
| | | data.put("data", distribListVos); |
| | | data.put("count", count); |
| | | data.put("code", 0); |
| | | return data; |
| | | } |
| | | |
| | | public void adddistrib(AdddistribDto model) { |
| | | String id = model.getId(); |
| | | AccountInfo accountInfo = accountMapper.selectByPrimaryKey(id); |
| | | accountInfo.setIsHead(1); |
| | | accountMapper.updateByPrimaryKey(accountInfo); |
| | | } |
| | | |
| | | public Map<String, Object> distribInfoList(DistribInfoListDto distribInfoListDto) { |
| | | PageHelper.startPage(distribInfoListDto.getPage(), distribInfoListDto.getLimit()); |
| | | if(StrUtil.isNotEmpty(distribInfoListDto.getName())){ |
| | | String decode = StringUtils.encode(distribInfoListDto.getName()); |
| | | distribInfoListDto.setName(decode); |
| | | } |
| | | List<DistribInfoListVo> distribInfoListVos = accountMapper.selectDsitribInfoListByQueryCol(distribInfoListDto); |
| | | if(CollUtil.isNotEmpty(distribInfoListVos)){ |
| | | for(DistribInfoListVo distribInfoListVo : distribInfoListVos){ |
| | | String nickname = distribInfoListVo.getNickname(); |
| | | String decode = StringUtils.decode(nickname); |
| | | distribInfoListVo.setNickname(decode); |
| | | } |
| | | } |
| | | PageInfo<DistribInfoListVo> pageInfo = new PageInfo<>(distribInfoListVos); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | int count = Convert.toInt(pageInfo.getTotal()); |
| | | data.put("data", distribInfoListVos); |
| | | data.put("count", count); |
| | | data.put("code", 0); |
| | | return data; |
| | | |
| | | } |
| | | } |