Ad.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\common\model\page;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 广告模型
  6. */
  7. class Ad extends BaseModel
  8. {
  9. protected $name = 'ad';
  10. protected $pk = 'ad_id';
  11. /**
  12. * 获取全部
  13. */
  14. public function getAll()
  15. {
  16. return $this->order(['sort' => 'asc'])->select();
  17. }
  18. /**
  19. * 获取列表
  20. */
  21. public function getList($limit = 20)
  22. {
  23. return $this->with(['image','category'])->order(['sort' => 'asc'])
  24. ->paginate($limit);
  25. }
  26. /**
  27. * 广告详情
  28. */
  29. public static function detail($ad_id)
  30. {
  31. return (new static())->with(['image'])->find($ad_id);
  32. }
  33. /**
  34. * 获取列表
  35. */
  36. public function getLists($where,$limit = 20)
  37. {
  38. // 获取列表
  39. $data = $this->limit($limit)
  40. ->where($where)
  41. ->with(['image'])
  42. ->order('sort asc')
  43. ->select();
  44. // 隐藏api属性
  45. !$data->isEmpty() ;
  46. return $data;
  47. }
  48. /**
  49. * 关联图片
  50. */
  51. public function image()
  52. {
  53. return $this->belongsTo('app\common\model\file\UploadFile', 'image_id', 'file_id');
  54. }
  55. /**
  56. * 关联分类表
  57. * @return \think\model\relation\BelongsTo
  58. */
  59. public function category()
  60. {
  61. $module = self::getCalledModule() ?: 'common';
  62. return $this->BelongsTo("app\\{$module}\\model\\page\\AdCategory", 'category_id', 'category_id');
  63. }
  64. }