Core.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. Dever::db($this->table)->insert($where);
  45. } else {
  46. if ($info['state'] == 1) {
  47. Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 2));
  48. } else {
  49. Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 1));
  50. }
  51. }
  52. # 更新点赞数
  53. $where = array();
  54. $where['type_id'] = $id;
  55. $where['type'] = $type;
  56. $where['state'] = 1;
  57. $total = Dever::db($this->table)->total($where);
  58. $table = Dever::config('base')->table_name[$type];
  59. $state = Dever::db($table)->update(array('where_id' => $id, 'num_' . $this->name => $total));
  60. Dever::score($uid, 'submit_' . $this->name, $this->lang);
  61. return true;
  62. }
  63. }