Collect.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $where = array();
  47. $where['data_id'] = $id;
  48. $where['type'] = $type;
  49. $where['state'] = 1;
  50. $total = Dever::db($this->table)->total($where);
  51. $table = Dever::config('base')->type_table[$type];
  52. Dever::db($table)->update(array('where_id' => $id, 'num_up' => $total));
  53. Dever::score($uid, 'submit_like', '点赞');
  54. return true;
  55. }
  56. }