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
<?php
 
namespace app\common\model\supplier\member;
 
use app\common\model\BaseModel;
 
/**
 * 供应商年卡模型
 * 用于管理供应商年卡类型及其权益
 */
class Plan extends BaseModel
{
    // 表名
    protected $name = 'supplier_member_plan';
    protected $pk = 'plan_id';
    
    /**
     * 关联年卡权限
     */
    public function planAccess()
    {
        return $this->hasMany('app\common\model\supplier\member\PlanAccess', 'plan_id', 'plan_id');
    }
    /**
     * 获取启用的年卡列表
     */
    public function getEnabledPlans()
    {
        return $this->where(['status' => 1, 'is_default' =>0])
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select();
    }
    
    /**
     * 获取详情
     */
    public static function detail($planId)
    {
        return (new static())->with(['plan_access'])->where('plan_id', '=', $planId)->find();
    }
    
    /**
     * 获取列表
     */
    public function getList($data)
    {
        $model = $this;
        if (!empty($data['name'])) {
            $model = $model->where('name', 'like', '%' . $data['name'] . '%');
        }
        if (isset($data['status']) && $data['status'] >= 0) {
            $model = $model->where('status', '=', $data['status']);
        }
        return $model->where('app_id', '=', $data['app_id'])
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->paginate($data);
    }
}