Like.php 1.5 KB

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