$data['diyname']]); } public function getFullurlAttr($value, $data) { return addon_url('cms/page/index', [':diyname' => $data['diyname']], true, true); } /** * 获取单页列表 * @param $params * @return false|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getPageList($params) { $name = empty($params['name']) ? '' : $params['name']; $condition = empty($params['condition']) ? '' : $params['condition']; $field = empty($params['field']) ? '*' : $params['field']; $row = empty($params['row']) ? 10 : (int)$params['row']; $orderby = empty($params['orderby']) ? 'nums' : $params['orderby']; $orderway = empty($params['orderway']) ? 'desc' : strtolower($params['orderway']); $limit = empty($params['limit']) ? $row : $params['limit']; $cache = !isset($params['cache']) ? true : (int)$params['cache']; $imgwidth = empty($params['imgwidth']) ? '' : $params['imgwidth']; $imgheight = empty($params['imgheight']) ? '' : $params['imgheight']; $orderway = in_array($orderway, ['asc', 'desc']) ? $orderway : 'desc'; $where = []; if ($name !== '') { $where['name'] = $name; } $order = $orderby == 'rand' ? 'rand()' : (in_array($orderby, ['name', 'id', 'createtime', 'updatetime']) ? "{$orderby} {$orderway}" : "id {$orderway}"); $list = self::where($where) ->where($condition) ->field($field) ->order($order) ->limit($limit) ->cache($cache) ->select(); self::render($list, $imgwidth, $imgheight); return $list; } public static function render(&$list, $imgwidth, $imgheight) { $width = $imgwidth ? 'width="' . $imgwidth . '"' : ''; $height = $imgheight ? 'height="' . $imgheight . '"' : ''; foreach ($list as $k => &$v) { $v['hasimage'] = $v->getData('image') ? true : false; $v['textlink'] = '' . $v['title'] . ''; $v['imglink'] = ''; $v['img'] = ''; } return $list; } }