<?php
/**
 * @package merchant
 *
 * @author xaboy
 * @day 2020-05-07
 *
 *
 */

namespace app\common\model\user;


use app\common\model\BaseModel;

class UserRich extends BaseModel
{

    /**
     * @return string
     * @author xaboy
     * @day 2020-03-30
     */
    public static function tablePk(): string
    {
        return 'id';
    }
    /**
     * @return string
     * @author xaboy
     * @day 2020-03-30
     */
    public static function tableName(): string
    {
        return 'user_rich';
    }

    /**
     * 增加用户一壶茶提现金额
     * @param $uid
     * @param $number
     * @return bool
     */
    public function increase_tea_price($uid,$number)
    {
        $count = self::getDB()->where('uid', $uid)->count();
        if ($count) {
            self::getDB()->where('uid', $uid)->inc('totel_tea_price', $number)->inc('tea_price', $number)->update();
        } else {
            $insert['uid'] = $uid;
            $insert['totel_tea_price'] = $number;
            $insert['tea_price'] = $number;
            self::getDB()->insert($insert);
        }
        return true;
    }
    /**
     * 更新用户一壶茶提现金额
     * @param $uid
     * @param $number
     * @return bool
     */
    public function reduce_tea_price($uid,$number)
    {
        $count = self::getDB()->where('uid', $uid)->count();
        if ($count) {
            self::getDB()->where('uid', $uid)->inc('tea_price', $number)->update();
            return true;
        }else{
            return false;
        }
    }
}
