package com.miaxis.app.controller.wx;

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.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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 【微信提现】Controller
 *
 * @author miaxis
 * @date 2022-01-24
 */
@RestController
@RequestMapping("/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 getPrepareOrder(Integer amount) throws Exception{

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

        }
        if (amount > 200 && amount <0){
            throw new CustomException("提现金额必须在200以内");
        }
        wxOrderService.wxwithdrawal(amount);
        return Response.success();


    }




}
