Comment.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\common\models;
  3. use app\backend\modules\goods\services\CommentService;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. /**
  6. * Created by PhpStorm.
  7. * Author: 芸众商城 www.yunzshop.com
  8. * Date: 2017/2/27
  9. * Time: 下午5:07
  10. */
  11. use Illuminate\Support\Facades\DB;
  12. class Comment extends BaseModel
  13. {
  14. const not_audit = 0;//不需要审核
  15. const pass_audit = 1;//通过审核
  16. const wait_audit = 2;//等待审核
  17. public $attributes = ['type' => 1];
  18. protected $casts = [
  19. 'score_latitude' => 'json'
  20. ];
  21. use SoftDeletes;
  22. public $table = 'yz_comment';
  23. public $TypeName;
  24. protected $appends = ['type_name'];
  25. protected $guarded = [''];
  26. protected $fillable = [''];
  27. public static function getOrderGoodsComment()
  28. {
  29. return self::uniacid();
  30. }
  31. public static function getReplyById($id)
  32. {
  33. return self::uniacid()
  34. ->where('comment_id', $id)
  35. ->where('uid', '<>', DB::raw('reply_id'))
  36. ->orderBy('created_at', 'asc')
  37. ->get();
  38. }
  39. // public function getReplyAttribute()
  40. // {
  41. // if (!isset($this->Reply)) {
  42. // $reply['data'] = static::getReplyById($this->id);
  43. // $reply['count'] = $reply['data']->count('id');
  44. // $this->Reply = $reply;
  45. // }
  46. // return $this->Reply;
  47. // }
  48. //
  49. // public function getAppendAttribute()
  50. // {
  51. // if (!isset($this->Append)) {
  52. // $append['data'] = static::getAppendById($this->id);
  53. // $append['count'] = $append['data']->count('id');
  54. // $this->Append = $append;
  55. // }
  56. // return $this->Append;
  57. // }
  58. public static function getAppendById($id)
  59. {
  60. return self::uniacid()
  61. ->where('comment_id', $id)
  62. ->where('uid', DB::raw('reply_id'))
  63. ->orderBy('created_at', 'asc')
  64. ->get();
  65. }
  66. public function getTypeNameAttribute()
  67. {
  68. if (!isset($this->TypeName)) {
  69. $this->TypeName = CommentService::getTypeName($this->type);
  70. }
  71. return $this->TypeName;
  72. }
  73. public function hasManyReply()
  74. {
  75. return $this->hasMany(self::class);
  76. }
  77. public function hasManyAppend()
  78. {
  79. return $this->hasMany(self::class);
  80. }
  81. public function hasOneGoods(){
  82. return $this->hasOne(Goods::class,'id','goods_id');
  83. }
  84. public function hasOneMember()
  85. {
  86. return $this->hasOne('app\common\models\Member', 'uid', 'uid');
  87. }
  88. public function getAfterContent($comment_id)
  89. {
  90. return self::uniacid()
  91. ->select(['id','content','images','type'])
  92. ->where('comment_id',$comment_id)
  93. ->where('type',3)
  94. ->where('audit_status','!=',2)
  95. ->first();
  96. }
  97. /**
  98. * 修改主评论追评ID
  99. * @param int $comment_id 主评论ID
  100. * @param int $additional_comment_id 追评ID
  101. * @return bool
  102. */
  103. public static function updatedAdditionalCommentId($comment_id,$additional_comment_id)
  104. {
  105. return self::where('id', $comment_id)->update(['additional_comment_id' => $additional_comment_id]);
  106. }
  107. }