Comment.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\sharing;
  10. use app\common\model\BaseModel;
  11. /**
  12. * 拼团商品评价模型
  13. * Class Comment
  14. * @package app\common\model\sharing
  15. */
  16. class Comment extends BaseModel
  17. {
  18. protected $name = 'sharing_comment';
  19. /**
  20. * 所属订单
  21. * @return \think\model\relation\BelongsTo
  22. */
  23. public function orderM()
  24. {
  25. return $this->belongsTo('Order');
  26. }
  27. /**
  28. * 订单商品
  29. * @return \think\model\relation\BelongsTo
  30. */
  31. public function OrderGoods()
  32. {
  33. return $this->belongsTo('OrderGoods');
  34. }
  35. /**
  36. * 关联用户表
  37. * @return \think\model\relation\BelongsTo
  38. */
  39. public function user()
  40. {
  41. $module = self::getCalledModule() ?: 'common';
  42. return $this->belongsTo("app\\{$module}\\model\\User");
  43. }
  44. /**
  45. * 关联评价图片表
  46. * @return \think\model\relation\HasMany
  47. */
  48. public function image()
  49. {
  50. return $this->hasMany('CommentImage', 'comment_id')->order(['id' => 'asc']);
  51. }
  52. /**
  53. * 评价详情
  54. * @param $comment_id
  55. * @return Comment|null
  56. * @throws \think\exception\DbException
  57. */
  58. public static function detail($comment_id)
  59. {
  60. return self::get($comment_id, ['user', 'orderM', 'OrderGoods', 'image.file']);
  61. }
  62. }