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