where('id', $id) ->field('id,username,nickname,mobile') ->find() ?: null; } return self::$users[$id]; } /** * 用户显示名:昵称优先,其次账号 */ public static function userName($id) { $user = self::user($id); if (!$user) { return ''; } return $user['nickname'] !== '' && $user['nickname'] !== null ? $user['nickname'] : $user['username']; } /** * 用户手机号 */ public static function userMobile($id) { $user = self::user($id); return $user ? $user['mobile'] : ''; } /** * 信息标题 */ public static function postTitle($id) { $id = (int)$id; if ($id <= 0) { return ''; } if (!array_key_exists($id, self::$posts)) { self::$posts[$id] = (string)Db::name('fc_post')->where('id', $id)->value('title'); } return self::$posts[$id]; } /** * 分类名称 */ public static function categoryName($id) { $id = (int)$id; if ($id <= 0) { return ''; } if (!array_key_exists($id, self::$categories)) { self::$categories[$id] = (string)Db::name('fc_category')->where('id', $id)->value('name'); } return self::$categories[$id]; } /** * 订单号 */ public static function orderNo($id) { $id = (int)$id; if ($id <= 0) { return ''; } if (!array_key_exists($id, self::$orders)) { self::$orders[$id] = (string)Db::name('fc_order')->where('id', $id)->value('order_no'); } return self::$orders[$id]; } /** * 提现单号 */ public static function withdrawNo($id) { $id = (int)$id; if ($id <= 0) { return ''; } if (!array_key_exists($id, self::$withdraws)) { self::$withdraws[$id] = (string)Db::name('fc_withdraw')->where('id', $id)->value('withdraw_no'); } return self::$withdraws[$id]; } /** * 评价内容摘要 */ public static function commentSnippet($id, $length = 40) { $id = (int)$id; if ($id <= 0) { return ''; } if (!array_key_exists($id, self::$comments)) { self::$comments[$id] = (string)Db::name('fc_comment')->where('id', $id)->value('content'); } $content = self::$comments[$id]; if ($content === '') { return ''; } return mb_strlen($content, 'utf-8') > $length ? mb_substr($content, 0, $length, 'utf-8') . '…' : $content; } }