package com.ym.mec.student.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.RechargeDto;
import com.ym.mec.biz.dal.entity.SysUserCashAccount;
import com.ym.mec.biz.service.StudentRechargeService;
import com.ym.mec.biz.service.SysUserCashAccountService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @version V1.0
 * @Description: 充值
 * @date Date : 2019年09月23日 16:56
 */

@RequestMapping("recharge")
@Api(tags = "账户充值")
@RestController
public class RechargeController extends BaseController {
    @Resource
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private StudentRechargeService rechargeService;

    @Autowired
    private SysUserCashAccountService sysUserCashAccountService;

    @ApiOperation("充值")
    @GetMapping(value = "/recharge")
    public Object recharge(RechargeDto rechargeDto){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            return failed("获取用户信息失败");
        }
        SysUserCashAccount userCashAccount = sysUserCashAccountService.get(sysUser.getId());
        if(userCashAccount == null || !userCashAccount.getStatus().equals(1)){
            return failed("账户不存在");
        }

        if(!userCashAccount.getStatus().equals(1)){
            return failed("账户已冻结");
        }

        return succeed(rechargeService.recharge(rechargeDto));
    }
}
