WalletController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package com.ruoyi.app.pay;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. //import com.ruoyi.app.pay.dto.WithDrawalDto;
  7. import com.ruoyi.app.service.WalletService;
  8. import com.ruoyi.common.annotation.Anonymous;
  9. import com.ruoyi.common.annotation.Log;
  10. import com.ruoyi.common.annotation.RepeatSubmit;
  11. import com.ruoyi.common.core.controller.BaseController;
  12. import com.ruoyi.common.core.domain.AjaxResult;
  13. import com.ruoyi.common.core.page.TableDataInfo;
  14. import com.ruoyi.common.enums.BusinessType;
  15. import com.ruoyi.common.utils.StringUtils;
  16. import com.ruoyi.common.utils.poi.ExcelUtil;
  17. import com.ruoyi.system.domain.*;
  18. import com.ruoyi.system.service.*;
  19. import com.ruoyi.system.utils.Auth;
  20. import com.ruoyi.system.utils.JwtUtil;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.security.access.prepost.PreAuthorize;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import org.springframework.web.bind.annotation.*;
  25. import jakarta.servlet.http.HttpServletResponse;
  26. import java.util.ArrayList;
  27. import java.util.Arrays;
  28. import java.util.List;
  29. import java.util.stream.Collectors;
  30. /**
  31. * 钱包
  32. */
  33. @RestController
  34. @RequestMapping("/wallet")
  35. public class WalletController extends BaseController {
  36. @Autowired
  37. private WalletService walletService;
  38. @Autowired
  39. private IUserWalletService userWalletService;
  40. // @Autowired
  41. // private IWithdrawExtendService withdrawExtendService;
  42. // @Autowired
  43. // private IRechargeService rechargeService;
  44. @Autowired
  45. private IInfoUserService infoUserService;
  46. @Autowired
  47. private IUserBillingService userBillingService;
  48. @Autowired
  49. private IPosOrderService posOrderService;
  50. /**
  51. * 骑手、商家获取钱包明细
  52. *
  53. * @param token
  54. * @param pageNum
  55. * @param pageSize
  56. * @return
  57. */
  58. @GetMapping("/getUserBills")
  59. @Anonymous
  60. @Auth
  61. public AjaxResult getUserBills(@RequestHeader String token, @RequestParam int pageNum, @RequestParam int pageSize, @RequestParam(defaultValue = "") String type) {
  62. JwtUtil jwtUtil = new JwtUtil();
  63. String userId = jwtUtil.getusid(token);
  64. IPage<UserBilling> pageInput = new Page<>(pageNum, pageSize);
  65. LambdaQueryWrapper<UserBilling> queryWrapper = new LambdaQueryWrapper<>();
  66. queryWrapper.eq(UserBilling::getUserId, userId)
  67. .in(UserBilling::getType, Arrays.asList("0", "1", "2","6"));
  68. //0 收入,包含分成、抽成返还
  69. if("0".equals(type)){
  70. queryWrapper.in( UserBilling::getType, Arrays.asList("0","6"));
  71. }
  72. if(!StrUtil.isEmpty(type) && !"0".equals(type)){
  73. queryWrapper.eq(UserBilling::getType,type);
  74. }
  75. queryWrapper.orderByDesc(UserBilling::getId);
  76. IPage<UserBilling> result = userBillingService.page(pageInput, queryWrapper);
  77. if (!result.getRecords().isEmpty()) {
  78. List<String> orderDdIds = result.getRecords().stream().filter(x -> x.getType().equals("0")).map(x -> x.getDdId()).collect(Collectors.toList());
  79. List<String> withDrawalDdIds = result.getRecords().stream().filter(x -> x.getType().equals("2")).map(UserBilling::getDdId).collect(Collectors.toList());
  80. List<String> rechargeDdIds = result.getRecords().stream().filter(x -> x.getType().equals("1")).map(UserBilling::getDdId).collect(Collectors.toList());
  81. // 只有当列表不为空时才执行查询,避免生成无效的 SQL (IN ())
  82. List<PosOrder> orders;
  83. if (!orderDdIds.isEmpty()) {
  84. orders = posOrderService.list(new LambdaQueryWrapper<PosOrder>().in(PosOrder::getDdId, orderDdIds));
  85. } else {
  86. orders = new ArrayList<>();
  87. }
  88. // List<WithdrawExtend> withdraws;
  89. // if (!withDrawalDdIds.isEmpty()) {
  90. // withdraws = withdrawExtendService.list(new LambdaQueryWrapper<WithdrawExtend>().in(WithdrawExtend::getDdId, withDrawalDdIds));
  91. // } else {
  92. // withdraws = new ArrayList<>();
  93. // }
  94. //
  95. // List<Recharge> recharges;
  96. // if (!rechargeDdIds.isEmpty()) {
  97. // recharges = rechargeService.list(new LambdaQueryWrapper<Recharge>().in(Recharge::getDdId, rechargeDdIds));
  98. // } else {
  99. // recharges = new ArrayList<>();
  100. // }
  101. // result.getRecords().forEach(x -> {
  102. // if (x.getType().equals("0")) {
  103. // orders.stream().filter(o -> x.getDdId().equals(o.getDdId().toString())).findFirst().ifPresent(o -> x.setPayType(o.getPayType()));
  104. // }
  105. // if (x.getType().equals("1")) {
  106. // recharges.stream().filter(o -> x.getDdId().equals(o.getDdId())).findFirst().ifPresent(o -> x.setPayType(o.getPayType()));
  107. // }
  108. // if (x.getType().equals("2")) {
  109. // withdraws.stream().filter(o -> x.getDdId().equals(o.getDdId())).findFirst().ifPresent(o -> {
  110. // String payType = "1".equals(o.getWithdrawType()) ? "3" : "5";
  111. // x.setPayType(payType);
  112. // });
  113. // }
  114. // });
  115. }
  116. return AjaxResult.success(result);
  117. }
  118. /**
  119. * 获取钱包信息
  120. *
  121. * @param token
  122. * @return
  123. */
  124. @GetMapping("/getWalletInfo")
  125. @Anonymous
  126. @Auth
  127. public AjaxResult getWalletInfo(@RequestHeader String token) {
  128. JwtUtil jwtUtil = new JwtUtil();
  129. String userId = jwtUtil.getusid(token);
  130. UserWallet userWallet = userWalletService.selectByUserId(Long.valueOf(userId));
  131. return AjaxResult.success(userWallet);
  132. }
  133. /**
  134. * 骑手、商家获取提现列表
  135. *
  136. * @param token
  137. * @param pageNum
  138. * @param pageSize
  139. * @return
  140. */
  141. // @GetMapping("/getWithdrawalList")
  142. // @Anonymous
  143. // @Auth
  144. // public AjaxResult getWithdrawalList(@RequestHeader String token, @RequestParam int pageNum, @RequestParam int pageSize) {
  145. // JwtUtil jwtUtil = new JwtUtil();
  146. // String userId = jwtUtil.getusid(token);
  147. // IPage<WithdrawExtend> pageInput = new Page<>(pageNum, pageSize);
  148. // LambdaQueryWrapper<WithdrawExtend> queryWrapper = new LambdaQueryWrapper<>();
  149. // queryWrapper.eq(WithdrawExtend::getUserId, userId);
  150. // queryWrapper.orderByDesc(WithdrawExtend::getId);
  151. // IPage<WithdrawExtend> result = withdrawExtendService.page(pageInput, queryWrapper);
  152. // return AjaxResult.success(result);
  153. // }
  154. /**
  155. * 骑手、商家获取充值列表
  156. *
  157. * @param token
  158. * @param pageNum
  159. * @param pageSize
  160. * @return
  161. */
  162. // @GetMapping("/getRechargeList")
  163. // @Anonymous
  164. // @Auth
  165. // public AjaxResult getRechargeList(@RequestHeader String token, @RequestParam int pageNum, @RequestParam int pageSize) {
  166. // JwtUtil jwtUtil = new JwtUtil();
  167. // String userId = jwtUtil.getusid(token);
  168. // IPage<Recharge> pageInput = new Page<>(pageNum, pageSize);
  169. // LambdaQueryWrapper<Recharge> queryWrapper = new LambdaQueryWrapper<>();
  170. // queryWrapper.eq(Recharge::getUserId, userId);
  171. // queryWrapper.ne(Recharge::getStatus, "0");
  172. // queryWrapper.orderByDesc(Recharge::getId);
  173. // IPage<Recharge> result = rechargeService.page(pageInput, queryWrapper);
  174. // return AjaxResult.success(result);
  175. // }
  176. /**
  177. * 查询【请填写功能名称】列表
  178. */
  179. @PreAuthorize("@ss.hasPermi('system:wallet:query')")
  180. @GetMapping("/list")
  181. public TableDataInfo list(UserWallet userWallet) {
  182. startPage();
  183. List<UserWallet> list = userWalletService.selectUserWalletList(userWallet);
  184. if (!list.isEmpty()) {
  185. List<Long> userIds = list.stream().map(UserWallet::getUserId).collect(Collectors.toList());
  186. List<InfoUser> users = infoUserService.list(new LambdaQueryWrapper<InfoUser>().in(InfoUser::getUserId, userIds));
  187. list.forEach(x -> {
  188. users.stream().filter(u -> u.getUserId().equals(x.getUserId())).findFirst().ifPresent(y -> {
  189. String name = StrUtil.isEmpty(y.getNickName()) ? y.getUserName() : y.getNickName();
  190. x.setUserName(name);
  191. if ("0".equals(y.getUserType())) {
  192. x.setUserName(y.getPhone());
  193. }
  194. x.setUserType(y.getUserType());
  195. });
  196. });
  197. }
  198. return getDataTable(list);
  199. }
  200. /**
  201. * 获取【请填写功能名称】详细信息
  202. */
  203. @PreAuthorize("@ss.hasPermi('system:wallet:query')")
  204. @GetMapping(value = "/{id}")
  205. public AjaxResult getInfo(@PathVariable("id") Long id) {
  206. UserWallet result = userWalletService.selectUserWalletById(id);
  207. if (result != null) {
  208. InfoUser user = infoUserService.getById(result.getUserId());
  209. result.setUserName(user.getUserName());
  210. if ("0".equals(user.getUserType())) {
  211. result.setUserName(user.getPhone());
  212. }
  213. result.setUserType(user.getUserType());
  214. }
  215. return success(result);
  216. }
  217. /**
  218. * 导出【请填写功能名称】列表
  219. */
  220. @PreAuthorize("@ss.hasPermi('system:wallet:export')")
  221. @Log(title = "userWallet", businessType = BusinessType.EXPORT)
  222. @PostMapping("/export")
  223. public void export(HttpServletResponse response, UserWallet userWallet) {
  224. List<UserWallet> list = userWalletService.selectUserWalletList(userWallet);
  225. if (!list.isEmpty()) {
  226. List<Long> userIds = list.stream().map(UserWallet::getUserId).collect(Collectors.toList());
  227. List<InfoUser> users = infoUserService.list(new LambdaQueryWrapper<InfoUser>().in(InfoUser::getUserId, userIds));
  228. list.forEach(x -> {
  229. users.stream().filter(u -> u.getUserId().equals(x.getUserId())).findFirst().ifPresent(y -> {
  230. String name = StrUtil.isEmpty(y.getNickName()) ? y.getUserName() : y.getNickName();
  231. x.setUserName(name);
  232. if ("0".equals(y.getUserType())) {
  233. x.setUserName(y.getPhone());
  234. }
  235. x.setUserType(y.getUserType());
  236. });
  237. });
  238. }
  239. ExcelUtil<UserWallet> util = new ExcelUtil<UserWallet>(UserWallet.class);
  240. util.exportExcel(response, list, "用户钱包数据");
  241. }
  242. }