Subscribe.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. # 获取小刊订阅列表
  21. public function getList($id, $type = 4)
  22. {
  23. $where['type'] = $type;
  24. $where['data_id'] = $id;
  25. $where['avatar'] = 'null';
  26. $data = Dever::db('act/subscribe')->getAll($where);
  27. /*
  28. if ($data) {
  29. foreach ($data as $k => $v) {
  30. $user = Dever::load('passport/api')->info($v['uid']);
  31. $data[$k]['username'] = $user['username'];
  32. $data[$k]['avatar'] = $user['avatar'];
  33. }
  34. }
  35. */
  36. return $data;
  37. }
  38. # 订阅
  39. public function submit($uid, $id, $source = 1, $type = 4)
  40. {
  41. $where['uid'] = $uid;
  42. $where['data_id'] = $id;
  43. $where['type'] = $type;
  44. $table = 'act/subscribe';
  45. $info = Dever::db($table)->one($where);
  46. if (!$info) {
  47. $where['source'] = $source;
  48. Dever::db($table)->insert($where);
  49. }
  50. # 更新订阅数
  51. $where = array();
  52. $where['data_id'] = $id;
  53. $where['type'] = $type;
  54. $where['state'] = 1;
  55. $total = Dever::db($table)->total($where);
  56. $table = Dever::config('base')->type_table[$type];
  57. Dever::db($table)->update(array('where_id' => $id, 'num_ding' => $total));
  58. return true;
  59. }
  60. }