buildUrl($value, $data); } public function getFullurlAttr($value, $data) { return $this->buildUrl($value, $data, true); } private function buildUrl($value, $data, $domain = false) { $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id']; $time = $data['createtime'] ?? time(); $vars = [ ':id' => $data['id'], ':diyname' => $diyname, ':year' => date("Y", $time), ':month' => date("m", $time), ':day' => date("d", $time) ]; $suffix = static::$config['moduleurlsuffix']['page'] ?? static::$config['urlsuffix']; return addon_url('shop/page/index', $vars, $suffix, $domain); } public function getContentAttr($value, $data) { if (isset($data['parsetpl']) && $data['parsetpl']) { $view = View::instance(); $view->engine->layout(false); return $view->display($data['content']); } //组装卡片信息 return \addons\shop\library\Service::formatSourceTpl($data['content']); } public function getHasimageAttr($value, $data) { return $this->getData("image") ? true : false; } public function getLikeratioAttr($value, $data) { return bcmul(($data['dislikes'] > 0 ? min(1, $data['likes'] / ($data['dislikes'] + $data['likes'])) : ($data['likes'] ? 1 : 0.5)), 100); } /** * 获取单页列表 * @param $params * @return false|\PDOStatement|string|\think\Collection */ public static function getPageList($params) { $type = empty($params['type']) ? '' : $params['type']; $condition = empty($params['condition']) ? '' : $params['condition']; $field = empty($params['field']) ? '*' : $params['field']; $row = empty($params['row']) ? 10 : (int)$params['row']; $orderby = empty($params['orderby']) ? 'createtime' : $params['orderby']; $orderway = empty($params['orderway']) ? 'desc' : strtolower($params['orderway']); $limit = empty($params['limit']) ? $row : $params['limit']; $imgwidth = empty($params['imgwidth']) ? '' : $params['imgwidth']; $imgheight = empty($params['imgheight']) ? '' : $params['imgheight']; $orderway = in_array($orderway, ['asc', 'desc']) ? $orderway : 'desc'; $paginate = !isset($params['paginate']) ? false : $params['paginate']; list($cacheKey, $cacheExpire) = Service::getCacheKeyExpire('pagelist', $params); self::$tagCount++; $where = ['status' => 'normal']; if ($type !== '') { $where['type'] = $type; } $order = $orderby == 'rand' ? Db::raw('rand()') : (preg_match("/\,|\s/", $orderby) ? $orderby : "{$orderby} {$orderway}"); $pageModel = self::where($where) ->where($condition) ->field($field) ->orderRaw($order); if ($paginate) { $paginateArr = explode(',', $paginate); $listRows = is_numeric($paginate) ? $paginate : (is_numeric($paginateArr[0]) ? $paginateArr[0] : $row); $config = []; $config['var_page'] = $paginateArr[2] ?? 'ppage' . self::$tagCount; $config['path'] = $paginateArr[3] ?? ''; $config['fragment'] = $paginateArr[4] ?? ''; $config['query'] = request()->get(); $config['type'] = '\\addons\\shop\\library\\Bootstrap'; $list = $pageModel->paginate($listRows, ($paginateArr[1] ?? false), $config); } else { $list = $pageModel->limit($limit)->cache($cacheKey, $cacheExpire, 'shop')->select(); } self::render($list, $imgwidth, $imgheight); return $list; } public static function getPageInfo($params) { $config = get_addon_config('shop'); $sid = empty($params['sid']) ? '' : $params['sid']; $condition = empty($params['condition']) ? '' : $params['condition']; $field = empty($params['field']) ? '*' : $params['field']; $row = empty($params['row']) ? 10 : (int)$params['row']; $orderby = empty($params['orderby']) ? 'weigh' : $params['orderby']; $orderway = empty($params['orderway']) ? 'desc' : strtolower($params['orderway']); $limit = empty($params['limit']) ? $row : $params['limit']; $imgwidth = empty($params['imgwidth']) ? '' : $params['imgwidth']; $imgheight = empty($params['imgheight']) ? '' : $params['imgheight']; $orderway = in_array($orderway, ['asc', 'desc']) ? $orderway : 'desc'; list($cacheKey, $cacheExpire) = Service::getCacheKeyExpire('pageinfo', $params); $where = []; if ($sid !== '') { $where['id'] = $sid; } $order = $orderby == 'rand' ? Db::raw('rand()') : (preg_match("/\,|\s/", $orderby) ? $orderby : "{$orderby} {$orderway}"); $order = $orderby == 'weigh' ? $order . ',id DESC' : $order; $data = self::where($where) ->where($condition) ->field($field) ->order($order) ->limit($limit) ->cache($cacheKey, $cacheExpire, 'shop') ->find(); if ($data) { $list = [$data]; self::render($list, $imgwidth, $imgheight); return reset($list); } else { return false; } } public static function render(&$list, $imgwidth, $imgheight) { $width = $imgwidth ? 'width="' . $imgwidth . '"' : ''; $height = $imgheight ? 'height="' . $imgheight . '"' : ''; foreach ($list as $k => &$v) { $v['textlink'] = '' . $v['title'] . ''; $v['imglink'] = ''; $v['img'] = ''; } return $list; } }