init
This commit is contained in:
22
app/Models/Comment.php
Normal file
22
app/Models/Comment.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(__CLASS__, 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
127
app/Models/Dynamic.php
Normal file
127
app/Models/Dynamic.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Dynamic extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $casts = [
|
||||
'pictures' => 'json',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function getPicturesUrlAttribute(): array
|
||||
{
|
||||
$pictures = $this->getAttribute('pictures');
|
||||
|
||||
if (empty($pictures)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($pictures)->map(function ($picture) {
|
||||
return $this->parseImageUrl($picture);
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析图片文件的实际展示地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:53 下午
|
||||
* @Author : < Jason.C >
|
||||
* @param string|null $image
|
||||
* @return string
|
||||
*/
|
||||
protected function parseImageUrl(?string $image): string
|
||||
{
|
||||
if (empty($image)) {
|
||||
return '';
|
||||
} elseif (Str::startsWith($image, 'http')) {
|
||||
return $image;
|
||||
} else {
|
||||
return Storage::url($image);
|
||||
}
|
||||
}
|
||||
|
||||
public function isLikedBy(User $user): bool
|
||||
{
|
||||
if ($this->relationLoaded('likers')) {
|
||||
return $this->likers->contains($user);
|
||||
}
|
||||
$likes = $this->likers()->where('user_id', $user->getKey())->first();
|
||||
return (bool) $likes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 点赞用户
|
||||
*
|
||||
* @Date : 2021/4/23 4:12 下午
|
||||
* @Author : < Jason.C >
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function likers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
User::class,
|
||||
'likes',
|
||||
'likeable_id',
|
||||
'user_id'
|
||||
)->where('likeable_type', $this->getMorphClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 是否被某人评论过了
|
||||
*
|
||||
* @Date : 2021/4/16 3:44 下午
|
||||
* @Author : < Jason.C >
|
||||
* @param Model $user
|
||||
* @return bool
|
||||
*/
|
||||
public function isCommentedBy(Model $user): bool
|
||||
{
|
||||
if ($this->relationLoaded('commenters')) {
|
||||
return $this->commenters->contains($user);
|
||||
}
|
||||
|
||||
return $this->comments()->where('user_id', $user->getKey())->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 评论记录
|
||||
*
|
||||
* @Date : 2021/4/16 3:44 下午
|
||||
* @Author : < Jason.C >
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function comments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Comment::class, 'commentable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 评论用户
|
||||
*
|
||||
* @Date : 2021/4/23 4:12 下午
|
||||
* @Author : < Jason.C >
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function commenters(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
User::class,
|
||||
'comments',
|
||||
'commentable_id',
|
||||
'user_id'
|
||||
)->where('commentable_type', $this->getMorphClass());
|
||||
}
|
||||
}
|
||||
8
app/Models/Group.php
Normal file
8
app/Models/Group.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Group extends Model
|
||||
{
|
||||
|
||||
}
|
||||
30
app/Models/Like.php
Normal file
30
app/Models/Like.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class Like extends Model
|
||||
{
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function likeable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function liker(): BelongsTo
|
||||
{
|
||||
return $this->user();
|
||||
}
|
||||
|
||||
public function scopeWithType(Builder $query, string $type): Builder
|
||||
{
|
||||
return $query->where('likeable_type', app($type)->getMorphClass());
|
||||
}
|
||||
}
|
||||
8
app/Models/Model.php
Normal file
8
app/Models/Model.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Model extends \Illuminate\Database\Eloquent\Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
}
|
||||
10
app/Models/OriginUser.php
Normal file
10
app/Models/OriginUser.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class OriginUser extends Model
|
||||
{
|
||||
protected $connection = 'mysql_tx';
|
||||
|
||||
protected $table = 'dtalk_addr_backup';
|
||||
}
|
||||
7
app/Models/Storage.php
Normal file
7
app/Models/Storage.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Storage extends Model
|
||||
{
|
||||
}
|
||||
61
app/Models/User.php
Normal file
61
app/Models/User.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Jobs\SyncUserInfo;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Jason\Api\Api;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Tencent\TLSSigAPIv2;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'privacy' => 'boolean',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
self::created(function ($model) {
|
||||
$model->info()->create([
|
||||
'nickname' => '用户'.substr($model->username, -4),
|
||||
]);
|
||||
$params = [
|
||||
'Identifier' => (string) $model->id,
|
||||
'Nick' => '用户'.substr($model->username, -4),
|
||||
'FaceUrl' => '',
|
||||
];
|
||||
app('im')->send('im_open_login_svc', 'account_import', $params);
|
||||
});
|
||||
}
|
||||
|
||||
public function getUserSigAttribute(): string
|
||||
{
|
||||
$api = new TLSSigAPIv2(config('im.sdk_app_id'), config('im.secret_key'));
|
||||
return $api->genUserSig($this->id, 15552000);
|
||||
}
|
||||
|
||||
public function getTokenAttribute(): string
|
||||
{
|
||||
return Api::login($this);
|
||||
}
|
||||
|
||||
public function info(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserInfo::class);
|
||||
}
|
||||
}
|
||||
24
app/Models/UserInfo.php
Normal file
24
app/Models/UserInfo.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserInfo extends Model
|
||||
{
|
||||
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::created(function ($model) {
|
||||
});
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user