Subscribe.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Subscribe
  5. {
  6. # 获取小刊是否被人订阅
  7. public function get($id, $uid, $type = 4)
  8. {
  9. $where['uid'] = $uid;
  10. $where['type'] = $type;
  11. $where['data_id'] = $id;
  12. $where['state'] = 1;
  13. $data = Dever::db('act/subscribe')->one($where);
  14. if ($data) {
  15. return 1;
  16. } else {
  17. return 2;
  18. }
  19. }
  20. public function getInfo($id, $uid, $type = 4)
  21. {
  22. $where['uid'] = $uid;
  23. $where['type'] = $type;
  24. $where['data_id'] = $id;
  25. $where['state'] = 1;
  26. $data = Dever::db('act/subscribe')->one($where);
  27. return $data;
  28. }
  29. # 获取小刊订阅列表
  30. public function getList($id, $type = 4)
  31. {
  32. $key = 'subscribe_' . $type . '_' . $id;
  33. //$data = Dever::cache($key);
  34. $data = array();
  35. if (!$data) {
  36. $where['type'] = $type;
  37. $where['data_id'] = $id;
  38. $where['avatar'] = 'null';
  39. $data = Dever::db('act/subscribe')->getAll($where);
  40. if ($data) {
  41. //Dever::cache($key, $data, 900);
  42. }
  43. }
  44. /*
  45. if ($data) {
  46. foreach ($data as $k => $v) {
  47. $user = Dever::load('passport/api')->info($v['uid']);
  48. $data[$k]['username'] = $user['username'];
  49. $data[$k]['avatar'] = $user['avatar'];
  50. }
  51. }
  52. */
  53. return $data;
  54. }
  55. # 订阅
  56. public function submit($uid, $id, $source = 1, $type = 4)
  57. {
  58. $where['uid'] = $uid;
  59. $where['data_id'] = $id;
  60. $where['type'] = $type;
  61. $table = 'act/subscribe';
  62. $info = Dever::db($table)->one($where);
  63. if (!$info) {
  64. $where['source'] = $source;
  65. Dever::db($table)->insert($where);
  66. return true;
  67. }
  68. return false;
  69. # 更新订阅数
  70. $where = array();
  71. $where['data_id'] = $id;
  72. $where['type'] = $type;
  73. $where['state'] = 1;
  74. $total = Dever::db($table)->total($where);
  75. $table = Dever::config('base')->type_table[$type];
  76. Dever::db($table)->update(array('where_id' => $id, 'num_ding' => $total));
  77. return false;
  78. }
  79. }