package com.ruoyi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.annotations.UserLoginToken;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.controller.req.RechargeOrderReq;
import com.ruoyi.frequency.rechargecoin.entity.RechargeCoin;
import com.ruoyi.frequency.rechargecoin.service.RechargeCoinService;
import com.ruoyi.frequency.rechargeorder.service.RechargeOrderService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值
 * @author ly
 */
@CrossOrigin
@RestController
@RequestMapping("/api/rechargeOrder")
@Api(tags = "充值")
public class ApiRechargeOrderController extends RyController {


    @Autowired
    private RechargeOrderService rechargeOrderService;

    @Autowired
    private RechargeCoinService rechargeCoinService;

    @UserLoginToken
    @PostMapping("/rechargeOrder")
    @ApiOperation(value = "充值余额")
    public ResponseData rechargeOrder(@RequestBody RechargeOrderReq req) {
        return rechargeOrderService.rechargeOrder(req, getUserVo());
    }


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(value = "充值列表")
    public ResponseData list(@RequestBody(required = false) Integer type) {
        if (type == null) {
            type = 1;
        }
        List<RechargeCoin> list = rechargeCoinService.list(new QueryWrapper<RechargeCoin>().lambda().
                eq(RechargeCoin::getPhoneType, type).
                eq(RechargeCoin::getDelFlag, PublicCommon.启用).orderByAsc(RechargeCoin::getPrice));
        return ResponseData.success(list);
    }

}
