You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use App\Common\Token;
  4. class Comment extends BaseModel
  5. {
  6. //评价
  7. protected $table = 'comment';
  8. public $timestamps = false;
  9. /**
  10. * 不能被批量赋值的属性
  11. *
  12. * @var array
  13. */
  14. protected $guarded = [];
  15. const UNSHOW_COMMENT = 0; //评论未批准显示
  16. const SHOW_COMMENT = 1; //评论批准显示
  17. const GOODS_COMMENT_TYPE = 0; //商品评论
  18. const ARTICLE_COMMENT_TYPE = 1; //文章评论
  19. //获取列表
  20. public static function getList(array $param)
  21. {
  22. extract($param); //参数:limit,offset
  23. $where['user_id'] = $user_id;
  24. $where['comment_type'] = $comment_type; //0商品评价,1文章评价
  25. $where['status'] = self::SHOW_COMMENT;
  26. $limit = isset($limit) ? $limit : 10;
  27. $offset = isset($offset) ? $offset : 0;
  28. $model = new Comment;
  29. if(isset($comment_rank)){$where['comment_rank'] = $comment_rank;} //评价分
  30. $model = $model->where($where);
  31. $res['count'] = $model->count();
  32. $res['list'] = array();
  33. if($res['count']>0)
  34. {
  35. $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
  36. }
  37. else
  38. {
  39. return '暂无记录';
  40. }
  41. return $res;
  42. }
  43. public static function getOne($id)
  44. {
  45. return self::where('id', $id)->first()->toArray();
  46. }
  47. public static function add(array $data)
  48. {
  49. if(self::where(array('user_id'=>$data['user_id'],'id_value'=>$data['id_value'],'comment_type'=>$data['comment_type']))->first()){return '亲,您已经评价啦!';}
  50. if ($id = self::insertGetId($data))
  51. {
  52. return true;
  53. }
  54. return false;
  55. }
  56. public static function modify($where, array $data)
  57. {
  58. if (self::where($where)->update($data))
  59. {
  60. return true;
  61. }
  62. return false;
  63. }
  64. //删除一条记录
  65. public static function remove(array $data)
  66. {
  67. if(!self::where(array('user_id'=>$data['user_id'],'comment_type'=>$data['comment_type'],'id_value'=>$data['id_value']))->first()){return '商品尚未评价';}
  68. if (!self::where(array('user_id'=>$data['user_id'],'comment_type'=>$data['comment_type'],'id_value'=>$data['id_value']))->delete())
  69. {
  70. return false;
  71. }
  72. return true;
  73. }
  74. }