package com.xhpc.payment.controller;

import cn.hutool.core.date.DateUtil;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.service.AlipayInterface;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

@Controller
@RequestMapping("/text/callBack")
@Api(value = "支付宝支付接口", tags = "支付宝支付接口")
public class PayCallbackController {

   // private static final Logger logger = LoggerFactory.getLogger(PayCallbackController.class);

    @Autowired
    private AlipayInterface alipayInterfacess;


    @GetMapping("/relationBind")
    public  AjaxResult relationBind(){
        Date date = Calendar.getInstance().getTime();
        String format = DateUtil.format(date, "yyMMddHHmmss");
        System.out.println("format:"+format);
        try{
            return alipayInterfacess.bindPaypal("2265829957@qq.com", "loginName", "四川兴彦新能源技术有限公司", format);
        }catch (Exception e){

        }
        return null;
    }

    @GetMapping("/unBindPaypal")
    public  AjaxResult unBindPaypal(){
        Date date = Calendar.getInstance().getTime();
        String format = DateUtil.format(date, "yyMMddHHmmss");
        System.out.println("format:"+format);
        try{
            return alipayInterfacess.unBindPaypal("2088341251677576", "userId", "YuAssist", format);
        }catch (Exception e){

        }
        return null;
    }


    @GetMapping("/batchquery")
    public AjaxResult batchquery(){
        Date date = Calendar.getInstance().getTime();
        String format = DateUtil.format(date, "yyMMddHHmmss");
        System.out.println("format:"+format);
        try{
            return alipayInterfacess.batchquery(1, 20,  format);
        }catch (Exception e){

        }
        return null;
    }

    @GetMapping("/settlePaypal")
    public AjaxResult settlePaypal(){
        Date date = Calendar.getInstance().getTime();
        String format = DateUtil.format(date, "yyMMddHHmmss");
        System.out.println("format:"+format);
        try{
            boolean b = alipayInterfacess.settlePaypal(format, "2021120922001455001440999220", "2088341251677576", new BigDecimal(1));
            return AjaxResult.success(b);
        }catch (Exception e){

        }
        return null;
    }

    @GetMapping("/query")
    public AjaxResult query(){
        Date date = Calendar.getInstance().getTime();
        String format = DateUtil.format(date, "yyMMddHHmmss");
        System.out.println("format:"+format);
        try{
            return alipayInterfacess.query("", "2021120922001455001440999220");
        }catch (Exception e){

        }
        return null;
    }

    @GetMapping("/refund")
    public AjaxResult refund(){
        try{
            return alipayInterfacess.refund("", "2021120922001455001440999220",new BigDecimal(7),"","","");
        }catch (Exception e){

        }
        return null;
    }

    @GetMapping("/refundQuery")
    public AjaxResult refundQuery(){
        try{
            return alipayInterfacess.refundQuery("", "2021120922001455001440999220",new BigDecimal(7),"","","");
        }catch (Exception e){

        }
        return null;
    }
}
