12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2016/10/6
- * Time: 下午10:35
- */
- namespace search;
- require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
- require_once (BASE_ROOT_PATH . '/helper/message/subscriber.php');
- use StatesHelper;
- use Log;
- use event\IProcessor;
- use process_looper;
- class processor implements IProcessor
- {
- const GetRelatedWord = 1;
- const SearchReasult = 2;
- const MatchPrice = 3;
- const PromoteGoods = 4;
- const ValidateArea = 20;
- public function onStart()
- {
- }
- public function onConnected($bufid,$stream,$host,$port,$args)
- {
- }
- public function onRequest($bufid, $body)
- {
- if(StatesHelper::fetch_state('init')) {
- Log::record("searcher::instance reload data.",Log::DEBUG);
- searcher::instance()->init();
- }
- $body = unserialize($body);
- $type = $body['type'];
- if($type == self::GetRelatedWord)
- {
- $words = $body['keyword'];
- $result = searcher::instance()->get_word($words);
- $data = serialize($result);
- }
- elseif($type == self::SearchReasult) {
- $params = $body['params'];
- $result = searcher::instance()->get_result($params);
- $data = serialize($result);
- }
- elseif($type == self::MatchPrice) {
- $params = $body['params'];
- $result = searcher::instance()->match_price($params);
- $data = serialize($result);
- }
- elseif($type == self::PromoteGoods) {
- $params = $body['params'];
- $result = searcher::instance()->promote_goods($params);
- $data = serialize($result);
- }
- elseif ($type == self::ValidateArea) {
- $params = $body['params'];
- $area_id = $params['area_id'];
- $result = area_library::instance()->country($area_id);
- if($result == false) {
- $data = serialize(array('result' => false));
- } else {
- $result['result'] = true;
- $data = serialize($result);
- }
- }
- else {
- ob_clean();
- return false;
- }
- process_looper::instance()->write($bufid,$data);
- return true;
- }
- public function onClose($bufid)
- {
- }
- }
|