puzhibing
2025-01-02 210828d1a6947596fe00ab30fcd8725c6714dde4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.ruoyi.other.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.domain.ShopWithdraw;
import com.ruoyi.other.dto.ShopBalanceDto;
import com.ruoyi.other.service.ShopService;
import com.ruoyi.other.service.ShopWithdrawService;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-20
 */
@RestController
@RequestMapping("/shop-withdraw")
@Api(tags = {"管理后台-门店管理-提现管理"})
public class ShopWithdrawController {
 
    @Resource
    private ShopWithdrawService shopWithdrawService;
    @Resource
    private ShopService shopService;
    @Resource
    private TokenService tokenService;
 
    /**
     * 提现申请列表
     */
    @GetMapping("/list")
    @ApiOperation("提现申请列表")
    public R<IPage<ShopWithdraw>> list(@ApiParam("页码") @RequestParam Integer pageNum,
                         @ApiParam("每一页数据大小") Integer pageSize,
                         ShopWithdraw shopWithdraw) {
        List<Shop> list = shopService.list(new LambdaUpdateWrapper<Shop>().like(StringUtils.isNotEmpty(shopWithdraw.getShopName()), Shop::getName, shopWithdraw.getShopName()).eq(Shop::getDelFlag, 0));
        List<Integer> collect1 = list.stream().map(Shop::getId).collect(Collectors.toList());
        Page<ShopWithdraw> page = shopWithdrawService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<ShopWithdraw>()
                .in(collect1.size() > 0, ShopWithdraw::getShopId, collect1));
        List<ShopWithdraw> records = page.getRecords();
        List<Integer> collect = records.stream().map(ShopWithdraw::getShopId).collect(Collectors.toList());
        List<Shop> shops = null;
        if(collect.size() > 0){
            shops = shopService.listByIds(collect);
        }
        for(ShopWithdraw item : records){
            Optional<Shop> first = shops.stream().filter(s -> s.getId().equals(item.getId())).findFirst();
            if(first.isPresent()){
                item.setShopName(first.get().getName());
            }
        }
        return R.ok(page);
    }
 
    @GetMapping("/shop/list")
    @ApiOperation(value = "提现申请列表", notes = "提现申请列表", tags = {"门店后台"})
    public R<IPage<ShopWithdraw>> shoplist(@ApiParam("页码") @RequestParam Integer pageNum,
                                       @ApiParam("每一页数据大小") Integer pageSize,
                                       ShopWithdraw shopWithdraw) {
        Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
        Page<ShopWithdraw> page = shopWithdrawService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<ShopWithdraw>()
                        .eq(ShopWithdraw::getShopId,objectId)
                        .eq(shopWithdraw.getAuditStatus()!=null,ShopWithdraw::getAuditStatus,shopWithdraw.getAuditStatus())
                        .orderByDesc(ShopWithdraw::getCreateTime)
                );
        return R.ok(page);
    }
 
    @GetMapping("/shop/info")
    @ApiOperation(value = "提现申请列表上方数据", notes = "提现申请列表", tags = {"门店后台"})
    public R<Shop> shopCommissionStatisticsinfo(){
        Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
        Shop byId = shopService.getById(objectId);
        return R.ok(byId);
    }
    @GetMapping("/shop/with")
    @ApiOperation(value = "提现申请", notes = "提现申请列表", tags = {"门店后台"})
    public R<Shop> shopwith(@RequestParam BigDecimal money){
        Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
        Shop byId = shopService.getById(objectId);
        if (money.compareTo(byId.getCanWithdrawMoney())>0){
            return R.fail("提现金额不能大于可提现金额");
        }
        ShopWithdraw shopWithdraw = new ShopWithdraw();
        shopWithdraw.setShopId(objectId);
        shopWithdraw.setMoney(money);
        shopWithdraw.setAuditStatus(0);
        shopWithdraw.setStatus(1);
        shopWithdrawService.save(shopWithdraw);
 
        return R.ok(byId);
    }
 
 
    /**
     * 审核
     */
    @PostMapping("/audit")
    @ApiOperation("审核")
    public R<Void> audit(@RequestBody ShopWithdraw shopWithdraw) {
        LoginUser loginUser = tokenService.getLoginUser();
        ShopWithdraw shopWithdraw1 = shopWithdrawService.getById(shopWithdraw.getId());
        shopWithdraw1.setAuditStatus(shopWithdraw.getAuditStatus());
        shopWithdraw1.setAuditUserId(loginUser.getUserid());
        shopWithdraw1.setAuditTime(LocalDateTime.now());
        shopWithdraw1.setAuditMsg(shopWithdraw.getAuditMsg());
        shopWithdrawService.updateById(shopWithdraw1);
        return R.ok();
    }
 
 
 
 
}