Core.php 2.8 KB

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