SchoolAlbum.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: thinkphp <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model;
  13. use cores\BaseModel;
  14. /**
  15. * 学校图库模型类
  16. * Class SchoolAlbum
  17. * @package app\common\model
  18. */
  19. class SchoolAlbum extends BaseModel
  20. {
  21. protected $globalScope = [''];
  22. // 定义表名
  23. protected $name = 'school_album';
  24. // 定义主键
  25. protected $pk = 'album_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, $limitRow=0){
  36. if($list = \think\facade\Cache::get('caches:schools:albums:'.$schoolId)){
  37. return $list;
  38. }
  39. $query = self::where(['school_id'=>$schoolId]);
  40. if($limitRow){
  41. $query->limit($limitRow);
  42. }
  43. $list = $query->field('album_id,title,album_url')
  44. ->order('album_id desc')
  45. ->select();
  46. $list = $list? $list->toArray() :[];
  47. if($list){
  48. foreach ($list as &$item){
  49. $item['image'] = $item['album_url']? getPreview($item['album_url']) : '';
  50. }
  51. \think\facade\Cache::set('caches:schools:albums:'.$schoolId, $list, rand(5, 10));
  52. }
  53. return $list;
  54. }
  55. }