| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\api\model\massager;
- use app\api\model\BaseModel;
- class Comment extends BaseModel
- {
- // 表名
- protected $name = 'massager_comment';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- /**
- * @param $m_id
- * @param $page
- * @param $size
- * @return \think\Paginator
- * @throws \think\exception\DbException
- */
- public function fetchByMassagerId($m_id, $page, $size)
- {
- return $this
- ->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();
- }
- }
|