msgutil.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/2/26
  6. * Time: 下午7:36
  7. */
  8. class MsgStates extends Stackable
  9. {
  10. public function run() {
  11. }
  12. }
  13. class StatesHelper
  14. {
  15. static public function onIndex($states,$msg)
  16. {
  17. $type = $msg['type'];
  18. if($type == 'tags') {
  19. $states['tags'] = true;
  20. }
  21. elseif($type == 'special') {
  22. $states['special'] = true;
  23. }
  24. elseif($type == 'brands') {
  25. $states['brands'] = true;
  26. }
  27. elseif($type == 'fcode') {
  28. $states['fcode'] = true;
  29. }
  30. elseif($type == 'pay_fcode') {
  31. $states['pay_fcode'] = true;
  32. }
  33. elseif($type == 'present_fcode') {
  34. $states['present_fcode'] = true;
  35. }
  36. }
  37. static public function onGoods($states,$msg)
  38. {
  39. $type = $msg['type'];
  40. if($type == 'common_info') {
  41. $states['common_info'] = true;
  42. }
  43. }
  44. static public function onActivity($states,$msg)
  45. {
  46. $type = $msg['type'];
  47. if($type == 'full_sent') {
  48. $states['full_sent'] = true;
  49. }
  50. elseif($type == 'groupbuy') {
  51. $states['groupbuy'] = true;
  52. }
  53. elseif($type == 'limit') {
  54. $states['limit'] = true;
  55. }
  56. elseif($type == 'recommend_goods') {
  57. $states['recommend_goods'] = true;
  58. }
  59. elseif($type == 'bundling') {
  60. $states['bundling'] = true;
  61. }
  62. elseif($type == 'recommend_combo') {
  63. $states['recommend_combo'] = true;
  64. }
  65. elseif($type == 'goods_gift') {
  66. $states['goods_gift'] = true;
  67. }
  68. elseif($type == 'optional_goods') {
  69. $states['optional_goods'] = true;
  70. }
  71. elseif($type == 'goods_sampler') {
  72. $states['goods_sampler'] = true;
  73. }
  74. elseif($type == 'bargain_goods') {
  75. $states['bargain_goods'] = true;
  76. }
  77. }
  78. static public function onSearcher($states,$msg)
  79. {
  80. $type = $msg['type'];
  81. if($type == 'init') {
  82. $states['init'] = true;
  83. }
  84. }
  85. static public function fetch_state($tag)
  86. {
  87. global $gMessageStates;
  88. global $gMessageLock;
  89. if(empty($gMessageLock) || empty($gMessageStates)) {
  90. return true;
  91. }
  92. $finded = false;
  93. Mutex::lock($gMessageLock);
  94. foreach ($gMessageStates as $key => $val)
  95. {
  96. if($key == $tag)
  97. {
  98. $finded = true;
  99. $state = $gMessageStates[$tag];
  100. if($state == true) {
  101. $gMessageStates[$tag] = false;
  102. break;
  103. }
  104. }
  105. }
  106. if($finded == false) {
  107. $gMessageStates[$tag] = false;
  108. $state = true;
  109. }
  110. Mutex::unlock($gMessageLock);
  111. return $state;
  112. }
  113. static public function init()
  114. {
  115. global $gMessageStates;
  116. global $gMessageLock;
  117. Mutex::lock($gMessageLock);
  118. $gMessageStates['tags'] = true;
  119. Mutex::unlock($gMessageLock);
  120. }
  121. }
  122. function handler_redis($redis, $chan, $msg)
  123. {
  124. Log::record("message: {$chan} -- {$msg}",Log::DEBUG);
  125. if (defined('UGC_SUBSCRIBER_PROC') && UGC_SUBSCRIBER_PROC == true)
  126. {
  127. if($chan == 'special') {
  128. UgcHandler::onSpecial($msg);
  129. }
  130. elseif($chan == 'follow') {
  131. UgcHandler::onFellow($msg);
  132. }
  133. elseif ($chan == 'inviter') {
  134. UgcHandler::onInviter($msg);
  135. }
  136. else {
  137. Log::record("message: {$chan} -- {$msg}",Log::DEBUG);
  138. }
  139. }
  140. else
  141. {
  142. $cur_trd = Thread::getCurrentThread();
  143. if(!is_null($cur_trd)) {
  144. $cur_trd->dispatch($chan,$msg);
  145. }
  146. }
  147. }