relation_helper.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. if(!relation\mem_relation::use_frineds_relation) {
  18. $relation = new relation\mem_relation($member_id);
  19. $relation->pass_subscribe();
  20. }
  21. }
  22. catch (Exception $ex)
  23. {
  24. Log::record("{$ex->getMessage()} member_id = {$member_id}",Log::ERR);
  25. }
  26. }
  27. static public function onRegister($user)
  28. {
  29. try
  30. {
  31. if(!relation\mem_relation::use_frineds_relation) {
  32. $relation = new relation\mem_relation($user);
  33. $relation->pass_subscribe();
  34. }
  35. }
  36. catch (Exception $ex)
  37. {
  38. Log::record("{$ex->getMessage()} member_id = {$user}",Log::ERR);
  39. }
  40. }
  41. static public function onUpContacts($member_id,$contacts)
  42. {
  43. try
  44. {
  45. $relation = new relation\mem_relation($member_id);
  46. $relation->subscribe_contacts($contacts);
  47. }
  48. catch (Exception $ex)
  49. {
  50. Log::record("{$ex->getMessage()} member_id = {$member_id}",Log::ERR);
  51. }
  52. }
  53. static public function onInvite($me_id,$user_id)
  54. {
  55. try
  56. {
  57. if($me_id == $user_id) {
  58. return false;
  59. }
  60. $relation = new relation\mem_relation($me_id);
  61. return $relation->invite($user_id);
  62. }
  63. catch (Exception $ex)
  64. {
  65. Log::record("onInvite: {$ex->getMessage()} param = {$me_id},{$user_id}",Log::ERR);
  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. Log::record("onInvite: {$ex->getMessage()} param = {$me_id},{$someone_id}");
  84. return false;
  85. }
  86. }
  87. static public function onSubscribe($me_id,$someone_id)
  88. {
  89. try
  90. {
  91. $me_id = intval($me_id);
  92. $someone_id = intval($someone_id);
  93. if($me_id == $someone_id) {
  94. return false;
  95. }
  96. $relation = new relation\mem_relation($me_id);
  97. $ret = $relation->subscribe($someone_id);
  98. if($ret == true)
  99. {
  100. $someone_relation = new relation\mem_relation($someone_id);
  101. $someone_relation->pass_subscribe();
  102. $publisher = new message\publisher();
  103. $publisher->add_follow($someone_id,[$me_id]);
  104. $minfo = new member_info($me_id);
  105. push_helper::notice_subscribe($someone_id,$minfo);
  106. }
  107. return $ret;
  108. }
  109. catch (Exception $ex)
  110. {
  111. Log::record("onInvite: {$ex->getMessage()} param = {$me_id},{$someone_id}",Log::ERR);
  112. return false;
  113. }
  114. }
  115. static public function onAccept($me_id,$someone_id)
  116. {
  117. try
  118. {
  119. $relation = new relation\mem_relation($me_id);
  120. return $relation->pass_onesub($someone_id);
  121. }
  122. catch (Exception $ex) {
  123. Log::record("onAccept: {$ex->getMessage()} param = {$me_id},{$someone_id}",Log::ERR);
  124. return false;
  125. }
  126. }
  127. static public function onUnSubscribe($me_id,$someone_id)
  128. {
  129. try
  130. {
  131. if($me_id == $someone_id) {
  132. return false;
  133. }
  134. $relation = new relation\mem_relation($me_id);
  135. $ret = $relation->unsubscribe($someone_id);
  136. if($ret == true) {
  137. $publisher = new message\publisher();
  138. $publisher->del_follow($someone_id,[$me_id]);
  139. }
  140. return $ret;
  141. }
  142. catch (Exception $ex)
  143. {
  144. $msg = $ex->getMessage();
  145. Log::record("onInvite: {$msg} param = {$me_id},{$someone_id}");
  146. return false;
  147. }
  148. }
  149. //关注我的
  150. static public function subscriber($member_id)
  151. {
  152. try
  153. {
  154. $relation = new relation\mem_relation($member_id);
  155. return $relation->subscriber();
  156. }
  157. catch (Exception $ex)
  158. {
  159. $msg = $ex->getMessage();
  160. Log::record("{$msg} member_id = {$member_id}");
  161. return array();
  162. }
  163. }
  164. static public function follower($member_id)
  165. {
  166. try
  167. {
  168. $relation = new relation\mem_relation($member_id);
  169. return $relation->follower();
  170. }
  171. catch (Exception $ex)
  172. {
  173. $msg = $ex->getMessage();
  174. Log::record("{$msg} member_id = {$member_id}");
  175. return [];
  176. }
  177. }
  178. static public function friends($member_id)
  179. {
  180. try
  181. {
  182. $relation = new relation\mem_relation($member_id);
  183. $subscriber = $relation->subscriber();
  184. $follower = $relation->follower();
  185. return array_merge($subscriber,$follower);
  186. }
  187. catch (Exception $ex)
  188. {
  189. $msg = $ex->getMessage();
  190. Log::record("{$msg} member_id = {$member_id}");
  191. return [];
  192. }
  193. }
  194. static public function is_follow($me,$other)
  195. {
  196. try
  197. {
  198. $relation = new relation\mem_relation($me);
  199. return $relation->is_follower($other);
  200. }
  201. catch (Exception $ex)
  202. {
  203. $msg = $ex->getMessage();
  204. Log::record("is_follow {$msg} member_id = {$me}");
  205. return false;
  206. }
  207. }
  208. static public function is_friends($left,$right)
  209. {
  210. try{
  211. $l = new relation\mem_relation($left);
  212. $r = new relation\mem_relation($right);
  213. return $l->is_friends($right) && $r->is_friends($left);
  214. }
  215. catch (Exception $ex)
  216. {
  217. Log::record(__METHOD__ . " {$ex->getMessage()}",Log::ERR);
  218. return false;
  219. }
  220. }
  221. }