package com.younike.admin;

import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.system.domain.OrderRefund;
import com.younike.system.domain.vo.OrderVo;
import com.younike.system.param.OrderQueryParam;
import com.younike.system.service.IOrderRefundService;
import com.younike.system.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 会员订单Controller
 *
 * @author zulu.chen
 * @date 2022-01-11
 */
@Api("会员订单接口")
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController extends BaseController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IOrderRefundService orderRefundService;


    /**
     * 查询会员订单列表
     */
    @ApiOperation("查询会员订单列表")
    @PreAuthorize("@ss.hasPermi('admin:order:list')")
    @GetMapping("/orderList")
    public TableDataInfo list(OrderQueryParam param) {
        startPage();
        List<OrderVo> list = orderService.orderList(param);
        return getDataTable(list);
    }

    @ApiOperation("查询会员订单退款信息")
    @PreAuthorize("@ss.hasPermi('admin:order:edit')")
    @GetMapping("getRefundInfo")
    public AjaxResult getRefundInfo(@RequestParam("orderId") String orderId) {
        return AjaxResult.success(orderRefundService.selectOrderRefundByOrderId(orderId));
    }

    @ApiOperation("审核退款")
    @PreAuthorize("@ss.hasPermi('admin:order:edit')")
    @PutMapping("doRefund")
    public AjaxResult doRefund(@RequestBody OrderRefund orderRefund) {
        return orderService.doRefund(orderRefund);
    }
}
