msgutil.php 4.3 KB

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