| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | <?phpnamespace App\Services\Content;use App\Models\AdCategory;use App\Repositories\AdCategoryRepository;use App\Repositories\AdRepository;class AdService{    /**     * @var AdCategoryRepository     */    protected $adCategoryRepository;    protected $adRepository;    public function __construct(AdCategoryRepository $adCategoryRepository, AdRepository $adRepository)    {        $this->adCategoryRepository = $adCategoryRepository;        $this->adRepository = $adRepository;    }    public function getAds($data)    {        $where = array();        $theme = 'default';        if (array_key_exists('theme', $data)) {            $theme = $data['theme'];        }        $where['c.theme'] = $theme;        $org = 'Home';        if (array_key_exists('org', $data)) {            $org = $data['org'];        }        $where['c.org'] = $org;        //错误提示        if (!in_array($org, array('Home','Mobile','Apk'))) {            throw new \Exception('参数不正确');        }        if (array_key_exists('alias', $data)) {            $alias = $data['alias'];            $where['c.alias'] = $alias;        }        $where['is_display'] = 1;        $limit = $data['num'];        //获取广告信息        $ads = $this->adRepository->getAds($where, $limit);        return $ads;    }}
 |