$max ? $max : $num; } /** * 获取消息列表 * @return array */ public static function getNoticeList($uid, $page, $limit = 20) { $max = sys_config_int('notice_max', 60); $limit = $max; $prefix = Env::get('database.prefix', 'eb_'); $tnotice = $prefix . 'user_notice'; $tnotice_see = $prefix . 'user_notice_see'; $sql = sprintf(" select n.id, n.icon, n.`user` as `from`, n.title as subject, n.content as `body`, n.add_time as ts, n.`type`, s.id as `read` from %s n left join (select id,nid from %s where uid=%d) s on n.id = s.nid where n.uid in (%d, 0) and n.del_time=0 order by n.add_time desc limit %d,%d ", $tnotice, $tnotice_see, $uid, $uid, ($page - 1) * $limit, $limit); // echo $sql; $data = Db::query($sql); return $data; } /** * 用户删除消息, 软删除 * @param $uid * @param $ids */ public static function delNotice($uid, $ids) { $model = new self; $model->where('uid', $uid)->whereIn('id', $ids)->update(['del_time' => time()]); } /** * 设为已读 * @param $uid * @param $nids */ public static function seeNotice($uid, $nids) { $rows = []; foreach ($nids as $nid) { $rows[] = [ 'nid' => $nid, 'uid' => $uid, 'add_time' => time(), ]; } try { UserNoticeSee::setAll($rows); } catch (\Exception $e) { warnlog("seeNotice exception.sql=" . UserNoticeSee::getLastSql()); } } public static function unseeNotice($uid, $nids) { foreach ($nids as $nid) { try { UserNoticeSee::where('uid', $uid)->where('nid', $nid)->delete(); } catch (\Exception $e) { warnlog("unseeNotice exception.sql=" . UserNoticeSee::getLastSql()); } } } }