Ad.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\common\model\ad;
  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 getList($limit = 20,$shop_supplier_id=0)
  15. {
  16. $where = [];
  17. if($shop_supplier_id){
  18. $where['shop_supplier_id'] = $shop_supplier_id;
  19. }
  20. return $this->with(['image','category'])->where($where)->order(['sort' => 'asc'])
  21. ->paginate($limit);
  22. }
  23. /**
  24. * 广告详情
  25. */
  26. public static function detail($ad_id)
  27. {
  28. return (new static())->with(['image'])->find($ad_id);
  29. }
  30. /**
  31. * 获取列表
  32. */
  33. public function getLists($where,$limit = 20)
  34. {
  35. // 获取列表
  36. $data = $this->limit($limit)
  37. ->where($where)
  38. ->with(['image'])
  39. ->order('sort asc')
  40. ->select();
  41. // 隐藏api属性
  42. !$data->isEmpty() ;
  43. return $data;
  44. }
  45. /**
  46. * 关联图片
  47. */
  48. public function image()
  49. {
  50. return $this->belongsTo('app\common\model\file\UploadFile', 'image_id', 'file_id');
  51. }
  52. /**
  53. * 关联分类表
  54. * @return \think\model\relation\BelongsTo
  55. */
  56. public function category()
  57. {
  58. $module = self::getCalledModule() ?: 'common';
  59. return $this->BelongsTo("app\\{$module}\\model\\ad\\AdCategory", 'category_id', 'category_id');
  60. }
  61. }