Core.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_' . $user['id']] = array
  40. (
  41. 'id' => $user['id'],
  42. 'username' => $user['username'],
  43. 'author' => $user['author'],
  44. );
  45. }
  46. }
  47. $max = 1;
  48. $total = count($info);
  49. if ($total >= $max) {
  50. $all = Dever::db($this->table)->getTotal($where);
  51. if ($all > $total) {
  52. $result['total'] = $all - $total;
  53. }
  54. }
  55. return $result;
  56. }
  57. # 更新提交数据
  58. public function submit($uid, $id, $type, $data = array())
  59. {
  60. if ($this->otable) {
  61. $oinfo = Dever::load($this->otable)->get($uid, $id, $type);
  62. if ($oinfo) {
  63. Dever::alert('已经做过其他操作');
  64. }
  65. }
  66. $where['uid'] = $uid;
  67. $where['type_id'] = $id;
  68. $where['type'] = $type;
  69. $info = Dever::db($this->table)->one($where);
  70. if ($data) {
  71. $where += $data;
  72. }
  73. if (!$info) {
  74. $up = 1;
  75. Dever::db($this->table)->insert($where);
  76. } else {
  77. $up = 2;
  78. Dever::db($this->table)->delete($info['id']);
  79. }
  80. # 更新点赞数
  81. $where = array();
  82. $where['type_id'] = $id;
  83. $where['type'] = $type;
  84. $where['state'] = 1;
  85. $total = Dever::db($this->table)->total($where);
  86. $table = Dever::config('base')->table_name[$type];
  87. $state = Dever::db($table)->update(array('where_id' => $id, 'num_' . $this->name => $total));
  88. if ($up == 1) {
  89. Dever::score($uid, 'submit_' . $this->name, $this->lang);
  90. } else {
  91. Dever::score($uid, 'submit_no_' . $this->name, '取消' . $this->lang);
  92. }
  93. return true;
  94. }
  95. }