首页上一页'; } else { $linkPage .= '首页'; $linkPage .= ''; } /** * 中间页码 */ for ($i = $currentPage - $halfPer, $i > 1 || $i = 1, $j = $currentPage + $halfPer, $j < $totalPages || $j = $totalPages; $i < (int)$j + 1; $i++) { $linkPage .= ($i == $currentPage) ? '' . $i . '' : '' . $i . ''; } // 当前页码小于总数 if ($currentPage < $totalPages) { $linkPage .= ''; $linkPage .= '尾页'; } else { $linkPage .= '下一页尾页'; } // 祛除首页地址 $linkPage = str_replace('planUrl', 'page', $linkPage); return str_replace('list_1.html', '', $linkPage); } } if (!function_exists('get_adwords')) { /** * 获取广告词 * @param string $adwords * @return string */ function get_adwords(string $adwords): string { return '
广告位招租
'; $adwords = explode(',', $adwords); return $adwords[array_rand($adwords)]; } } if (!function_exists('parse_tag')) { /** * 生成参数列表,以数组形式返回 * @param string $tag 字符串 * @return array */ function parse_tag($tag) { if (is_array($tag)) { return $tag; } $param = array(); //标签解析 $array = explode(';', $tag); foreach ($array as $key => $val) { if (!empty($val)) { $temp = explode(':', trim($val)); if (!empty($temp[1])) { $param[$temp[0]] = $temp[1]; } } } if (!isset($param['status'])) { // 默认只查询已审核的 $param['status'] = 1; } return $param; } } if (!function_exists('mysql_comment')) { /** * 获取用户评论 * @param $param * @param int $page * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ function mysql_comment($param, $page = 1) { $param = parse_tag($param); $field = !empty($param['field']) ? $param['field'] : '*'; $limit = !empty($param['limit']) ? $param['limit'] : '2'; $order = !empty($param['order']) ? $param['order'] : 'id desc'; // 默认查询首屏 $where = []; if (empty($param['pid'])) { $where[] = ['pid', '=', 0]; } else if ($param['pid'] != 'self') { $where[] = ['pid', '=', $param['pid']]; } if (!empty($param['cid'])) { $where[] = ['cid', '=', $param['cid']]; } if (!empty($param['sid'])) { $where[] = ['sid', '=', $param['sid']]; } if (!empty($param['user_id'])) { $where[] = ['user_id', '=', $param['user_id']]; } // 默认为文章类型 if (empty($param['tid'])) { $where[] = ['tid', '=', 1]; } else { $where[] = ['tid', '=', $param['tid']]; } // 获取总数 $count = Comment::where($where)->count('id'); // 设置分页 $page = ($count <= $limit) ? 1 : $page; $totalPages = ceil($count / $limit); $list = Comment::with(['user', 'child'])->where($where)->order($order)->limit($limit)->page($page)->select()->toArray(); return ['data' => $list, 'total' => $count, 'maxPage' => $totalPages, 'pages' => '']; } }