package com.sv.service.common;

import com.enums.MoneyLogEnum;
import com.sv.entity.MemberMoneyLog;
import com.sv.service.api.MemberMoneyLogService;
import com.sv.service.api.MemberService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class MemberMoney {
    @Resource
    private MemberMoneyLogService memberMoneyLogService;
    @Resource
    private MemberService memberService;

    /**
     * 修改用户余额，并且生成记录
     * @param memberId
     * @param platformId
     * @param type
     * @param price
     * @param payType
     * @param cardType
     * @param venueId
     * @param venueType
     * @param lessonId
     */
    @Transactional
    public void create(Integer memberId, Integer platformId, Integer type, BigDecimal price, Integer payType,
                       String cardType , Integer venueId, Integer venueType, Integer lessonId){
        MemberMoneyLog memberMoneyLog = new MemberMoneyLog();
        memberMoneyLog.setType(type);
        memberMoneyLog.setMoney(price);
        memberMoneyLog.setMemberId(memberId);
        memberMoneyLog.setPlatformId(platformId);
        memberMoneyLog.setPayType(payType);
        memberMoneyLog.setCardType(cardType);
        memberMoneyLog.setVenueId(venueId);
        memberMoneyLog.setVenueType(venueType);
        memberMoneyLog.setLessonId(lessonId);
        memberMoneyLogService.insert(memberMoneyLog);
        if (type.intValue() != MoneyLogEnum.VIPCARD.value && type.intValue() != MoneyLogEnum.BUY_LESSON.value &&
                type.intValue() != MoneyLogEnum.REFUND.value && type.intValue() != MoneyLogEnum.APPLY_MONEY_SUCCESS.value){
            // 修改用户余额
            memberService.updateMoney(memberId,price);
        }
    }
}
