timestamps = false; } /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function webSocketDialogMsg(): \Illuminate\Database\Eloquent\Relations\HasOne { return $this->hasOne(WebSocketDialogMsg::class, 'id', 'msg_id'); } /** * 强制标记成阅读 * @param $dialogId * @param $userId * @return void */ public static function forceRead($dialogId, $userId) { self::whereDialogId($dialogId) ->whereUserid($userId) ->whereNull('read_at') ->update(['read_at' => Carbon::now()]); } /** * 仅标记成阅读 * @param $list * @return void */ public static function onlyMarkRead($list) { $dialogMsg = []; /** @var WebSocketDialogMsgRead $item */ foreach ($list as $item) { $item->read_at = Carbon::now(); $item->save(); if (isset($dialogMsg[$item->msg_id])) { $dialogMsg[$item->msg_id]['readNum']++; } else { $dialogMsg[$item->msg_id] = [ 'dialogMsg' => $item->webSocketDialogMsg, 'readNum' => 1 ]; } } foreach ($dialogMsg as $item) { if ($item['dialogMsg']) { $item['dialogMsg']->increment('read', $item['readNum']); } } } }