<?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\services\operate;

use app\model\operate\ClientConfig;

class ClientConfigService{

	/**
	 * @title 获取广告
	 *
	 * @param [type] $request
	 * @return void
	 */
	public function getDataList($request){
		$param = $request->param();
		$order = "id desc";
		$map = [];
		if(isset($param['title']) && $param['title'] != ''){
			$map[] = ['title', 'LIKE', '%' . $param['title'] . '%'];
		}
		if(isset($param['name']) && $param['name'] != ''){
			$map[] = ['name', '=', $param['name']];
		}

		$list = ClientConfig::where($map)->order($order)->append(['status_text'])->paginate($request->pageConfig);
		return $list;
	}

	/**
	 * @title 添加广告
	 *
	 * @param [type] $request
	 * @return void
	 */
	public function create($request){
		$data = $request->param();

		return ClientConfig::create($data);
	}

	/**
	 * @title 编辑配置
	 *
	 * @param [type] $request
	 * @return void
	 */
	public function update($request){
		$data = $request->param();

		$config = ClientConfig::find($data['id']);
		$config->save($data);
        return $config;
	}

	/**
	 * @title 删除配置
	 *
	 * @param [type] $request
	 * @return void
	 */
	public function delete($request){
		$data = $request->param();

		$config = ClientConfig::find($data['id']);

		return $config->delete();
	}
}