Share.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Share
  5. {
  6. # 获取某个用户在某个图文的分享回流数
  7. public function getRefluxNum($uid, $id, $type)
  8. {
  9. $where['source_uid'] = $uid;
  10. $where['type'] = $type;
  11. $where['data_id'] = $id;
  12. return Dever::db('act/share_reflux')->total($where);
  13. }
  14. # 提交分享
  15. public function submit($uid, $id, $type)
  16. {
  17. $where['uid'] = $uid;
  18. $where['data_id'] = $id;
  19. $where['type'] = $type;
  20. $info = Dever::db('act/share')->one($where);
  21. if (!$info) {
  22. $where['num'] = 1;
  23. Dever::db('act/share')->insert($where);
  24. } else {
  25. $where['num'] = $info['num'] + 1;
  26. $where['where_id'] = $info['id'];
  27. Dever::db('act/share')->update($where);
  28. }
  29. Dever::score($uid, 'share_friend', '邀请好友');
  30. return true;
  31. }
  32. # 回流
  33. public function submit_reflux($source_uid, $uid, $id, $type, $system = 1)
  34. {
  35. if ($source_uid == $uid) {
  36. return false;
  37. }
  38. $where['uid'] = $source_uid;
  39. //$where['uid'] = $uid;
  40. $where['data_id'] = $id;
  41. $where['type'] = $type;
  42. $share = Dever::db('act/share')->one($where);
  43. if ($share) {
  44. $where = array();
  45. $user = Dever::db('passport/user')->one($uid);
  46. $where['user_type'] = 3;
  47. //if ($user['temp'] == 2 || $user['bind'] == 1) {
  48. if ($user) {
  49. # 必须是已经绑定手机号或者授权用户才可以增加积分
  50. # 新用户 增加邀请关系
  51. if (Dever::project('invite')) {
  52. $parent = Dever::load('invite/api')->getParent($uid, $level = 1);
  53. if (!$parent) {
  54. # 新用户
  55. $where['user_type'] = 1;
  56. Dever::load('invite/api')->setRelation($uid, $source_uid);
  57. } else {
  58. # 老用户
  59. $where['user_type'] = 2;
  60. }
  61. }
  62. if ($type <= 4) {
  63. $method = '';
  64. $name = Dever::config('base')->type[$type];
  65. if ($type == 1) {
  66. $method = 'article';
  67. }
  68. if ($type == 2) {
  69. $method = 'vod';
  70. }
  71. if ($type == 3) {
  72. $method = 'live';
  73. }
  74. if ($type == 4) {
  75. $method = 'journal';
  76. }
  77. # 增加积分
  78. if ($where['user_type'] == 1) {
  79. $score = 0;
  80. if ($type == 4) {
  81. $active = Dever::db('journal/active')->one(array('id' => $id));
  82. /*
  83. if ($active && $active['status'] == 1 && time() <= $active['end']) {
  84. $score = $active['invite_score'];
  85. }
  86. */
  87. if ($active) {
  88. $score = $active['invite_score'];
  89. }
  90. }
  91. Dever::score($source_uid, 'share_'.$method.'_new_reflux', '通过'.$name.'邀请到新用户', 'act/lib/score.submit?method=share&type='.$type.'&id=' . $id, $score);
  92. # 插入到邀请列表里
  93. Dever::load('act/lib/invite')->submit($source_uid, $uid, $id, $type);
  94. # 小刊订阅
  95. if ($type == 4) {
  96. if (isset($active) && $active) {
  97. $num = $active['invite_num'];
  98. $invite_num = Dever::load('act/lib/invite')->getTotal($source_uid, $id, $type);
  99. if ($invite_num >= $num) {
  100. # 发消息
  101. if ($invite_num == $num) {
  102. $journal = Dever::db('journal/info')->one($id);
  103. if (Dever::project('message')) {
  104. Dever::load('message/lib/data')->push(-1, $source_uid, '活动提醒', '邀请人数已达'.$invite_num.'人,您获得了 '.$journal['name'].' 的阅读资格!', 11, $journal['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  105. }
  106. # 发送模板消息 这里没有formid 暂时先不发送模板消息,后续应该通过前端收集formid就好了
  107. # 发短信
  108. /*
  109. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $system == 1) {
  110. $send = array();
  111. $send['num'] = $invite_num;
  112. $send['name'] = $journal['name'];
  113. Dever::load('sms/api.send', 'share_journal', $user['mobile'], $send);
  114. }
  115. */
  116. }
  117. Dever::load('act/lib/subscribe')->submit($source_uid, $id, 3);
  118. }
  119. }
  120. }
  121. } elseif ($where['user_type'] == 2) {
  122. Dever::score($source_uid, 'share_'.$method.'_reflux', '通过'.$name.'邀请到老用户');
  123. }
  124. }
  125. }
  126. $where['source_uid'] = $source_uid;
  127. $where['uid'] = $uid;
  128. $where['data_id'] = $id;
  129. $where['type'] = $type;
  130. $where['share_id'] = $share['id'];
  131. $info = Dever::db('act/share_reflux')->one($where);
  132. if (!$info) {
  133. Dever::db('act/share_reflux')->insert($where);
  134. return true;
  135. }
  136. }
  137. return false;
  138. }
  139. }