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.

93 lines
2.3 KiB

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 SHOW_COMMENT = 1; //评论已审核
  16. //获取列表
  17. public static function getList(array $param)
  18. {
  19. extract($param); //参数:limit,offset
  20. $where['user_id'] = $user_id;
  21. $where['comment_type'] = $comment_type; //0商品评价,1文章评价
  22. $where['status'] = self::SHOW_COMMENT;
  23. $limit = isset($limit) ? $limit : 10;
  24. $offset = isset($offset) ? $offset : 0;
  25. $model = new Comment;
  26. if(isset($comment_rank)){$where['comment_rank'] = $comment_rank;} //评价分
  27. $model = $model->where($where);
  28. $res['count'] = $model->count();
  29. $res['list'] = array();
  30. if($res['count']>0)
  31. {
  32. $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
  33. }
  34. else
  35. {
  36. return '暂无记录';
  37. }
  38. return $res;
  39. }
  40. public static function getOne($id)
  41. {
  42. return self::where('id', $id)->first()->toArray();
  43. }
  44. public static function add(array $data)
  45. {
  46. if(self::where(array('user_id'=>$data['user_id'],'id_value'=>$data['id_value'],'comment_type'=>$data['comment_type']))->first()){return '亲,您已经评价啦!';}
  47. if ($id = self::insertGetId($data))
  48. {
  49. return true;
  50. }
  51. return false;
  52. }
  53. public static function modify($where, array $data)
  54. {
  55. if (self::where($where)->update($data))
  56. {
  57. return true;
  58. }
  59. return false;
  60. }
  61. //删除一条记录
  62. public static function remove(array $data)
  63. {
  64. if(!self::where(array('user_id'=>$data['user_id'],'comment_type'=>$data['comment_type'],'id_value'=>$data['id_value']))->first()){return '商品尚未评价';}
  65. if (!self::where(array('user_id'=>$data['user_id'],'comment_type'=>$data['comment_type'],'id_value'=>$data['id_value']))->delete())
  66. {
  67. return false;
  68. }
  69. return true;
  70. }
  71. }