SchoolNew.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model;
  13. use cores\BaseModel;
  14. /**
  15. * 学校图库模型类
  16. * Class SchoolNew
  17. * @package app\common\model
  18. */
  19. class SchoolNew extends BaseModel
  20. {
  21. protected $globalScope = [''];
  22. // 定义表名
  23. protected $name = 'school_news';
  24. // 定义主键
  25. protected $pk = 'news_id';
  26. /**
  27. * 获取学校新闻资讯列表
  28. * @param $schoolId
  29. * @param int $limitRow
  30. * @return array|mixed
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public static function getShowList($schoolId, $type = 1, $limitRow=0){
  36. $cacheKey = "caches:schools:news:{$schoolId}_{$type}_{$limitRow}";
  37. if($list = \think\facade\Cache::get($cacheKey)){
  38. return $list;
  39. }
  40. $query = self::where(['school_id'=>$schoolId, 'type'=> $type, 'status'=>1]);
  41. if($limitRow){
  42. $query->limit($limitRow);
  43. }
  44. $list = $query->order('addtime desc,news_id desc')->select();
  45. $list->hidden(['content','update_time','status']);
  46. $list = $list? $list->toArray() :[];
  47. if($list){
  48. foreach ($list as &$item){
  49. $item['logo_preview'] = $item['logo']? getPreview($item['logo']) : '';
  50. $item['publish_time'] = $item['addtime']? date('Y/m/d', strtotime($item['addtime'])) : '';
  51. }
  52. \think\facade\Cache::set($cacheKey, $list, rand(10, 30));
  53. }
  54. return $list;
  55. }
  56. public function getList($where, $limitRow= 15){
  57. }
  58. }