Share.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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)
  34. {
  35. $where['source_uid'] = $source_uid;
  36. $where['uid'] = $uid;
  37. if ($where['source_uid'] == $where['uid']) {
  38. //return false;
  39. }
  40. $where['data_id'] = $id;
  41. $where['type'] = $type;
  42. $share = Dever::db('act/share')->one($where);
  43. if ($share) {
  44. $user = Dever::db('passport/user')->one($uid);
  45. $where['user_type'] = 3;
  46. //if ($user['temp'] == 2 || $user['bind'] == 1) {
  47. if ($user) {
  48. # 必须是已经绑定手机号或者授权用户才可以增加积分
  49. # 新用户 增加邀请关系
  50. if (Dever::project('invite')) {
  51. $parent = Dever::load('invite/api')->getParent($uid, $level = 1);
  52. if (!$parent) {
  53. # 新用户
  54. $where['user_type'] = 1;
  55. Dever::load('invite/api')->setRelation($uid, $source_uid);
  56. } else {
  57. # 老用户
  58. $where['user_type'] = 2;
  59. }
  60. }
  61. if ($type <= 4) {
  62. $method = '';
  63. $name = Dever::config('base')->type[$type];
  64. if ($type == 1) {
  65. $method = 'article';
  66. }
  67. if ($type == 2) {
  68. $method = 'vod';
  69. }
  70. if ($type == 3) {
  71. $method = 'live';
  72. }
  73. if ($type == 4) {
  74. $method = 'journal';
  75. }
  76. # 增加积分
  77. if ($where['user_type'] == 1) {
  78. $score = 0;
  79. if ($type == 4) {
  80. $active = Dever::db('journal/active')->one(array('id' => $id));
  81. if ($active && $active['status'] == 1 && time() <= $active['end']) {
  82. $score = $active['invite_score'];
  83. }
  84. }
  85. Dever::score($source_uid, 'share_'.$method.'_new_reflux', '通过'.$name.'邀请到新用户', 'act/lib/score.submit?method=share&type='.$type.'&id=' . $id, $score);
  86. # 插入到邀请列表里
  87. Dever::load('act/lib/invite')->submit($source_uid, $uid, $id, $type);
  88. # 小刊订阅
  89. if ($type == 4) {
  90. if (isset($active) && $active) {
  91. $num = $active['invite_num'];
  92. $invite_num = Dever::load('act/lib/invite')->getTotal($source_uid, $id, $type);
  93. if ($invite_num >= $num) {
  94. # 发消息
  95. if ($invite_num == $num) {
  96. $journal = Dever::db('journal/info')->one($id);
  97. Dever::load('message/lib/data')->push(-1, $source_uid, '活动提醒', '邀请人数已达'.$invite_num.'人,您获得了 '.$journal['name'].' 的阅读资格!', 1);
  98. # 发送模板消息
  99. # 发短信
  100. }
  101. Dever::load('act/lib/subscribe')->submit($source_uid, $id, 3);
  102. }
  103. }
  104. }
  105. } elseif ($where['user_type'] == 2) {
  106. Dever::score($source_uid, 'share_'.$method.'_reflux', '通过'.$name.'邀请到老用户');
  107. }
  108. }
  109. }
  110. $where['share_id'] = $share['id'];
  111. $info = Dever::db('act/share_reflux')->one($where);
  112. if (!$info) {
  113. Dever::db('act/share_reflux')->insert($where);
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. }