| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- /**
- * 加盟品牌服务
- * @author wesmielr
- */
- namespace app\index\service;
- use think\Db;
- class JiamengService
- {
- /**
- * 获取最新品牌
- * @param int $num
- * @return $this
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getNewList($num = 10)
- {
- $touziarr = config('params.touziLevels');
- $dataList = Db::name('jiameng')
- ->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)
- {
- var_dump($param);
- $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(function($query) use ($aid){
- $query->where(['j.area_id' => $aid])->whereOr(['j.area_id'=> 0]);
- });
- }
- })
- ->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;
- });
- }
- }
|