package com.bweb.controller;

import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.HuiLianTongUnionCardConfig;
import com.hai.config.TuanYouConfig;
import com.hai.model.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author hurui
 * @version 1.0
 * @ClassName TuanYouController
 * @description: TODO
 * @date 2021/9/17 17:52
 */
@Controller
@RequestMapping(value = "/tuanYou")
@Api(value="用户管理")
public class TuanYouController {

    private static Logger log = LoggerFactory.getLogger(TuanYouController.class);

    @RequestMapping(value="/getTuanYouAccount",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询团油账户余额")
    public ResponseData getTuanYouAccount() {
        try {

            return ResponseMsgUtil.success(TuanYouConfig.queryCompanyAccountInfo2JD());

        } catch (Exception e) {
            log.error("getUserByTelephone",e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/refund",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "团油退款")
    public ResponseData refund(
            @RequestParam(name = "refundOrderNo", required = false) String refundOrderNo,
            @RequestParam(name = "origOrderNo", required = false) String origOrderNo
    ) {
        try {

            return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.refund(refundOrderNo , origOrderNo));

        } catch (Exception e) {
            log.error("getUserByTelephone",e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/queryCardInfo",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询")
    public ResponseData queryCardInfo(
            @RequestParam(name = "card", required = false) String card
    ) {
        try {
            JSONObject cardInfo = HuiLianTongUnionCardConfig.queryCardInfo(card);
            return ResponseMsgUtil.success(cardInfo);

        } catch (Exception e) {
            log.error("getUserByTelephone",e);
            return ResponseMsgUtil.exception(e);
        }
    }

}
