where("identity_type", \E_IDENTITY_TYPE::User) ->where("to_user_id", $user_id) ->order("updatetime", "desc") ->page($page) ->paginate($size); } public function fetchMassagerSystemMessage($m_id, $page, $size) { return $this->where("identity_type", \E_IDENTITY_TYPE::Massager) ->where("to_massager_id", $m_id) ->order("updatetime", "desc") ->page($page) ->paginate($size); } public function fetchAgencySystemMessage($a_id, $page, $size) { return $this->where("identity_type", \E_IDENTITY_TYPE::Agency) ->where("to_agency_id", $a_id) ->order("updatetime", "desc") ->page($page) ->paginate($size); } /** * @param $m_id * @return int|string * @throws \think\Exception */ public function getUnreadMessageCount($m_id) { return $this->where("identity_type", \E_IDENTITY_TYPE::Massager) ->where("to_massager_id", $m_id) ->where("is_read", 0) ->count(); } /** * 给系统用户发送系统消息 * @param $identity_type * @param array $to_target * @param $title * @param $content * @return Message */ public static function sendSystemMessage($identity_type, array $to_target, $title, $content) { return self::create([ "identity_type" => $identity_type, "to_user_id" => isset($to_target["to_user_id"]) ? $to_target["to_user_id"] : null, "to_massager_id" => isset($to_target["to_massager_id"]) ? $to_target["to_massager_id"] : null, "to_agency_id" => isset($to_target["to_agency_id"]) ? $to_target["to_agency_id"] : null, "title" => $title, "content" => $content, "is_read" => 0, "createtime" => time(), "updatetime" => time() ]); } /** * @param $msgs * @return bool|int|string */ public static function sendSystemMessages($msgs) { return self::insertAll($msgs); } }