field('id,title,touzi_level,logo,mendian,hits') ->where('status', 1) ->order('update_time desc,create_time desc, id desc') ->limit($num) ->select() ->each(function ($item, $k) use ($touziarr) { $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1'; $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : ''; return $item; }); return $dataList; } /** * 获取热门排行榜 * @param int $num * @return array|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getHotList($num = 20) { return Db::name('jiameng') ->field('id,title,thumb,hits,zhiying') ->where(['status' => 1])->order('hits desc') ->limit($num) ->select(); } /** * 获取加盟品牌列表 * @param $param 参数 * @param string $field 返回字段:连表别名j-jiameng,c1-category,c2-category * @param int $pageSize 分页大小 * @return \think\Paginator * @throws \think\exception\DbException */ public static function getList($param, $field = '', $pageSize = 20) { $pcatid = 0; $enname = isset($param['enname'])? trim($param['enname']) : ''; if($enname){ $pcatid = Db::name('category')->where('enname', $enname)->value('id'); } $pcid = isset($param['pcid']) ? intval($param['pcid']) : 0; $pcid = $pcid>0? $pcid : $pcatid; $catids = []; if($pcid){ $catids = Db::name('category')->where('parent_id', $pcid)->column('id'); $catids[] = $pcid; } $pageParams = $param; $pageType = isset($param['pageType'])? : 0; if($pageType == 1){ $pageParams = ['page'=> input('page', 1)]; } $field = $field ? $field : 'j.id,j.title,j.logo,j.catid,j.pcatid,j.touzi_level,j.area,j.level,j.company,j.product,j.area_id,j.mendian,j.zhiying,j.found_at,j.is_choose,c1.catname as catname,c1.enname as encatname,c2.catname as pcatname,c2.enname as penname'; $dataList = Db::name('jiameng')->alias('j') ->field($field) ->leftJoin('category c1', 'c1.id=j.catid') ->leftJoin('category c2', 'c2.id=j.pcatid') ->where(function ($query) use ($param, $catids) { $query->where('j.status', 1); $kw = isset($param['kw']) ? trim($param['kw']) : ''; if ($kw) { $query->where('j.title', 'like', "%{$kw}%"); } // 信息等级 $level = isset($param['level'])? intval($param['level']) : 0; if($level>0){ $query->where(['j.level' => $level]); } $catid = isset($param['catid']) ? intval($param['catid']) : 0; if ($catid > 0) { $query->where(['j.catid|j.pcatid' => $catid]); } if ($catids) { $query->where('catid','in', $catids); } $lv = isset($param['lv']) ? intval($param['lv']) : -1; $lv = $lv>0? $lv : (isset($param['touzi_level']) ? intval($param['touzi_level']) : -1); if ($lv >= 0) { $query->where(['j.touzi_level' => $lv]); } $aid = isset($param['aid']) ? intval($param['aid']) : -1; $aid = $aid>0? $aid : (isset($param['area_id']) ? intval($param['area_id']) : -1); if ($aid > 0) { $query->where(['j.area_id' => $aid]); } }) ->order('j.update_time desc, j.create_time desc, j.list_order') ->paginate($pageSize, false, ['query' => $pageParams]); // echo Db::name('jiameng')->getLastSql(); return $dataList; } /** * 获取等级信息品牌列表 * @param $level 等级:1--今日之星,2-品牌精选,3-品牌推荐,4-品牌严选,5-默认,6-推荐专题品牌 * @param int $pageSize 记录数 * @param string $field 返回字段 * @return $this * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getListByLevel($level, $pageSize=10,$field=''){ $touziarr = config('params.touziLevels'); $field = $field? $field : 'j.id,j.title,j.touzi_level,j.logo,j.hits,j.guanggaowei,j.touzi_level,j.cover_area,j.mendian,j.product,c1.catname'; return Db::name('jiameng') ->alias('j') ->leftJoin('category c1', 'c1.id=j.catid') ->field($field) ->where('j.level',$level) ->where('j.status',1) ->order('j.list_order asc, j.id desc') ->limit($pageSize) ->select() ->each(function($item, $k) use ($touziarr){ $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1'; $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : ''; return $item; }); } /** * 获取排行榜数据 * @param $where 条件 * @param $pageSize 记录数 * @param string $field 字段 * @return $this * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getTopList($where, $pageSize=10, $field=''){ $touziarr = config('params.touziLevels'); $field = $field? $field : 'j.id,j.title,j.touzi_level,j.logo,j.guanggaowei,j.touzi_level,j.cover_area,j.mendian,j.product,c1.catname,c2.catname as pcatname'; return Db::name('jiameng') ->alias('j') ->leftJoin('category c1', 'c1.id=j.catid') ->leftJoin('category c2', 'c2.id=j.pcatid') ->field($field) ->where('j.status', 1) ->where($where) ->order('j.hits desc') ->limit($pageSize) ->select() ->each(function($item, $k) use ($touziarr){ $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1'; $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : ''; return $item; }); } }