package co.yixiang.yshop.module.member.api.user;

import co.yixiang.yshop.module.member.api.user.dto.IncreaseNowMoneyDTO;
import co.yixiang.yshop.module.member.enums.BillDetailEnum;
import co.yixiang.yshop.module.member.service.user.MemberUserService;
import co.yixiang.yshop.module.member.service.userbill.UserBillService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

@Service
@Validated
public class MemberUserNowMoneyApiImpl implements MemberUserNowMoneyApi {

    @Resource
    private MemberUserService memberUserService;

    @Resource
    private UserBillService userBillService;

    @Override
    public void increaseNowMoney(IncreaseNowMoneyDTO increaseNowMoneyDTO) {
        // 增加余额
        memberUserService.incMoney(increaseNowMoneyDTO.getId(), increaseNowMoneyDTO.getAmount());
        // 保存记录
        userBillService.income(increaseNowMoneyDTO.getId(),
                "充值", BillDetailEnum.CATEGORY_1.getValue(),
                BillDetailEnum.TYPE_1.getValue(),
                increaseNowMoneyDTO.getAmount(),
                increaseNowMoneyDTO.getAmount(),
                increaseNowMoneyDTO.getMark(),
                increaseNowMoneyDTO.getLink());
    }
}
