Comment.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\api\model\massager;
  3. use app\api\model\BaseModel;
  4. class Comment extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'massager_comment';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. /**
  15. * @param $m_id
  16. * @param $page
  17. * @param $size
  18. * @return \think\Paginator
  19. * @throws \think\exception\DbException
  20. */
  21. public function fetchByMassagerId($m_id, $page, $size)
  22. {
  23. return $this
  24. ->with("user")
  25. ->where([
  26. "comment.massager_id" => $m_id,
  27. "comment.status" => \E_BASE_STATUS::Normal
  28. ])
  29. ->order("id", "desc")
  30. ->page($page)
  31. ->paginate($size);
  32. }
  33. public function fetchByUserId($u_id, $page, $size)
  34. {
  35. return $this
  36. ->with("massager")
  37. ->where([
  38. "comment.user_id" => $u_id,
  39. "comment.status" => \E_BASE_STATUS::Normal
  40. ])
  41. ->order("id", "desc")
  42. ->page($page)
  43. ->paginate($size);
  44. }
  45. public function user()
  46. {
  47. return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  48. }
  49. public function massager()
  50. {
  51. return $this->belongsTo('app\admin\model\Massager', 'massager_id', 'id', [], 'LEFT')->setEagerlyType(0);
  52. }
  53. public function fetchByMassagerIdAndNegative($m_id, $negative = null, $page = 1, $size = 10)
  54. {
  55. $query = $this
  56. ->with("user")
  57. ->where([
  58. "massager_id" => $m_id,
  59. ]);
  60. if (null !== $negative)
  61. $query->where("negative", $negative);
  62. return $query->order("updatetime", "desc")
  63. ->page($page)
  64. ->paginate($size);
  65. }
  66. public function fetchNegativeCommentByMassager($m_id, $year, $month)
  67. {
  68. $last_day = date("t", strtotime("$year-$month-01 00:00:00"));
  69. return $this->where([
  70. "massager_id" => $m_id,
  71. "negative" => 1,
  72. ])->where("createtime", "BETWEEN", [strtotime("$year-$month-01 00:00:00"), strtotime("$year-$month-$last_day 00:00:00")])
  73. ->select();
  74. }
  75. public function fetchPraiseCommentByMassager($m_id, $year, $month)
  76. {
  77. $last_day = date("t", strtotime("$year-$month-01 00:00:00"));
  78. return $this->where([
  79. "massager_id" => $m_id,
  80. "negative" => 0,
  81. ])->where("createtime", "BETWEEN", [strtotime("$year-$month-01 00:00:00"), strtotime("$year-$month-$last_day 00:00:00")])
  82. ->select();
  83. }
  84. }