<?php




namespace app\common\dao\user;


use app\common\dao\BaseDao;
use app\common\model\user\LabelRule;

class LabelRuleDao extends BaseDao
{

    protected function getModel(): string
    {
        return LabelRule::class;
    }

    public function search(array $where)
    {
        return LabelRule::hasWhere('label')->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
            $query->whereLike('UserLabel.label_name', "%{$where['keyword']}%");
        })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
            $query->where('LabelRule.type', intval($where['type']));
        })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
            $query->where('LabelRule.mer_id', intval($where['mer_id']));
        });
    }
}