UserComment.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. ->where("c.user_id != c.comment_id")
  30. ->page($page, config('paginate.list_rows'))
  31. ->order("inputtime DESC")
  32. ->select();
  33. }
  34. public function add($data){
  35. return $this->save($data);
  36. }
  37. }