无关风月
2025-04-17 a0eae3ecda7b70468c60a0079db6c4609c29939d
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
package com.ruoyi.admin.controller;
 
 
import com.ruoyi.admin.entity.Franchisee;
import com.ruoyi.admin.entity.FranchiseeWithdraw;
import com.ruoyi.admin.entity.TFranchiseeBalanceChange;
import com.ruoyi.admin.service.FranchiseeService;
import com.ruoyi.admin.service.TFranchiseeBalanceChangeService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.admin.request.WithdrawDTO;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
 
/**
 * <p>
 * 师傅信息表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-06-03
 */
@RestController
@RequestMapping("/franchisee")
@Api(value = "加盟商迭代新增", tags = "加盟商迭代新增")
public class AppFranchiseeController {
 
 
    @Resource
    private TokenService tokenService;
    @Resource
    private FranchiseeService franchiseeService;
    @Resource
    private TFranchiseeBalanceChangeService franchiseeBalanceChangeService;
 
 
 
    @PostMapping("/applyWithdraw")
    @ApiOperation(value = "加盟商申请提现", tags = {"提现"})
    public R check(@RequestBody WithdrawDTO dto) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (loginUser==null){
            return R.fail("登录失效");
        }
        Franchisee franchisee = franchiseeService.getById(loginUser.getUserid());
        if (franchisee.getBalance().subtract(dto.getMoney()).compareTo(BigDecimal.ZERO)>=0){
            BigDecimal subtract = franchisee.getBalance().subtract(dto.getMoney());
            franchisee.setBalance(subtract);
        }else{
            return R.fail("余额不足");
        }
        // 扣去余额 生成余额明细
        TFranchiseeBalanceChange balanceChange = new TFranchiseeBalanceChange();
        balanceChange.setAmount(dto.getMoney());
        balanceChange.setIs_pay(1);
        balanceChange.setFranchiseeName(franchisee.getName());
        balanceChange.setFranchiseeId(franchisee.getId()+"");
        balanceChange.setRemark("余额提现");
        balanceChange.setType(3);
        balanceChange.setIsDelete(0);
        franchiseeBalanceChangeService.save(balanceChange);
        // 生成提现记录
        FranchiseeWithdraw franchiseeWithdraw = new FranchiseeWithdraw();
        franchiseeWithdraw.setChangeId(balanceChange.getId());
        franchiseeWithdraw.setFranchiseeId(Integer.valueOf(balanceChange.getFranchiseeId()));
        franchiseeWithdraw.setStatus(1);
        franchiseeWithdraw.setContent(dto.getContent());
        franchiseeWithdraw.setMoney(dto.getMoney());
        franchiseeWithdraw.setCreateTime(LocalDateTime.now());
        franchiseeWithdraw.setUpdateTime(LocalDateTime.now());
        franchiseeWithdraw.setIsDelete(0);
 
 
        return R.ok();
    }
 
}