Core.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 submit($uid, $id, $type, $data = array())
  29. {
  30. if ($this->otable) {
  31. $oinfo = Dever::load($this->otable)->get($uid, $id, $type);
  32. if ($oinfo) {
  33. Dever::alert('已经做过其他操作');
  34. }
  35. }
  36. $where['uid'] = $uid;
  37. $where['type_id'] = $id;
  38. $where['type'] = $type;
  39. $info = Dever::db($this->table)->one($where);
  40. if ($data) {
  41. $where += $data;
  42. }
  43. if (!$info) {
  44. $up = 1;
  45. Dever::db($this->table)->insert($where);
  46. } else {
  47. if ($info['state'] == 1) {
  48. $up = 2;
  49. Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 2));
  50. } else {
  51. $up = 1;
  52. Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 1));
  53. }
  54. }
  55. # 更新点赞数
  56. $where = array();
  57. $where['type_id'] = $id;
  58. $where['type'] = $type;
  59. $where['state'] = 1;
  60. $total = Dever::db($this->table)->total($where);
  61. $table = Dever::config('base')->table_name[$type];
  62. $state = Dever::db($table)->update(array('where_id' => $id, 'num_' . $this->name => $total));
  63. if ($up == 1) {
  64. Dever::score($uid, 'submit_' . $this->name, $this->lang);
  65. } else {
  66. Dever::score($uid, 'submit_no_' . $this->name, '取消' . $this->lang);
  67. }
  68. return true;
  69. }
  70. }