package com.sqx.modules.discSpinning.controller;

import com.sqx.common.utils.Constant;
import com.sqx.common.utils.IPUtils;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.pay.entity.CashOut;
import com.sqx.modules.pay.service.CashOutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 提现审核
 *
 * @author tankaikai
 * @since 2024-12-26 14:39
 */
@RestController
@RequestMapping("/cashOutAudit")
@AllArgsConstructor
@Api(value = "提现审核", tags = {"提现审核"})
public class CashOutController {

    @Resource
    private CashOutService cashOutService;

    @GetMapping("/page")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
    })
    public Result page(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = cashOutService.auditPage(params);
        return Result.success().put("page", page);
    }

    @PostMapping("/audit")
    @ApiOperation("审核")
    public Result audit(@RequestBody CashOut cashOut) {
        cashOutService.audit(cashOut);
        return Result.success();
    }

    @PostMapping("/batchAudit")
    @ApiOperation("批量审核")
    public Result batchAudit(@RequestBody CashOut cashOut) {
        cashOutService.batchAudit(cashOut.getUserId(), cashOut.getIsAgree(), cashOut.getRefund());
        return Result.success();
    }

    @GetMapping("/alipay/transfer/summary/query")
    @ApiOperation("支付宝提现查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "alipayAccountName", value = "支付宝账户名", paramType = "query", required = true, dataType = "String"),
    })
    public Result alipayTransferSummaryQuery(String alipayAccountName) {
        Map<String, Object> data = cashOutService.alipayTransferSummaryQuery(alipayAccountName);
        return Result.success().put("data", data);
    }

    @RequestMapping(value = "/batchCashOutOrder", method = RequestMethod.GET)
    @ApiOperation("批量提现")
    public Result batchCashOutOrder(HttpServletRequest request, Double maxMoney, Integer count) {
        String ipAddr = IPUtils.getIpAddr(request);
        if (!"127.0.0.1".equals(ipAddr)) {
            return Result.error("非法请求");
        }
        return cashOutService.batchCashOutOrder(maxMoney, count);
    }
}
