package com.pj.project.tb_account;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.pj.constants.UserTypeEnum;
import com.pj.project.tb_costomer.TbCostomer;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;

import com.pj.current.satoken.StpUserUtil;
import cn.dev33.satoken.annotation.SaCheckPermission;


/**
 * Controller: tb_account -- 客户账户
 *
 * @author qzy
 */
@RestController
@RequestMapping("/TbAccount/")
public class TbAccountController {

    /**
     * 底层 Service 对象
     */
    @Autowired
    TbAccountService tbAccountService;

    @RequestMapping(value = "getCustomerAccount")
    @SaCheckPermission(TbCostomer.PERMISSION_CODE)
    public AjaxJson getCustomerAccount(String customerId) {
        return AjaxJson.getSuccessData(tbAccountService.getByCustomerId(customerId));
    }

    @RequestMapping(value = "recharge")
    public AjaxJson recharge() {
        if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
            return AjaxJson.getError("无权限充值");
        }
        SoMap soMap = SoMap.getRequestSoMap();
        String customerId = soMap.getString("customerId");
        String money = soMap.getString("money");
        tbAccountService.recharge(customerId,money);
        return AjaxJson.getSuccess();
    }


}
