UserRelation.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\user;
  12. use app\model\activity\video\Video;
  13. use app\model\product\product\StoreProduct;
  14. use crmeb\traits\ModelTrait;
  15. use crmeb\basic\BaseModel;
  16. use think\Model;
  17. /**
  18. * 用户点赞、收藏、分享(商品、短视频)model
  19. * Class UserRelation
  20. * @package app\model\product\product
  21. */
  22. class UserRelation extends BaseModel
  23. {
  24. use ModelTrait;
  25. /**
  26. * 模型名称
  27. * @var string
  28. */
  29. protected $name = 'user_relation';
  30. /**
  31. * 关联商品
  32. * @return \think\model\relation\HasOne
  33. */
  34. public function product()
  35. {
  36. return $this->hasOne(StoreProduct::class, 'id', 'relation_id');
  37. }
  38. /**
  39. * 关联视频
  40. * @return \think\model\relation\HasOne
  41. */
  42. public function video()
  43. {
  44. return $this->hasOne(Video::class, 'id', 'relation_id');
  45. }
  46. /**
  47. * 用户搜索器
  48. * @param Model $query
  49. * @param $value
  50. */
  51. public function searchUidAttr($query, $value)
  52. {
  53. $query->where('uid', $value);
  54. }
  55. /**
  56. * 关联搜索器
  57. * @param Model $query
  58. * @param $value
  59. */
  60. public function searchRelationIdAttr($query, $value)
  61. {
  62. if ($value) {
  63. if (is_array($value)) {
  64. $query->whereIn('relation_id', $value);
  65. } else {
  66. $query->where('relation_id', $value);
  67. }
  68. }
  69. }
  70. /**
  71. * 类型搜索器
  72. * @param Model $query
  73. * @param $value
  74. */
  75. public function searchTypeAttr($query, $value)
  76. {
  77. if ($value) {
  78. if (is_array($value)) {
  79. $query->whereIn('type', $value);
  80. } else {
  81. $query->where('type', $value);
  82. }
  83. }
  84. }
  85. /**
  86. * 商品类型搜索器
  87. * @param Model $query
  88. * @param $value
  89. */
  90. public function searchCategoryAttr($query, $value)
  91. {
  92. if ($value) {
  93. if (is_array($value)) {
  94. $query->whereIn('category', $value);
  95. } else {
  96. $query->where('category', $value);
  97. }
  98. }
  99. }
  100. }