<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 22/04/26
 * Time: 14:41
 */

namespace App\Services\Api;

use App\Models\User;

class UserService
{
    //获取用户信息（需要更多信息的话在这里追加）
    public static function getUserInfoById($id)
    {
        $info = User::query()->where('id', $id)->whereNull('deleted_at')->first();
        $info->makeHidden(['updated_at', 'deleted_at']);

        $info = !empty($info) ? $info->toArray() : [];

        return $info;
    }

    //通过手机号查用户
    public static function checkUserByMobile($mobile)
    {
        $user = User::where('mobile', $mobile)->whereNull('deleted_at')->first();
        if ($user) {
            return true;
        }

        return false;
    }

    //通过邮箱查找用户
    public static function checkUserByEmail($email)
    {
        $user = User::where('email', $email)->whereNull('deleted_at')->first();
        if ($user) {
            return true;
        }

        return false;
    }

    //收藏数+1
    public static function collectNumInc($userId)
    {
        User::query()->where('id', $userId)->increment('collect_num');
    }

    //收藏数-1
    public static function collectNumDec($userId)
    {
        User::query()->where('id', $userId)->decrement('collect_num');
    }



}