Share.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. if ($active && $active['status'] == 1 && time() <= $active['end']) {
  83. $score = $active['invite_score'];
  84. }
  85. }
  86. Dever::score($source_uid, 'share_'.$method.'_new_reflux', '通过'.$name.'邀请到新用户', 'act/lib/score.submit?method=share&type='.$type.'&id=' . $id, $score);
  87. # 插入到邀请列表里
  88. Dever::load('act/lib/invite')->submit($source_uid, $uid, $id, $type);
  89. # 小刊订阅
  90. if ($type == 4) {
  91. if (isset($active) && $active) {
  92. $num = $active['invite_num'];
  93. $invite_num = Dever::load('act/lib/invite')->getTotal($source_uid, $id, $type);
  94. if ($invite_num >= $num) {
  95. # 发消息
  96. if ($invite_num == $num) {
  97. $journal = Dever::db('journal/info')->one($id);
  98. if (Dever::project('message')) {
  99. Dever::load('message/lib/data')->push(-1, $source_uid, '活动提醒', '邀请人数已达'.$invite_num.'人,您获得了 '.$journal['name'].' 的阅读资格!', 11);
  100. }
  101. # 发送模板消息 这里没有formid 暂时先不发送模板消息,后续应该通过前端收集formid就好了
  102. # 发短信
  103. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $system == 1) {
  104. $send = array();
  105. $send['num'] = $invite_num;
  106. $send['name'] = $journal['name'];
  107. Dever::load('sms/api.send', 'share_journal', $user['mobile'], $send);
  108. }
  109. }
  110. Dever::load('act/lib/subscribe')->submit($source_uid, $id, 3);
  111. }
  112. }
  113. }
  114. } elseif ($where['user_type'] == 2) {
  115. Dever::score($source_uid, 'share_'.$method.'_reflux', '通过'.$name.'邀请到老用户');
  116. }
  117. }
  118. }
  119. $where['source_uid'] = $source_uid;
  120. $where['uid'] = $uid;
  121. $where['data_id'] = $id;
  122. $where['type'] = $type;
  123. $where['share_id'] = $share['id'];
  124. $info = Dever::db('act/share_reflux')->one($where);
  125. if (!$info) {
  126. Dever::db('act/share_reflux')->insert($where);
  127. return true;
  128. }
  129. }
  130. return false;
  131. }
  132. }