Comment.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\model;
  13. use cores\BaseModel;
  14. /**
  15. * 商品评价模型
  16. * Class Comment
  17. * @package app\common\model
  18. */
  19. class Comment extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'comment';
  23. // 定义主键
  24. protected $pk = 'comment_id';
  25. /**
  26. * 所属订单
  27. * @return \think\model\relation\BelongsTo
  28. */
  29. public function orderData()
  30. {
  31. return $this->belongsTo('Order');
  32. }
  33. /**
  34. * 订单商品
  35. * @return \think\model\relation\BelongsTo
  36. */
  37. public function orderGoods()
  38. {
  39. return $this->belongsTo('OrderGoods')
  40. ->field(['order_goods_id', 'goods_id', 'goods_name', 'image_id', 'goods_props', 'order_id']);
  41. }
  42. /**
  43. * 关联用户表
  44. * @return \think\model\relation\BelongsTo
  45. */
  46. public function user()
  47. {
  48. return $this->belongsTo('User')->field(['user_id', 'nick_name', 'avatar_id']);
  49. }
  50. /**
  51. * 关联评价图片表
  52. * @return \think\model\relation\HasMany
  53. */
  54. public function images()
  55. {
  56. return $this->hasMany('CommentImage')->order(['id']);
  57. }
  58. /**
  59. * 详情记录
  60. * @param int $commentId
  61. * @param array $with
  62. * @return static|array|null
  63. */
  64. public static function detail(int $commentId, array $with = [])
  65. {
  66. return static::get($commentId, $with);
  67. }
  68. /**
  69. * 添加评论图片
  70. * @param array $images
  71. * @return array|false
  72. */
  73. protected function addCommentImages(array $images)
  74. {
  75. $data = array_map(function ($imageId) {
  76. return [
  77. 'image_id' => $imageId,
  78. 'store_id' => self::$storeId
  79. ];
  80. }, $images);
  81. return $this->image()->saveAll($data) !== false;
  82. }
  83. }