package com.sqx.modules.app.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sqx.modules.app.entity.UserMoney;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserMoneyDao extends BaseMapper<UserMoney> {

    void updateMayMoney(@Param("type") Integer type, @Param("userId")Long userId, @Param("money") Double money);

    void updateMayAmount(@Param("type") Integer type, @Param("userId")Long userId, @Param("amount") Double amount);

    @Select("select sum(money) from user_money_details where user_id=#{userId} and classify in (6,1) and (content like '%额外奖励金币%' or content like '获取金币')")
    BigDecimal sumMoney(Long userId);

    @Select("select sum(money) from user_money_details where user_id=#{userId} and classify=6 and content like '%额外奖励现金红包%'")
    BigDecimal sumMoney2(Long userId);

    @Update("update user_money set amount=amount+#{money} where user_id=#{userId}")
    Boolean incrMoney(@Param("money") String money, @Param("userId") Long userId);

    @Update("update user_money set amount=amount-#{money} where user_id=#{userId}")
    Boolean decrMoney(@Param("money") String money, @Param("userId") Long userId);
}
