Comment.php 1.3 KB

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