package com.ruoyi.web.controller.coffee;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OrderRefund;
import com.ruoyi.system.service.IOrderRefundService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单退款Controller
 * 
 * @author ruoyi
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/system/refund")
public class OrderRefundController extends BaseController
{
    @Autowired
    private IOrderRefundService orderRefundService;

    /**
     * 查询订单退款列表
     */
    @PreAuthorize("@ss.hasPermi('system:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderRefund orderRefund)
    {
        startPage();
        List<OrderRefund> list = orderRefundService.selectOrderRefundList(orderRefund);
        return getDataTable(list);
    }

    /**
     * 获取订单退款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:refund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(orderRefundService.selectOrderRefundById(id));
    }

    /**
     * 新增订单退款
     */
    @Log(title = "订单退款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderRefund orderRefund)
    {
        AjaxResult ajaxResult = orderRefundService.insertOrderRefund(orderRefund);
        Object obejct = ajaxResult.get(AjaxResult.DATA_TAG);
        if(obejct!=null && obejct instanceof OrderRefund){


        }

        return ajaxResult;
    }


//        public void refund(HttpServletRequest request,
//                     String openid,
//                     int activityid,
//                       int memberid) throws Exception {
//        //先将订单信息查出来  这里的订单就是上边说的支付订单，我的是通过openid和一个activityid查出来的，自己可根据业务逻辑修改。
//        QueryWrapper<Wxpaynotifyvo> wxPayNotifyVOQueryWrapper = new QueryWrapper<>();
//        wxPayNotifyVOQueryWrapper.eq("openid", openid);
//        wxPayNotifyVOQueryWrapper.eq("activityid", activityid);
//        Wxpaynotifyvo wxPayNotifyVO = this.wxPayService.getBaseMapper().selectOne(wxPayNotifyVOQueryWrapper);
//        //构建参数
//        Map<String, String> dataMap = new HashMap<>();
//        //小程序ID
//        dataMap.put("appid", WechatConstant.APPID);
//        //商户号
//        dataMap.put("mch_id", WechatConstant.MCH_ID);
//        //随机字符串
//        dataMap.put("nonce_str", UUID.randomUUID().toString().replaceAll("-", ""));
//        //微信订单号
//        dataMap.put("transaction_id", wxPayNotifyVO.getTransactionid());
//        //商户退款单号
//        Date now = new Date();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");//可以方便地修改日期格式
//        String outRefundNo = "NO" + dateFormat.format(now);
//        dataMap.put("out_refund_no", outRefundNo);
//        //订单金额
//        dataMap.put("total_fee", wxPayNotifyVO.getTotalfee());
//
//        //退款金额
//        dataMap.put("refund_fee", wxPayNotifyVO.getTotalfee());
//        //商户证书密钥，生成签名
//        String sign = WXPayUtil.generateSignature(dataMap, WechatConstant.KEY);
//        dataMap.put("sign", sign);
//        //这个是将报名表里的数据删除
//        int i = applymanService.deleteApplyman(openid, activityid, memberid);
//        //这个不是
//        this.wxPayService.refound(dataMap);
//        Res res = new Res();
//        res.setCode(0);
//        res.setMsg("退款成功！");
//        return res;
//    }


}
