with("user") ->where([ "comment.massager_id" => $m_id, "comment.status" => \E_BASE_STATUS::Normal ]) ->order("id", "desc") ->page($page) ->paginate($size); } public function fetchByUserId($u_id, $page, $size) { return $this ->with("massager") ->where([ "comment.user_id" => $u_id, "comment.status" => \E_BASE_STATUS::Normal ]) ->order("id", "desc") ->page($page) ->paginate($size); } public function user() { return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function massager() { return $this->belongsTo('app\admin\model\Massager', 'massager_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function fetchByMassagerIdAndNegative($m_id, $negative = null, $page = 1, $size = 10) { $query = $this ->with("user") ->where([ "massager_id" => $m_id, ]); if (null !== $negative) $query->where("negative", $negative); return $query->order("updatetime", "desc") ->page($page) ->paginate($size); } public function fetchNegativeCommentByMassager($m_id, $year, $month) { $last_day = date("t", strtotime("$year-$month-01 00:00:00")); return $this->where([ "massager_id" => $m_id, "negative" => 1, ])->where("createtime", "BETWEEN", [strtotime("$year-$month-01 00:00:00"), strtotime("$year-$month-$last_day 00:00:00")]) ->select(); } public function fetchPraiseCommentByMassager($m_id, $year, $month) { $last_day = date("t", strtotime("$year-$month-01 00:00:00")); return $this->where([ "massager_id" => $m_id, "negative" => 0, ])->where("createtime", "BETWEEN", [strtotime("$year-$month-01 00:00:00"), strtotime("$year-$month-$last_day 00:00:00")]) ->select(); } }