server/app/Model/AccountMessage.php

83 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $mess_id
* @property int $account_id
* @property int $message_id
* @property int $read_flag
* @property string $read_time
* @property string $deleted_at
* @property string $create_time
* @property string $update_time
*/
class AccountMessage extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'account_message';
protected string $primaryKey = 'mess_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['mess_id' => 'integer', 'account_id' => 'integer', 'message_id' => 'integer', 'read_flag' => 'integer'];
public static function list(array $param)
{
return (new self())->setTable("am")
->from("account_message as am")
->leftJoin("message as m", "m.message_id", "=", "am.message_id")
->where("m.recalled_flag", 0)
->where("m.type", $param['type'])
->where("am.account_id", $param['account_id'])
->whereNull("m.deleted_at")
->orderBy("am.read_flag")
->orderByDesc("am.mess_id")
->select(['am.mess_id', 'am.read_flag', 'am.create_time', 'm.title', 'm.extra'])
->paginate($param['limit']);
}
public static function read(array $param)
{
return (new self())->setTable("am")
->from("account_message as am")
->leftJoin("message as m", "m.message_id", "=", "am.message_id")
->where("m.recalled_flag", 0)
->whereNull("m.deleted_at")
->where("am.account_id", $param['account_id'])
->where("m.type", $param['type'])
->where("am.read_flag", 0)
->when(!empty($param['ids']), function ($query) use ($param) {
$query->whereIn("am.mess_id", $param['ids']);
})
->update([
'read_flag' => 1
]);
}
public static function detail(array $param)
{
return (new self())->setTable("am")
->from("account_message as am")
->leftJoin("message as m", "m.message_id", "=", "am.message_id")
->leftJoin("account as a", "a.account_id", "=", "m.create_id")
->where("m.recalled_flag", 0)
->whereNull("m.deleted_at")
->where("am.account_id", $param['account_id'])
->where("am.mess_id", $param['id'])
->select(['am.mess_id', 'am.create_time', 'm.title', 'm.content', 'm.extra', 'm.type', 'a.nickname'])
->first();
}
}