Banner.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\api\model;
  13. use app\common\exception\BaseException;
  14. use app\common\library\helper;
  15. use app\common\model\Banner as BannerModel;
  16. use app\common\model\Region;
  17. /**
  18. * 轮播幻灯片模型
  19. * Class Banner
  20. * @package app\api\model
  21. */
  22. class Banner extends BannerModel
  23. {
  24. /**
  25. * 隐藏字段
  26. * @var array
  27. */
  28. protected $hidden = [
  29. 'create_time',
  30. 'update_time'
  31. ];
  32. /**
  33. * 获取列表
  34. * @param array $param 查询条件
  35. * @param int $listRows 分页数量
  36. * @return mixed|\think\model\Collection|\think\Paginator
  37. * @throws \think\db\exception\DbException
  38. */
  39. public function getList(array $param = [], int $listRows = 15)
  40. {
  41. // 整理查询参数
  42. $params = array_merge($param, ['status' => 1]);
  43. // 获取商品列表
  44. $list = parent::getList($params, $listRows);
  45. if ($list->isEmpty()) {
  46. return $list;
  47. }
  48. // 隐藏冗余的字段
  49. $list->hidden(array_merge($this->hidden, ['albums']));
  50. // 整理列表数据并返回
  51. return $this->setListDataFromApi($list);
  52. }
  53. /**
  54. * 设置展示的数据 api模块
  55. * @param $info
  56. * @return mixed
  57. */
  58. private function setListDataFromApi($info)
  59. {
  60. return $this->setListData($info, function ($data){
  61. // 整理数据 api模块
  62. $this->setDataFromApi($data);
  63. });
  64. }
  65. /**
  66. * 整理数据 api模块
  67. * @param $info
  68. * @return mixed
  69. */
  70. private function setDataFromApi($info)
  71. {
  72. return $this->setData($info, function ($data) {
  73. $this->hidden(['update_time','status']);
  74. });
  75. }
  76. /**
  77. * 获取图片预览
  78. * @param $value
  79. * @return string
  80. */
  81. public function getImageAttr($value)
  82. {
  83. return $value? getPreview($value) : '';
  84. }
  85. }