UserComment.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. class UserComment extends Model{
  5. protected $createTime = "inputtime";
  6. protected $updateTime = '';
  7. protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
  8. public function initialize(){
  9. parent::initialize();
  10. }
  11. public function getInfo($user, $type, $page = 0){
  12. return $this->db()
  13. ->alias("c")
  14. ->field("c.comment_id s, c.inputtime t, c.content c, u.nickname n")
  15. ->join("gd_user u", "u.id = c.comment_id", "LEFT")
  16. ->where(['c.user_id'=>$user, "c.type"=>$type])
  17. ->page($page, config('paginate.list_rows'))
  18. ->order("inputtime DESC")
  19. ->select();
  20. }
  21. public function getInfoByComment($user, $comment, $type, $page = 0){
  22. return $this->db()
  23. ->alias("c")
  24. ->field("c.comment_id s, c.inputtime t, c.user_id u,c.content c, u.nickname n")
  25. ->join("gd_user u", "u.id = c.comment_id", "LEFT")
  26. ->where(['c.user_id'=>[['eq', $user], ['eq', $comment], 'or']])
  27. ->where(['c.comment_id'=>[['eq', $user], ['eq', $comment], 'or']])
  28. ->where(["c.type"=>$type])
  29. ->page($page, config('paginate.list_rows'))
  30. ->order("inputtime DESC")
  31. ->select();
  32. }
  33. public function add($data){
  34. return $this->save($data);
  35. }
  36. }