Subscribe.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Subscribe
  5. {
  6. # 获取小刊订阅列表
  7. public function get($id, $type = 4)
  8. {
  9. $where['type'] = $type;
  10. $where['data_id'] = $id;
  11. $data = Dever::db('act/subscribe')->getAll($where);
  12. if ($data) {
  13. foreach ($data as $k => $v) {
  14. $user = Dever::load('passport/api')->info($v['uid']);
  15. $data[$k]['username'] = $user['username'];
  16. $data[$k]['avatar'] = $user['avatar'];
  17. }
  18. }
  19. return $data;
  20. }
  21. # 订阅
  22. public function submit($uid, $id, $type = 4)
  23. {
  24. $where['uid'] = $uid;
  25. $where['data_id'] = $id;
  26. $where['type'] = $type;
  27. $table = 'act/subscribe';
  28. $info = Dever::db($table)->one($where);
  29. if (!$info) {
  30. Dever::db($table)->insert($where);
  31. }
  32. # 更新订阅数
  33. $where = array();
  34. $where['data_id'] = $id;
  35. $where['type'] = $type;
  36. $where['state'] = 1;
  37. $total = Dever::db($table)->total($where);
  38. $table = Dever::config('base')->type_table[$type];
  39. Dever::db($table)->update(array('where_id' => $id, 'num_ding' => $total));
  40. return true;
  41. }
  42. }