<?php
/**
*分词词典
*/
class distAction extends baseAction
{
	/**
	  * @method 查询词库
	  * @http   post
	  * @param  filedArr array  ['di_id', 'di_word'...] [必填]
	  * @param  where string  条件 [必填]
	  * @param  order string  order by ....
	  * @param  limit string  limit 10, 20
	  * @author soul
	  * @copyright 2018/5/5
	  * @return
			成功：['status'=>true, 'data'=>['count'=>0, 'data'=>[]]
			失败：['status'=>false, 'data'=>'xxx', 'code'=>'xxx']
	  */
	function getWords()
	{
		$arr = ['count'=>0, 'data'=>[]];
		if(isset($_POST['where']))
		{
			$MainBase = new MainBase();
			$where = $_POST['where'];
			$res = $MainBase->Get('fc_dict', ['count(*) as count'], $where, true);
			$arr['count'] = (int) $res['data']['count'];
			if($arr['count'] > 0)
			{
				$where .= !empty($_POST['order'])? $_POST['order']: '';
				$where .= !empty($_POST['limit'])? $_POST['limit']: '';
				$res = $MainBase->Get('fc_dict', $_POST['filedArr'], $where);
				$arr['data'] = $res['data'];
			}
		}
		echo json_encode(['status'=>true, 'data'=>$arr]);
	}

	/**
	  * @method 新增词库
	  * @http   post
	  * @param  wordArr  array  ['刹车片', '刹车盘']
	  * @author soul
	  * @copyright 2018/5/5
	  * @return
			成功：['status'=>true, 'data'=>true]
			失败：['status'=>false, 'data'=>'xxx', 'code'=>'xxx']
	  */
	function addWords()
	{
		$MainDist = new MainDist();
		$res = $MainDist->addWords($_POST['wordArr']);
		echo json_encode($res);
	}
	
	/**
	  * @method 编辑词库
	  * @http   post
	  * @param  action  string  del | status1 || status-1
	  * @param  dataArr  array  ['刹车片', '刹车盘']
	  * @param  setBy  string  id || word
	  * @author soul
	  * @copyright 2018/5/5
	  * @return
			成功：['status'=>true, 'data'=>true]
			失败：['status'=>false, 'data'=>'xxx', 'code'=>'xxx']
	  */
	function setWords()
	{
		$MainDist = new MainDist();
		$res = $MainDist->setWords($_POST['action'], $_POST['dataArr'], $_POST['setBy']);
		echo json_encode($res);
	}
	

	/**
	  * @method 获取最新的私有词典
	  * @http   get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @author soul
	  * @copyright 2018/5/5
	  * @return {"status":true,"data":string,"code":0}
	  */
	function getLastDist()
	{
		$MainDist = new MainDist();
		$res = $MainDist->getLastDist();
		echo json_encode($res);
	}

	/**
	  * @method 重置自动词典
	  * @http   get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @author soul
	  * @copyright 2018/5/5
	  * @return {"status":true,"data":string,"code":0}
	  */
	function resetAutoWord()
	{
		$MainDist = new MainDist();
		$res = $MainDist->resetAutoWord();
		echo json_encode($res);
	}
}