144 行
3.5 KiB
PHP
144 行
3.5 KiB
PHP
<?php
|
|
|
|
namespace app\common\library;
|
|
|
|
use think\Db;
|
|
|
|
/**
|
|
* 后台列表关联信息展示
|
|
*
|
|
* 列表只展示业务名称(昵称 / 标题 / 分类 / 单号),不把数据库自增 ID 暴露给运营。
|
|
* 同一请求内按 ID 缓存,避免列表逐行重复查询。
|
|
*/
|
|
class FcRelation
|
|
{
|
|
protected static $users = [];
|
|
protected static $posts = [];
|
|
protected static $categories = [];
|
|
protected static $orders = [];
|
|
protected static $withdraws = [];
|
|
protected static $comments = [];
|
|
|
|
/**
|
|
* 用户信息
|
|
*/
|
|
public static function user($id)
|
|
{
|
|
$id = (int)$id;
|
|
if ($id <= 0) {
|
|
return null;
|
|
}
|
|
if (!array_key_exists($id, self::$users)) {
|
|
self::$users[$id] = Db::name('user')
|
|
->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;
|
|
}
|
|
}
|