package com.miaxis.app.controller.wx;

import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.exception.CustomException;
import com.miaxis.common.utils.SecurityUtils;
import com.miaxis.wx.domain.WxExtract;
import com.miaxis.wx.dto.WxExtractBankDTO;
import com.miaxis.wx.service.IWxExtractService;
import com.miaxis.wx.service.IWxOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【微信提现】Controller
 *
 * @author miaxis
 * @date 2022-01-24
 */
@RestController
@RequestMapping(Constants.STUDENT_PREFIX +"/wx/extract")
@Api(tags={"【H5-微信提现】"})
public class WxExtractController extends BaseController{
    @Autowired
    private IWxExtractService wxExtractService;

    @Autowired
    private IWxOrderService wxOrderService;

    /**
     * 查询微信提现列表
     */
    @GetMapping("/list")
    @ApiOperation("查询微信提现列表")
        @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<WxExtract> list(){
        WxExtract wxExtract = new WxExtract();
        wxExtract.setOpenid(SecurityUtils.getLoginUser().getStudent().getOpenid());
        startPage();
        List<WxExtract> list = wxExtractService.selectWxExtractList(wxExtract);
        return toResponsePageInfo(list);
    }

    /**
     * 微信提现
     */
    @PostMapping(value = "/withdraw")
    @ApiOperation("微信提现")
    public Response wxwithdrawal(Integer amount) throws Exception{

        if (amount == null){
            throw new CustomException("提现金额不能为空");

        }
        if (amount > 20000 ){
            throw new CustomException("提现金额不能超过200元");
        }

        if (amount < 30 ){
            throw new CustomException("提现金额不能低于0.3元");
        }
        wxOrderService.wxwithdrawal(amount);
        return Response.success();


    }


    /**
     * 银行卡提现
     */
    @PostMapping(value = "/wxwithbankdrawal")
    @ApiOperation("银行卡提现")
    public Response wxwithbankdrawal(@RequestBody WxExtractBankDTO dto) throws Exception{


        return Response.success(wxOrderService.wxwithbankdrawal(dto));


    }




}
