package com.ruoyi.web.controller.coffee;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.service.impl.AppServiceImpl;
import com.ruoyi.system.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/app")
public class AppController extends BaseController {
    @Autowired
    private TokenService tokenService;
    @Autowired
    private AppServiceImpl appService;
    @Autowired
    private OrderServiceImpl orderService;



    @RequestMapping("/getMyOrder")
    public TableDataInfo getMyOrder(HttpServletRequest request){
        LoginUser loginUser = tokenService.getLoginUser(request);
        if(loginUser ==null){
          throw new ServiceException("请先登录");
        }
        String openId = loginUser.getOpenId();
        startPage();
        List<Order> myOrder = orderService.getMyOrder(openId);
        return getDataTable(myOrder);
    }
    @RequestMapping("/refundOrder")
    public AjaxResult refundOrder(String orderId){
        return AjaxResult.success(orderService.refundOrder(orderId));

    }

}
