ApiAgentCenterServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package com.tour.api.service.impl;
  2. import cn.binarywang.wx.miniapp.api.WxMaService;
  3. import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.tour.api.service.ApiAgentCenterService;
  6. import com.tour.api.service.ApiMemberService;
  7. import com.tour.api.vo.AgentVo;
  8. import com.tour.api.vo.LoginVo;
  9. import com.tour.common.core.domain.entity.SysUser;
  10. import com.tour.common.core.domain.model.LoginBody;
  11. import com.tour.common.enums.UserStatus;
  12. import com.tour.common.exception.CustomException;
  13. import com.tour.common.utils.SecurityUtils;
  14. import com.tour.common.utils.StringUtils;
  15. import com.tour.common.utils.sign.Md5Utils;
  16. import com.tour.framework.web.service.TokenService;
  17. import com.tour.module.domain.*;
  18. import com.tour.module.service.*;
  19. import com.tour.module.vo.CardListVo;
  20. import com.tour.module.vo.CardVo;
  21. import com.tour.module.vo.OrderCommissonVo;
  22. import com.tour.system.service.ISysUserService;
  23. import lombok.RequiredArgsConstructor;
  24. import lombok.extern.slf4j.Slf4j;
  25. import me.chanjar.weixin.common.error.WxErrorException;
  26. import org.springframework.beans.BeanUtils;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.security.core.userdetails.UsernameNotFoundException;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.util.CollectionUtils;
  31. import javax.annotation.Resource;
  32. import java.math.BigDecimal;
  33. import java.util.*;
  34. import java.util.stream.Collectors;
  35. /**
  36. * 会员相关
  37. *
  38. * @author Leong
  39. * @description
  40. * @date 2021/1/20
  41. */
  42. @Slf4j
  43. @Service
  44. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  45. public class ApiAgentCenterServiceImpl implements ApiAgentCenterService {
  46. private final ICardService iCardService;
  47. private final IOrderService iOrderService;
  48. private final IContactsService iContactsService;
  49. private final IAgentWithdrawalService iAgentWithdrawalService;
  50. private final IAgentService agentService;
  51. private final IOrderCommissonService orderCommissonService;
  52. private final ISysUserService userService;
  53. @Override
  54. public Map getUseCard(Long agentId) {
  55. Map map = new HashMap<>();
  56. List<Card> list = iCardService.list(new QueryWrapper<Card>().eq("agent_id", agentId));
  57. if (!CollectionUtils.isEmpty(list)) {
  58. List<Card> noUse = list.stream().filter(item -> "0".equals(item.getStatus())).collect(Collectors.toList());
  59. List<Card> use = list.stream().filter(item -> "1".equals(item.getStatus())).collect(Collectors.toList());
  60. map.put("noUseNum", noUse.size());
  61. map.put("useNum", use.size());
  62. map.put("totalNum", list.size());
  63. } else {
  64. map.put("noUseNum", 0);
  65. map.put("useNum", 0);
  66. map.put("totalNum", 0);
  67. }
  68. return map;
  69. }
  70. @Override
  71. public List<CardListVo> cardList(Long agentId, String status) {
  72. Card card = new Card();
  73. card.setAgentId(agentId);
  74. if (!"10".equals(status)) {
  75. card.setStatus(status);
  76. }
  77. List<CardListVo> res = new ArrayList<>();
  78. List<Card> list = iCardService.queryList(card);
  79. if (!CollectionUtils.isEmpty(list)) {
  80. list.forEach(i -> {
  81. CardListVo vo = new CardListVo();
  82. BeanUtils.copyProperties(i, vo);
  83. Order order = new Order();
  84. order.setCardKey(i.getCardKey());
  85. List<Order> orders = iOrderService.queryList(order);
  86. if (!CollectionUtils.isEmpty(orders)) {
  87. vo.setCreateTime(orders.get(0).getCreateTime());
  88. }
  89. res.add(vo);
  90. });
  91. }
  92. return res;
  93. }
  94. @Override
  95. public CardVo getCardOrder(String cardKey) {
  96. CardVo vo = new CardVo();
  97. Card card = iCardService.getOne(new QueryWrapper<Card>().eq("card_key", cardKey));
  98. if (card == null) {
  99. throw new CustomException("卡不存在");
  100. }
  101. if (card != null && !"1".equals(card.getStatus())) {
  102. throw new CustomException("卡未激活");
  103. }
  104. BeanUtils.copyProperties(card, vo);
  105. Order order = new Order();
  106. order.setCardKey(cardKey);
  107. List<Order> list = iOrderService.queryList(order);
  108. if (!CollectionUtils.isEmpty(list)) {
  109. vo.setCreateTime(list.get(0).getCreateTime());
  110. vo.setTravelDetail(list.get(0).getTravelDetail());
  111. String contactIds = list.get(0).getTravelerIds();
  112. List<String> ids = Arrays.asList(contactIds.split(","));
  113. List<Contacts> contactsList = iContactsService.list(new QueryWrapper<Contacts>().in("id", ids));
  114. vo.setContactsList(contactsList);
  115. }
  116. return vo;
  117. }
  118. @Override
  119. public Boolean withDrawal(AgentWithdrawal agentWithdrawal) {
  120. Agent agent = agentService.getById(agentWithdrawal.getAgentId());
  121. if (agent.getAmount().compareTo(agentWithdrawal.getAmount()) < 0) {
  122. throw new CustomException("提现金额超过可提现金额");
  123. }
  124. agent.setAmount(agent.getAmount().subtract(agentWithdrawal.getAmount()));
  125. agent.setWithdrawalAmount(agent.getWithdrawalAmount().add(agentWithdrawal.getAmount()));
  126. agentService.updateAgent(agent);
  127. Boolean result = iAgentWithdrawalService.save(agentWithdrawal);
  128. return result;
  129. }
  130. @Override
  131. public List<AgentWithdrawal> withDrawalList(Long agentId, Integer status) {
  132. AgentWithdrawal agentWithdrawal = new AgentWithdrawal();
  133. agentWithdrawal.setAgentId(agentId);
  134. if (status != 10) {
  135. agentWithdrawal.setStatus(status);
  136. }
  137. List<AgentWithdrawal> list = iAgentWithdrawalService.queryList(agentWithdrawal);
  138. return list;
  139. }
  140. @Override
  141. public List<OrderCommissonVo> commissonList(Long agentId) {
  142. return orderCommissonService.queryListByAgentId(agentId);
  143. }
  144. @Override
  145. public List<AgentVo> getGroupUser(Long agentId) {
  146. AgentVo vo = new AgentVo();
  147. List<AgentVo> list = new ArrayList<>();
  148. Agent agent = agentService.getById(agentId);
  149. BeanUtils.copyProperties(agent, vo);
  150. vo.setTotalAmount(agent.getAmount().add(agent.getWithdrawalAmount()));
  151. List<Agent> subAgents = agentService.list(new QueryWrapper<Agent>().eq("pid", agentId));
  152. if (!CollectionUtils.isEmpty(subAgents)) {
  153. BigDecimal subAmount = subAgents.stream().map(i -> {
  154. return i.getAmount().add(i.getWithdrawalAmount());
  155. }).reduce(BigDecimal.ZERO, BigDecimal::add);
  156. vo.setSubAmount(subAmount);
  157. list.add(vo);
  158. subAgents.forEach(i -> {
  159. AgentVo vo1 = new AgentVo();
  160. BeanUtils.copyProperties(i, vo1);
  161. vo1.setTotalAmount(i.getAmount().add(i.getWithdrawalAmount()));
  162. List<Agent> sAgents = agentService.list(new QueryWrapper<Agent>().eq("pid", i.getId()));
  163. if (!CollectionUtils.isEmpty(sAgents)) {
  164. BigDecimal sAmount = sAgents.stream().map(item -> {
  165. return item.getAmount().add(item.getWithdrawalAmount());
  166. }).reduce(BigDecimal.ZERO, BigDecimal::add);
  167. vo1.setSubAmount(sAmount);
  168. list.add(vo1);
  169. }
  170. });
  171. } else {
  172. Agent agent1 = agentService.getById(agent.getPid());
  173. if (agent1 != null) {
  174. vo.setPAgentName(agent1.getPAgentName());
  175. }
  176. }
  177. return list;
  178. }
  179. @Override
  180. public int updateAgentPass(Long agentId, String oldPassword, String password) {
  181. SysUser user = userService.queryByAgentId(agentId);
  182. if (user==null) {
  183. throw new CustomException("用户不存在");
  184. }
  185. else if(!SecurityUtils.matchesPassword(oldPassword,user.getPassword())){
  186. throw new CustomException("对不起,原密码错误");
  187. }
  188. user.setPassword(SecurityUtils.encryptPassword(password));
  189. return userService.resetPwd(user);
  190. }
  191. }