relation_helper.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/6/23
  6. * Time: 下午4:26
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/relation/mem_relation.php');
  9. require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
  10. require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
  11. class relation_helper
  12. {
  13. static public function onLogin($member_id)
  14. {
  15. try
  16. {
  17. $relation = new relation\mem_relation($member_id);
  18. $relation->pass_subscribe();
  19. }
  20. catch (Exception $ex)
  21. {
  22. $msg = $ex->getMessage();
  23. Log::record("{$msg} member_id = {$member_id}");
  24. }
  25. }
  26. static public function onRegister($user)
  27. {
  28. try
  29. {
  30. $relation = new relation\mem_relation($user);
  31. $relation->pass_subscribe();
  32. }
  33. catch (Exception $ex)
  34. {
  35. $msg = $ex->getMessage();
  36. Log::record("{$msg} member_id = {$user}");
  37. }
  38. }
  39. static public function onUpContacts($member_id,$contacts)
  40. {
  41. try
  42. {
  43. $relation = new relation\mem_relation($member_id);
  44. $relation->subscribe_contacts($contacts);
  45. }
  46. catch (Exception $ex)
  47. {
  48. $msg = $ex->getMessage();
  49. Log::record("{$msg} member_id = {$member_id}");
  50. }
  51. }
  52. static public function onInvite($me_id,$user_id)
  53. {
  54. try
  55. {
  56. if($me_id == $user_id) {
  57. return false;
  58. }
  59. $relation = new relation\mem_relation($me_id);
  60. return $relation->invite($user_id);
  61. }
  62. catch (Exception $ex)
  63. {
  64. $msg = $ex->getMessage();
  65. Log::record("onInvite: {$msg} param = {$me_id},{$user_id}");
  66. return false;
  67. }
  68. }
  69. static public function subscribed($me_id,$someone_id)
  70. {
  71. try
  72. {
  73. $me_id = intval($me_id);
  74. $someone_id = intval($someone_id);
  75. if($me_id == $someone_id) {
  76. return false;
  77. }
  78. $relation = new relation\mem_relation($me_id);
  79. return $relation->is_follower($someone_id);
  80. }
  81. catch (Exception $ex)
  82. {
  83. $msg = $ex->getMessage();
  84. Log::record("onInvite: {$msg} param = {$me_id},{$someone_id}");
  85. return false;
  86. }
  87. }
  88. static public function onSubscribe($me_id,$someone_id)
  89. {
  90. try
  91. {
  92. $me_id = intval($me_id);
  93. $someone_id = intval($someone_id);
  94. if($me_id == $someone_id) {
  95. return false;
  96. }
  97. $relation = new relation\mem_relation($me_id);
  98. $ret = $relation->subscribe($someone_id);
  99. if($ret == true)
  100. {
  101. $someone_relation = new relation\mem_relation($someone_id);
  102. $someone_relation->pass_subscribe();
  103. $publisher = new message\publisher();
  104. $publisher->add_follow($someone_id,[$me_id]);
  105. $minfo = new member_info($me_id);
  106. push_helper::notice_subscribe($someone_id,$minfo);
  107. }
  108. return $ret;
  109. }
  110. catch (Exception $ex)
  111. {
  112. $msg = $ex->getMessage();
  113. Log::record("onInvite: {$msg} param = {$me_id},{$someone_id}");
  114. return false;
  115. }
  116. }
  117. static public function onUnSubscribe($me_id,$someone_id)
  118. {
  119. try
  120. {
  121. if($me_id == $someone_id) {
  122. return false;
  123. }
  124. $relation = new relation\mem_relation($me_id);
  125. $ret = $relation->unsubscribe($someone_id);
  126. if($ret == true) {
  127. $publisher = new message\publisher();
  128. $publisher->del_follow($someone_id,[$me_id]);
  129. }
  130. return $ret;
  131. }
  132. catch (Exception $ex)
  133. {
  134. $msg = $ex->getMessage();
  135. Log::record("onInvite: {$msg} param = {$me_id},{$someone_id}");
  136. return false;
  137. }
  138. }
  139. //关注我的
  140. static public function subscriber($member_id)
  141. {
  142. try
  143. {
  144. $relation = new relation\mem_relation($member_id);
  145. return $relation->subscriber();
  146. }
  147. catch (Exception $ex)
  148. {
  149. $msg = $ex->getMessage();
  150. Log::record("{$msg} member_id = {$member_id}");
  151. return array();
  152. }
  153. }
  154. static public function follower($member_id)
  155. {
  156. try
  157. {
  158. $relation = new relation\mem_relation($member_id);
  159. return $relation->follower();
  160. }
  161. catch (Exception $ex)
  162. {
  163. $msg = $ex->getMessage();
  164. Log::record("{$msg} member_id = {$member_id}");
  165. return [];
  166. }
  167. }
  168. static public function friends($member_id)
  169. {
  170. try
  171. {
  172. $relation = new relation\mem_relation($member_id);
  173. $subscriber = $relation->subscriber();
  174. $follower = $relation->follower();
  175. return array_merge($subscriber,$follower);
  176. }
  177. catch (Exception $ex)
  178. {
  179. $msg = $ex->getMessage();
  180. Log::record("{$msg} member_id = {$member_id}");
  181. return [];
  182. }
  183. }
  184. }