<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin\operate;

use app\controller\Base;
use app\services\operate\AdsService;

class Ads extends Base{


	/**
	 * @title 广告列表
	 *
	 * @param AdsService $service
	 * @return void
	 */
	public function index(AdsService $service){
		$this->data['data'] = $service->getDataList($this->request);
		return $this->data;
	}

	/**
	 * @title 添加广告
	 *
	 * @param AdsService $service
	 * @return void
	 */
	public function add(AdsService $service){
		try {
			$data = $service->create($this->request);
			$this->data['code'] = 1;
			$this->data['data'] = $data;
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return $this->data;
	}

	/**
	 * @title 编辑广告
	 *
	 * @param AdsService $service
	 * @return void
	 */
	public function edit(AdsService $service){
		try {
			$data = $service->update($this->request);
			$this->data['code'] = 1;
			$this->data['data'] = $data;
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return $this->data;
	}

	/**
	 * @title 删除广告
	 *
	 * @param AdsService $service
	 * @return void
	 */
	public function delete(AdsService $service){
		try {
			$data = $service->delete($this->request);
			$this->data['code'] = 1;
			$this->data['data'] = $data;
		} catch (\Exception $e) {
			$this->data['code'] = 0;
			$this->data['message'] = $e->getMessage();
		}
		return $this->data;
	}
}