Banner.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\model;
  3. class Banner extends BaseModel
  4. {
  5. /**
  6. * @var string
  7. */
  8. protected $name = 'banner';
  9. /**
  10. * @var array
  11. */
  12. protected $auto = [];
  13. /**
  14. * @var array
  15. */
  16. protected $insert = ['created_at','updated_at'];
  17. /**
  18. * @var array
  19. */
  20. protected $update = ['updated_at'];
  21. /**
  22. * @var array
  23. */
  24. protected $hidden = ['deleted_at','updated_at'];
  25. /**
  26. * 关联获取Banner Item表
  27. * @return \think\model\relation\HasMany
  28. */
  29. public function items()
  30. {
  31. return $this->hasMany('BannerItem', 'banner_id', 'id')->where(['status' => 1]);
  32. }
  33. /**
  34. * 获取Banner 数据
  35. * @param $id
  36. *
  37. * @return array|\PDOStatement|string|\think\Model|null
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public static function getBannerById($id)
  43. {
  44. return self::with(['items'])->find($id);
  45. }
  46. }