<?php

namespace App\Ad\Controllers;


use App\Ad\Services\SysAdService;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class AdController extends BaseController
{
    private $service;
    public function __construct(SysAdService $service)
    {
        $this->service = $service;
    }

    /**
     * 广告保存
     * */
    public function saveAd(Request $request){
        $this->validate($request, [
            'position_id' => 'required',
        ], [
            'position_id.required' => '位置不能为空',
        ]);
        $params=$request->only(['id','position_id','ad_title','ad_file','ad_description', 'start_time','end_time',
            'ad_link','ad_link_type','ad_script','form_id','type','remark','hit_num','hit_click_num',
            'push_num']);
        $ret=$this->service->saveAd($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }


    /**
     * 广告保存
     * */
    public function changeStatus(Request $request){
        $this->validate($request, [
            'id' => 'required',
        ], [
            'id.required' => 'id不能为空',
        ]);
        $params=$request->only(['id','status']);
        $ret=$this->service->saveAd($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 获取广告列表
     * */
    public function getAdList(Request $request){
        $params=$request->only(['page_size','page','status']);
        $ret=$this->service->getAdList($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 获取广告位列表
     * */
    public function getAdPositionList(Request $request){
        $params=$request->only(['page_size','page','status']);
        $ret=$this->service->getAdPositionList($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }
}
