'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(); } }