Files
hyperf_service/app/Model/User.php
2025-03-03 16:21:38 +08:00

94 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Builder;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property string $mobile
* @property string $nickname
* @property string $password
* @property string $salt
* @property int $avatar_id
* @property int $gender
* @property int $age
* @property string $birthday
* @property int $city
* @property string $token
* @property string $last_ip
* @property string $reg_ip
* @property string $last_time
* @property string $invite_code
* @property string $create_time
* @property string $update_time
* @property int $is_del
*/
class User extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'user';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
protected array $guarded = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'avatar_id' => 'integer', 'gender' => 'integer', 'age' => 'integer', 'city' => 'integer', 'is_del' => 'integer'];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
/**
* @param int $id
* @return Builder|\Hyperf\Database\Model\Model|null
*/
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
{
return $this->where('id', $id)->first();
}
/**
* @param array $ids
* @return array
*/
public function getInfoByIds(array $ids): array
{
$data = $this->whereIn('id', $ids)->get();
if ($data->isEmpty()) return [];
$data = $data->toArray();
return array_column($data,null,'id');
}
/**
* @param string $code
* @return int
*/
public function checkInviteCodeIsUse(string $code): int
{
return $this->where('invite_code', $code)->count() ?? 0;
}
/**
* @param string $code
* @return int
*/
public function getUserIdByInviteCode(string $code): int
{
return $this->where('invite_code', $code)->value('id') ?? 0;
}
}