123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package com.tour.api.service.impl;
- import cn.binarywang.wx.miniapp.api.WxMaService;
- import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.tour.api.service.ApiAgentCenterService;
- import com.tour.api.service.ApiMemberService;
- import com.tour.api.vo.AgentVo;
- import com.tour.api.vo.LoginVo;
- import com.tour.common.core.domain.entity.SysUser;
- import com.tour.common.core.domain.model.LoginBody;
- import com.tour.common.enums.UserStatus;
- import com.tour.common.exception.CustomException;
- import com.tour.common.utils.SecurityUtils;
- import com.tour.common.utils.StringUtils;
- import com.tour.common.utils.sign.Md5Utils;
- import com.tour.framework.web.service.TokenService;
- import com.tour.module.domain.*;
- import com.tour.module.service.*;
- import com.tour.module.vo.CardListVo;
- import com.tour.module.vo.CardVo;
- import com.tour.module.vo.OrderCommissonVo;
- import com.tour.system.service.ISysUserService;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import me.chanjar.weixin.common.error.WxErrorException;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.core.userdetails.UsernameNotFoundException;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 会员相关
- *
- * @author Leong
- * @description
- * @date 2021/1/20
- */
- @Slf4j
- @Service
- @RequiredArgsConstructor(onConstructor_ = @Autowired)
- public class ApiAgentCenterServiceImpl implements ApiAgentCenterService {
- private final ICardService iCardService;
- private final IOrderService iOrderService;
- private final IContactsService iContactsService;
- private final IAgentWithdrawalService iAgentWithdrawalService;
- private final IAgentService agentService;
- private final IOrderCommissonService orderCommissonService;
- private final ISysUserService userService;
- @Override
- public Map getUseCard(Long agentId) {
- Map map = new HashMap<>();
- List<Card> list = iCardService.list(new QueryWrapper<Card>().eq("agent_id", agentId));
- if (!CollectionUtils.isEmpty(list)) {
- List<Card> noUse = list.stream().filter(item -> "0".equals(item.getStatus())).collect(Collectors.toList());
- List<Card> use = list.stream().filter(item -> "1".equals(item.getStatus())).collect(Collectors.toList());
- map.put("noUseNum", noUse.size());
- map.put("useNum", use.size());
- map.put("totalNum", list.size());
- } else {
- map.put("noUseNum", 0);
- map.put("useNum", 0);
- map.put("totalNum", 0);
- }
- return map;
- }
- @Override
- public List<CardListVo> cardList(Long agentId, String status) {
- Card card = new Card();
- card.setAgentId(agentId);
- if (!"10".equals(status)) {
- card.setStatus(status);
- }
- List<CardListVo> res = new ArrayList<>();
- List<Card> list = iCardService.queryList(card);
- if (!CollectionUtils.isEmpty(list)) {
- list.forEach(i -> {
- CardListVo vo = new CardListVo();
- BeanUtils.copyProperties(i, vo);
- Order order = new Order();
- order.setCardKey(i.getCardKey());
- List<Order> orders = iOrderService.queryList(order);
- if (!CollectionUtils.isEmpty(orders)) {
- vo.setCreateTime(orders.get(0).getCreateTime());
- }
- res.add(vo);
- });
- }
- return res;
- }
- @Override
- public CardVo getCardOrder(String cardKey) {
- CardVo vo = new CardVo();
- Card card = iCardService.getOne(new QueryWrapper<Card>().eq("card_key", cardKey));
- if (card == null) {
- throw new CustomException("卡不存在");
- }
- if (card != null && !"1".equals(card.getStatus())) {
- throw new CustomException("卡未激活");
- }
- BeanUtils.copyProperties(card, vo);
- Order order = new Order();
- order.setCardKey(cardKey);
- List<Order> list = iOrderService.queryList(order);
- if (!CollectionUtils.isEmpty(list)) {
- vo.setCreateTime(list.get(0).getCreateTime());
- vo.setTravelDetail(list.get(0).getTravelDetail());
- String contactIds = list.get(0).getTravelerIds();
- List<String> ids = Arrays.asList(contactIds.split(","));
- List<Contacts> contactsList = iContactsService.list(new QueryWrapper<Contacts>().in("id", ids));
- vo.setContactsList(contactsList);
- }
- return vo;
- }
- @Override
- public Boolean withDrawal(AgentWithdrawal agentWithdrawal) {
- Agent agent = agentService.getById(agentWithdrawal.getAgentId());
- if (agent.getAmount().compareTo(agentWithdrawal.getAmount()) < 0) {
- throw new CustomException("提现金额超过可提现金额");
- }
- agent.setAmount(agent.getAmount().subtract(agentWithdrawal.getAmount()));
- agent.setWithdrawalAmount(agent.getWithdrawalAmount().add(agentWithdrawal.getAmount()));
- agentService.updateAgent(agent);
- Boolean result = iAgentWithdrawalService.save(agentWithdrawal);
- return result;
- }
- @Override
- public List<AgentWithdrawal> withDrawalList(Long agentId, Integer status) {
- AgentWithdrawal agentWithdrawal = new AgentWithdrawal();
- agentWithdrawal.setAgentId(agentId);
- if (status != 10) {
- agentWithdrawal.setStatus(status);
- }
- List<AgentWithdrawal> list = iAgentWithdrawalService.queryList(agentWithdrawal);
- return list;
- }
- @Override
- public List<OrderCommissonVo> commissonList(Long agentId) {
- return orderCommissonService.queryListByAgentId(agentId);
- }
- @Override
- public List<AgentVo> getGroupUser(Long agentId) {
- AgentVo vo = new AgentVo();
- List<AgentVo> list = new ArrayList<>();
- Agent agent = agentService.getById(agentId);
- BeanUtils.copyProperties(agent, vo);
- vo.setTotalAmount(agent.getAmount().add(agent.getWithdrawalAmount()));
- List<Agent> subAgents = agentService.list(new QueryWrapper<Agent>().eq("pid", agentId));
- if (!CollectionUtils.isEmpty(subAgents)) {
- BigDecimal subAmount = subAgents.stream().map(i -> {
- return i.getAmount().add(i.getWithdrawalAmount());
- }).reduce(BigDecimal.ZERO, BigDecimal::add);
- vo.setSubAmount(subAmount);
- list.add(vo);
- subAgents.forEach(i -> {
- AgentVo vo1 = new AgentVo();
- BeanUtils.copyProperties(i, vo1);
- vo1.setTotalAmount(i.getAmount().add(i.getWithdrawalAmount()));
- List<Agent> sAgents = agentService.list(new QueryWrapper<Agent>().eq("pid", i.getId()));
- if (!CollectionUtils.isEmpty(sAgents)) {
- BigDecimal sAmount = sAgents.stream().map(item -> {
- return item.getAmount().add(item.getWithdrawalAmount());
- }).reduce(BigDecimal.ZERO, BigDecimal::add);
- vo1.setSubAmount(sAmount);
- list.add(vo1);
- }
- });
- } else {
- Agent agent1 = agentService.getById(agent.getPid());
- if (agent1 != null) {
- vo.setPAgentName(agent1.getPAgentName());
- }
- }
- return list;
- }
- @Override
- public int updateAgentPass(Long agentId, String oldPassword, String password) {
- SysUser user = userService.queryByAgentId(agentId);
- if (user==null) {
- throw new CustomException("用户不存在");
- }
- else if(!SecurityUtils.matchesPassword(oldPassword,user.getPassword())){
- throw new CustomException("对不起,原密码错误");
- }
- user.setPassword(SecurityUtils.encryptPassword(password));
- return userService.resetPwd(user);
- }
- }
|