Record.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace addon\notes\api\controller;
  3. use app\api\controller\BaseApi;
  4. use addon\notes\model\Record as RecordModel;
  5. /**
  6. * 文章点赞
  7. * @author Administrator
  8. *
  9. */
  10. class Record extends BaseApi
  11. {
  12. /**
  13. * 添加点赞
  14. */
  15. public function add()
  16. {
  17. $token = $this->checkToken();
  18. if ($token['code'] < 0) return $this->response($token);
  19. $note_id = isset($this->params['note_id']) ? $this->params['note_id'] : 0;
  20. if (empty($note_id)) {
  21. return $this->response($this->error('', 'REQUEST_NOTE_ID'));
  22. }
  23. $record_model = new RecordModel();
  24. $data = [
  25. 'member_id' => $token['data']['member_id'],
  26. 'note_id' => $note_id
  27. ];
  28. $res = $record_model->addRecord($data);
  29. return $this->response($res);
  30. }
  31. /**
  32. * 删除点赞
  33. */
  34. public function delete()
  35. {
  36. $token = $this->checkToken();
  37. if ($token['code'] < 0) return $this->response($token);
  38. $note_id = isset($this->params['note_id']) ? $this->params['note_id'] : 0;
  39. if (empty($note_id)) {
  40. return $this->response($this->error('', 'REQUEST_NOTE_ID'));
  41. }
  42. $record_model = new RecordModel();
  43. $res = $record_model->deleteRecord($token['data']['member_id'], $note_id);
  44. return $this->response($res);
  45. }
  46. /**
  47. * 是否点赞
  48. * @return string
  49. */
  50. public function isDianzan()
  51. {
  52. $token = $this->checkToken();
  53. if ($token['code'] < 0) return $this->response($token);
  54. $note_id = isset($this->params['note_id']) ? $this->params['note_id'] : 0;
  55. if (empty($note_id)) {
  56. return $this->response($this->error('', 'REQUEST_NOTE_ID'));
  57. }
  58. $record_model = new RecordModel();
  59. $res = $record_model->getIsDianzan($note_id, $token['data']['member_id']);
  60. return $this->response($res);
  61. }
  62. }