package com.jxy.order.controller;

import com.github.pagehelper.PageHelper;
import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.common.core.web.controller.BaseController;
import com.jxy.common.core.web.page.TableDataInfo;
import com.jxy.common.security.annotation.RequiresLogin;
import com.jxy.common.security.service.TokenService;
import com.jxy.common.security.utils.SecurityUtils;
import com.jxy.order.service.ConsumeService;
import com.jxy.order.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Description 顾客(用户)相关controller
 * @Date 2023/5/4 14:17
 * @Author 杜懿
 */
@RestController
@RequestMapping("/consume")
public class ConsumeController extends BaseController {

    @Autowired
    private ConsumeService consumeService;

    @Autowired
    private TokenService tokenService;

    //获取各等级支付金额
    @PostMapping("/getNeedFunding")
    @RequiresLogin
    public AjaxResult getNeedFunding(){

        return  consumeService.getNeedFunding();

    }

    //升级会员
    @PostMapping("/levelUp")
    @RequiresLogin
    public AjaxResult levelUp(@RequestBody LevelUpVo vo){

        return  consumeService.levelUp(vo);

    }

    @PostMapping("/test")
    @RequiresLogin
    public AjaxResult test(){

        return  consumeService.test();

    }

    @PostMapping("/test2")
    @RequiresLogin
    public AjaxResult test2(){

        return  AjaxResult.success(SecurityUtils.getLoginUser());

    }

    //用户获取历史消费记录记录
    @PostMapping("/privateConsume")
    @RequiresLogin
    public TableDataInfo privateConsume(@RequestBody(required = false) StatusPageVo vo){
        if(StringUtils.isNull(vo)){
            vo = new StatusPageVo();
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        return getDataTable(consumeService. privateConsume(vo));
    }

}
