Like.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $where['type'] = '1,2,3,6';
  25. $info = Dever::db('act/like')->getAll($where);
  26. return $info;
  27. }
  28. # 点赞+喜欢
  29. public function submit($uid, $id, $type)
  30. {
  31. $where['uid'] = $uid;
  32. $where['data_id'] = $id;
  33. $where['type'] = $type;
  34. $info = Dever::db('act/like')->one($where);
  35. if (!$info) {
  36. Dever::db('act/like')->insert($where);
  37. } else {
  38. if ($info['state'] == 1) {
  39. Dever::db('act/like')->update(array('where_id' => $info['id'], 'state' => 2));
  40. } else {
  41. Dever::db('act/like')->update(array('where_id' => $info['id'], 'state' => 1));
  42. }
  43. }
  44. # 更新点赞数
  45. $where = array();
  46. $where['data_id'] = $id;
  47. $where['type'] = $type;
  48. $where['state'] = 1;
  49. $total = Dever::db('act/like')->total($where);
  50. $table = Dever::config('base')->type_table[$type];
  51. Dever::db($table)->update(array('where_id' => $id, 'num_up' => $total));
  52. Dever::score($uid, 'submit_like', '喜欢');
  53. return true;
  54. }
  55. }