Record.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\notes\model;
  11. use app\model\BaseModel;
  12. /**
  13. * 笔记点赞记录
  14. */
  15. class Record extends BaseModel
  16. {
  17. /**
  18. * 添加点赞记录
  19. * @param $data
  20. * @return array
  21. */
  22. public function addRecord($data)
  23. {
  24. $info = model('notes_dianzan_record')->getInfo([['member_id', '=', $data['member_id']], ['note_id', '=', $data['note_id']]], 'record_id');
  25. if (empty($info)) {
  26. $res = model('notes_dianzan_record')->add($data);
  27. if ($res) {
  28. model("notes")->setInc([['note_id', '=', $data['note_id']]], 'dianzan_num', 1);
  29. }
  30. return $this->success($res);
  31. } else {
  32. return $this->error();
  33. }
  34. }
  35. /**
  36. * 取消点赞
  37. * @param $member_id
  38. * @param $note_id
  39. * @return array
  40. */
  41. public function deleteRecord($member_id, $note_id)
  42. {
  43. $res = model('notes_dianzan_record')->delete([['member_id', '=', $member_id], ['note_id', '=', $note_id]]);
  44. if ($res) {
  45. model("notes")->setDec([['note_id', '=', $note_id]], 'dianzan_num', 1);
  46. }
  47. return $this->success($res);
  48. }
  49. /**
  50. * 检测商品是否收藏
  51. * @param $note_id
  52. * @param $member_id
  53. * @return array
  54. */
  55. public function getIsDianzan($note_id, $member_id)
  56. {
  57. $count = model('notes_dianzan_record')->getCount([['member_id', '=', $member_id], ['note_id', '=', $note_id]]);
  58. return $this->success($count);
  59. }
  60. }