<?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\ClientMenu;

class ClientMenuService{

	/**
	 * @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 = ClientMenu::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();

		$data['user_id'] = $request->user['uid'];
		return ClientMenu::create($data);
	}

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

		$menu = ClientMenu::find($data['id']);
		return $client->save($data);
	}

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

		$menu = ClientMenu::find($data['id']);

		return $menu->delete();
	}
}