feat : user
This commit is contained in:
@@ -21,7 +21,8 @@ use Hyperf\DbConnection\Model\Model;
|
||||
* @property string $token
|
||||
* @property string $last_ip
|
||||
* @property string $reg_ip
|
||||
* @property string $last_time
|
||||
* @property string $last_time
|
||||
* @property string $invite_code
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
* @property int $is_del
|
||||
@@ -56,4 +57,37 @@ class User extends Model
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
47
app/Model/UserInvite.php
Normal file
47
app/Model/UserInvite.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $invitee_user_id
|
||||
* @property int $status
|
||||
* @property int $channel
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class UserInvite extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'user_invite';
|
||||
|
||||
/**
|
||||
* 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', 'user_id' => 'integer', 'invitee_user_id' => 'integer', 'status' => 'integer', 'channel' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return int
|
||||
*/
|
||||
public function checkIsInvite(int $userId): int
|
||||
{
|
||||
return $this->where('user_id',$userId)->count() ?? 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user