Core.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Community\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. # 获取当前用户是否点赞
  7. public function get($uid, $id, $type)
  8. {
  9. $where['uid'] = $uid;
  10. $where['type'] = $type;
  11. $where['type_id'] = $id;
  12. $where['state'] = 1;
  13. $info = Dever::db($this->table)->one($where);
  14. if ($info) {
  15. return true;
  16. } else {
  17. return false;
  18. }
  19. }
  20. # 获取当前用户的数据列表
  21. public function getList($uid)
  22. {
  23. $where['uid'] = $uid;
  24. $info = Dever::db($this->table)->getAll($where);
  25. return $info;
  26. }
  27. # 获取当前的点赞名单
  28. public function getData($id, $type, $collection_id)
  29. {
  30. $where['type'] = $type;
  31. $where['type_id'] = $id;
  32. $info = Dever::db($this->table)->getHot($where);
  33. $result = array();
  34. $result['user'] = array();
  35. $result['total'] = 0;
  36. if ($info) {
  37. foreach ($info as $k => $v) {
  38. $user = Dever::load('user/lib/info')->get($v['uid'], $collection_id, true);
  39. $result['user']['user_' . $v['uid']] = array
  40. (
  41. 'id' => $v['uid'],
  42. 'username' => $user['username'],
  43. 'author' => $user['author'],
  44. 'username_text' => $user['username_text'],
  45. );
  46. }
  47. }
  48. $max = 1;
  49. $total = count($info);
  50. if ($total >= $max) {
  51. $all = Dever::db($this->table)->getTotal($where);
  52. if ($all > $total) {
  53. $result['total'] = $all - $total;
  54. }
  55. }
  56. return $result;
  57. }
  58. # 更新提交数据
  59. public function submit($info_id, $uid, $id, $type, $data = array())
  60. {
  61. if ($this->otable) {
  62. $oinfo = Dever::load($this->otable)->get($uid, $id, $type);
  63. if ($oinfo) {
  64. Dever::alert('已经做过其他操作');
  65. }
  66. }
  67. $where['uid'] = $uid;
  68. $where['type_id'] = $id;
  69. $where['type'] = $type;
  70. $info = Dever::db($this->table)->one($where);
  71. if ($data) {
  72. $where += $data;
  73. }
  74. if (!$info) {
  75. $up = 1;
  76. Dever::db($this->table)->insert($where);
  77. } else {
  78. $up = 2;
  79. Dever::db($this->table)->delete($info['id']);
  80. }
  81. # 更新点赞数
  82. $where = array();
  83. $where['type_id'] = $id;
  84. $where['type'] = $type;
  85. $where['state'] = 1;
  86. $total = Dever::db($this->table)->total($where);
  87. $table = Dever::config('base')->table_name[$type];
  88. $state = Dever::db($table)->update(array('where_id' => $id, 'num_' . $this->name => $total));
  89. if ($up == 1) {
  90. Dever::score($uid, 'submit_' . $this->name, $this->lang, false, false, false, 'collection/info', $info_id);
  91. } else {
  92. Dever::score($uid, 'submit_no_' . $this->name, '取消' . $this->lang, false, false, false, 'collection/info', $info_id);
  93. }
  94. return true;
  95. }
  96. }