processor.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/10/6
  6. * Time: 下午10:35
  7. */
  8. namespace search;
  9. require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
  10. require_once (BASE_ROOT_PATH . '/helper/message/subscriber.php');
  11. use StatesHelper;
  12. use Log;
  13. use event\IProcessor;
  14. use process_looper;
  15. class processor implements IProcessor
  16. {
  17. const GetRelatedWord = 1;
  18. const SearchReasult = 2;
  19. const MatchPrice = 3;
  20. const PromoteGoods = 4;
  21. const ValidateArea = 20;
  22. public function onStart()
  23. {
  24. }
  25. public function onConnected($bufid,$stream,$host,$port,$args)
  26. {
  27. }
  28. public function onRequest($bufid, $body)
  29. {
  30. if(StatesHelper::fetch_state('init')) {
  31. Log::record("searcher::instance reload data.",Log::DEBUG);
  32. searcher::instance()->init();
  33. }
  34. $body = unserialize($body);
  35. $type = $body['type'];
  36. if($type == self::GetRelatedWord)
  37. {
  38. $words = $body['keyword'];
  39. $result = searcher::instance()->get_word($words);
  40. $data = serialize($result);
  41. }
  42. elseif($type == self::SearchReasult) {
  43. $params = $body['params'];
  44. $result = searcher::instance()->get_result($params);
  45. $data = serialize($result);
  46. }
  47. elseif($type == self::MatchPrice) {
  48. $params = $body['params'];
  49. $result = searcher::instance()->match_price($params);
  50. $data = serialize($result);
  51. }
  52. elseif($type == self::PromoteGoods) {
  53. $params = $body['params'];
  54. $result = searcher::instance()->promote_goods($params);
  55. $data = serialize($result);
  56. }
  57. elseif ($type == self::ValidateArea) {
  58. $params = $body['params'];
  59. $area_id = $params['area_id'];
  60. $result = area_library::instance()->country($area_id);
  61. if($result == false) {
  62. $data = serialize(array('result' => false));
  63. } else {
  64. $result['result'] = true;
  65. $data = serialize($result);
  66. }
  67. }
  68. else {
  69. ob_clean();
  70. return false;
  71. }
  72. process_looper::instance()->write($bufid,$data);
  73. return true;
  74. }
  75. public function onClose($bufid)
  76. {
  77. }
  78. }