Like.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Like
  5. {
  6. private $table = 'act/like';
  7. # 获取当前用户是否点赞
  8. public function get($uid, $id, $type)
  9. {
  10. $where['uid'] = $uid;
  11. $where['type'] = $type;
  12. $where['data_id'] = $id;
  13. $where['state'] = 1;
  14. $info = Dever::db($this->table)->one($where);
  15. if ($info) {
  16. return 1;
  17. } else {
  18. return 2;
  19. }
  20. }
  21. # 获取当前用户的点赞列表
  22. public function getList($uid)
  23. {
  24. $where['uid'] = $uid;
  25. //$where['type'] = '1,2,3,6';
  26. $info = Dever::db($this->table)->getAll($where);
  27. return $info;
  28. }
  29. # 点赞
  30. public function submit($uid, $id, $type)
  31. {
  32. $where['uid'] = $uid;
  33. $where['data_id'] = $id;
  34. $where['type'] = $type;
  35. $info = Dever::db($this->table)->one($where);
  36. if (!$info) {
  37. Dever::db($this->table)->insert($where);
  38. } else {
  39. if ($info['state'] == 1) {
  40. Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 2));
  41. } else {
  42. Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 1));
  43. }
  44. }
  45. # 更新点赞数
  46. if (isset(Dever::config('base')->type_table[$type])) {
  47. $where = array();
  48. $where['data_id'] = $id;
  49. $where['type'] = $type;
  50. $where['state'] = 1;
  51. $total = Dever::db($this->table)->total($where);
  52. $table = Dever::config('base')->type_table[$type];
  53. Dever::db($table)->update(array('where_id' => $id, 'num_up' => $total));
  54. Dever::score($uid, 'submit_' . $this->table, $this->name);
  55. }
  56. return true;
  57. }
  58. }