JiamengService.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * 加盟品牌服务
  4. * @author wesmielr
  5. */
  6. namespace app\index\service;
  7. use think\Db;
  8. class JiamengService
  9. {
  10. /**
  11. * 获取最新品牌
  12. * @param int $num
  13. * @return $this
  14. * @throws \think\db\exception\DataNotFoundException
  15. * @throws \think\db\exception\ModelNotFoundException
  16. * @throws \think\exception\DbException
  17. */
  18. public static function getNewList($num = 10)
  19. {
  20. $touziarr = config('params.touziLevels');
  21. $dataList = Db::name('jiameng')
  22. ->field('id,title,touzi_level,logo,mendian,hits')
  23. ->where('status', 1)
  24. ->order('update_time desc,create_time desc, id desc')
  25. ->limit($num)
  26. ->select()
  27. ->each(function ($item, $k) use ($touziarr) {
  28. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  29. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  30. return $item;
  31. });
  32. return $dataList;
  33. }
  34. /**
  35. * 获取热门排行榜
  36. * @param int $num
  37. * @return array|\PDOStatement|string|\think\Collection
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public static function getHotList($num = 20)
  43. {
  44. return Db::name('jiameng')
  45. ->field('id,title,thumb,hits')
  46. ->where(['status' => 1])->order('hits desc')
  47. ->limit($num)
  48. ->select();
  49. }
  50. /**
  51. * 获取加盟品牌列表
  52. * @param $param 参数
  53. * @param string $field 返回字段:连表别名j-jiameng,c1-category,c2-category
  54. * @param int $pageSize 分页大小
  55. * @return \think\Paginator
  56. * @throws \think\exception\DbException
  57. */
  58. public static function getList($param, $field = '', $pageSize = 20)
  59. {
  60. $pcatid = 0;
  61. $enname = isset($param['enname'])? trim($param['enname']) : '';
  62. if($enname){
  63. $pcatid = Db::name('category')->where('enname', $enname)->value('id');
  64. }
  65. $pcid = isset($param['pcid']) ? intval($param['pcid']) : 0;
  66. $pcid = $pcid>0? $pcid : $pcatid;
  67. $catids = [];
  68. if($pcid){
  69. $catids = Db::name('category')->where('parent_id', $pcid)->column('id');
  70. $catids[] = $pcid;
  71. }
  72. $pageParams = $param;
  73. $pageType = isset($param['pageType'])? : 0;
  74. if($pageType == 1){
  75. $pageParams = ['page'=> input('page', 1)];
  76. }
  77. $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,c1.catname as catname,c1.enname as encatname,c2.catname as pcatname,c2.enname as penname';
  78. $dataList = Db::name('jiameng')->alias('j')
  79. ->field($field)
  80. ->leftJoin('category c1', 'c1.id=j.catid')
  81. ->leftJoin('category c2', 'c2.id=j.pcatid')
  82. ->where(function ($query) use ($param, $catids) {
  83. $kw = isset($param['kw']) ? trim($param['kw']) : '';
  84. if ($kw) {
  85. $query->where('j.title', 'like', "%{$kw}%");
  86. }
  87. // 信息等级
  88. $level = isset($param['level'])? intval($param['level']) : 0;
  89. if($level>0){
  90. $query->where(['j.level' => $level]);
  91. }
  92. $catid = isset($param['catid']) ? intval($param['catid']) : 0;
  93. if ($catid > 0) {
  94. $query->where(['j.catid|j.pcatid' => $catid]);
  95. }
  96. if ($catids) {
  97. $query->where('catid','in', $catids);
  98. }
  99. $lv = isset($param['lv']) ? intval($param['lv']) : -1;
  100. $lv = $lv>0? $lv : (isset($param['touzi_level']) ? intval($param['touzi_level']) : -1);
  101. if ($lv >= 0) {
  102. $query->where(['j.touzi_level' => $lv]);
  103. }
  104. $aid = isset($param['aid']) ? intval($param['aid']) : -1;
  105. $aid = $aid>0? $aid : (isset($param['area_id']) ? intval($param['area_id']) : -1);
  106. if ($aid > 0) {
  107. $query->where(['j.area_id' => $aid]);
  108. }
  109. })
  110. ->order('j.update_time desc, j.create_time desc, j.list_order')
  111. ->paginate($pageSize, false, ['query' => $pageParams]);
  112. // echo Db::name('jiameng')->getLastSql();
  113. return $dataList;
  114. }
  115. /**
  116. * 获取等级信息品牌列表
  117. * @param $level 等级:1--今日之星,2-品牌精选,3-品牌推荐,4-品牌严选,5-默认,6-推荐专题品牌
  118. * @param int $pageSize 记录数
  119. * @param string $field 返回字段
  120. * @return $this
  121. * @throws \think\db\exception\DataNotFoundException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. * @throws \think\exception\DbException
  124. */
  125. public static function getListByLevel($level, $pageSize=10,$field=''){
  126. $touziarr = config('params.touziLevels');
  127. $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';
  128. return Db::name('jiameng')
  129. ->alias('j')
  130. ->leftJoin('category c1', 'c1.id=j.catid')
  131. ->field($field)
  132. ->where('j.level',$level)
  133. ->where('j.status',1)
  134. ->order('j.list_order asc, j.id desc')
  135. ->limit($pageSize)
  136. ->select()
  137. ->each(function($item, $k) use ($touziarr){
  138. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  139. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  140. return $item;
  141. });
  142. }
  143. /**
  144. * 获取排行榜数据
  145. * @param $where 条件
  146. * @param $pageSize 记录数
  147. * @param string $field 字段
  148. * @return $this
  149. * @throws \think\db\exception\DataNotFoundException
  150. * @throws \think\db\exception\ModelNotFoundException
  151. * @throws \think\exception\DbException
  152. */
  153. public static function getTopList($where, $pageSize=10, $field=''){
  154. $touziarr = config('params.touziLevels');
  155. $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';
  156. return Db::name('jiameng')
  157. ->alias('j')
  158. ->leftJoin('category c1', 'c1.id=j.catid')
  159. ->leftJoin('category c2', 'c2.id=j.pcatid')
  160. ->field($field)
  161. ->where('j.status', 1)
  162. ->where($where)
  163. ->order('j.hits desc')
  164. ->limit($pageSize)
  165. ->select()
  166. ->each(function($item, $k) use ($touziarr){
  167. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  168. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  169. return $item;
  170. });
  171. }
  172. }