GoodsCommentModel.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 商品评论-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class GoodsCommentModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'goods_comments';
  22. protected $appends = ['time_text'];
  23. // 时间
  24. public function getTimeTextAttribute()
  25. {
  26. return $this->create_time? dateFormat($this->create_time,'Y-m-d') : '';
  27. }
  28. /**
  29. * 图册
  30. * @param $value
  31. * @return array|string
  32. */
  33. public function getAlbumsAttribute($value)
  34. {
  35. $value = $value? get_images_preview($value,'url',2) : [];
  36. return $value;
  37. }
  38. /**
  39. * 发布用户
  40. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  41. */
  42. public function user()
  43. {
  44. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  45. ->select(['id','openid', 'mobile', 'nickname','balance','avatar', 'realname', 'status']);
  46. }
  47. /**
  48. * 订单
  49. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  50. */
  51. public function order()
  52. {
  53. return $this->hasOne(OrderModel::class, 'id', 'order_id')
  54. ->select(['id','order_no', 'user_id', 'total','status']);
  55. }
  56. }