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

class ClientService{

	/**
	 * @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 = Client::with(['setting'])->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 Client::create($data);
	}

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

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

	public function getClientMenu($request){
		$param = $request->param();

		$list = [];
		if(isset($param['type'])){
			if($param['type'] == 'home'){
				$list = [
					['title' => '常考题', 'image' => request()->static() . 'images/icon/5.jpg', 'url' => '/pages/exam/index/index'],
					['title' => '模拟考', 'image' => request()->static() . 'images/icon/6.jpg', 'url' => '/pages/exam/index/index'],
					['title' => '题库练习', 'image' => request()->static() . 'images/icon/7.jpg', 'url' => '/pages/exam/index/index'],
					['title' => '易错题', 'image' => request()->static() . 'images/icon/8.jpg', 'url' => '/pages/exam/index/index'],
					['title' => '我的错题', 'image' => request()->static() . 'images/icon/10.png', 'url' => '/pages/exam/my/index', 'desc' => '巩固错题，轻轻松松过考'],
					['title' => '我的收藏', 'image' => request()->static() . 'images/icon/9.png', 'url' => '/pages/exam/my/index', 'desc' => '您收藏的题目，都在这里'],
				];
			}else{
				$list = [
					['title' => '我的资料', 'icon' => 'profile', 'iconColor' => 'green', 'url' => '/pages/ucenter/profile/index'],
					['title' => '我的报名', 'icon' => 'edit', 'iconColor' => 'green', 'url' => '/pages/ucenter/enter/index'],
					['title' => '我的记录', 'icon' => 'list', 'iconColor' => 'green', 'url' => '/pages/ucenter/exam/index'],
					['title' => '我的订单', 'icon' => 'shop', 'iconColor' => 'green', 'url' => '/pages/ucenter/order/index'],
					['title' => '邀请推广', 'icon' => 'qrcode', 'iconColor' => 'green', 'url' => '/pages/ucenter/invite/index'],
					['title' => '关于我们', 'icon' => 'info', 'iconColor' => 'green', 'url' => '/pages/ucenter/about/index'],
				];
			}
		}
		

		return $list;
	}
}