GoodsComment.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use app\common\enum\GoodsCommentEnum;
  21. use think\model\concern\SoftDelete;
  22. class GoodsComment extends BaseModel
  23. {
  24. use SoftDelete;
  25. protected $deleteTime = 'delete_time';
  26. /**
  27. * @notes 用户评论获取器
  28. * @param $value
  29. * @return string
  30. * @author ljj
  31. * @date 2021/8/9 10:25 上午
  32. */
  33. public function getCommentAttr($value)
  34. {
  35. if (!$value) {
  36. return '此用户没有填写评价';
  37. }
  38. return $value;
  39. }
  40. /**
  41. * @notes 一对多关联商品评论图片模型
  42. * @return \think\model\relation\HasMany
  43. * @author ljj
  44. * @date 2021/8/9 10:28 上午
  45. */
  46. public function goodsCommentImage()
  47. {
  48. return $this->hasMany(GoodsCommentImage::class, 'comment_id','id');
  49. }
  50. public function user(){
  51. return $this->hasOne(User::class,'id','user_id')->bind(['nickname','avatar']);
  52. }
  53. /**
  54. * @notes 评价登记获取器
  55. * @param $value
  56. * @param $data
  57. * @return string
  58. * @author ljj
  59. * @date 2021/8/12 3:11 下午
  60. */
  61. public function getCommentLevelAttr($value,$data)
  62. {
  63. if ($data['goods_comment'] > 3) {
  64. return '好评';
  65. }
  66. if ($data['goods_comment'] == 3) {
  67. return '中评';
  68. }
  69. if ($data['goods_comment'] < 3) {
  70. return '差评';
  71. }
  72. return '未知';
  73. }
  74. /**
  75. * @notes 状态获取器
  76. * @param $value
  77. * @param $data
  78. * @return string|string[]
  79. * @author ljj
  80. * @date 2021/8/12 3:18 下午
  81. */
  82. public function getStatusDescAttr($value,$data)
  83. {
  84. return GoodsCommentEnum::getStatusDesc($data['status']);
  85. }
  86. /**
  87. * @notes 回复状态获取器
  88. * @param $value
  89. * @param $data
  90. * @return string
  91. * @author ljj
  92. * @date 2021/9/9 11:12 上午
  93. */
  94. public function getReplyStatusDescAttr($value,$data)
  95. {
  96. if ($data['reply'] == null) {
  97. return '待回复';
  98. }
  99. return '已回复';
  100. }
  101. }