Relevance.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\system;
  12. use app\common\model\store\product\Spu;
  13. use app\common\model\BaseModel;
  14. use app\common\model\community\Community;
  15. use app\common\model\store\StoreCategory;
  16. use app\common\model\system\auth\Menu;
  17. use app\common\model\system\merchant\Merchant;
  18. use app\common\model\user\User;
  19. use app\common\repositories\system\RelevanceRepository;
  20. class Relevance extends BaseModel
  21. {
  22. /**
  23. * TODO
  24. * @return string
  25. * @author Qinii
  26. * @day 10/26/21
  27. */
  28. public static function tablePk(): string
  29. {
  30. return 'relevance_id';
  31. }
  32. /**
  33. * TODO
  34. * @return string
  35. * @author Qinii
  36. * @day 10/26/21
  37. */
  38. public static function tableName(): string
  39. {
  40. return 'relevance';
  41. }
  42. public function fans()
  43. {
  44. return $this->hasOne(User::class,'uid','left_id');
  45. }
  46. public function focus()
  47. {
  48. return $this->hasOne(User::class,'uid','right_id');
  49. }
  50. public function community()
  51. {
  52. return $this->hasOne(Community::class,'community_id','right_id')
  53. ->bind(['community_id','title','image','start','uid','create_time','count_start','author','is_type']);
  54. }
  55. public function getIsStartAttr()
  56. {
  57. return self::where('left_id', $this->right_id)
  58. ->where('right_id',$this->left_id)
  59. ->where('type',RelevanceRepository::TYPE_COMMUNITY_FANS)
  60. ->count() > 0;
  61. }
  62. public function spu()
  63. {
  64. return $this->hasOne(Spu::class, 'spu_id','right_id');
  65. }
  66. public function merchant()
  67. {
  68. return $this->hasOne(Merchant::class, 'mer_id','right_id');
  69. }
  70. public function category()
  71. {
  72. return $this->hasOne(StoreCategory::class, 'store_category_id','right_id');
  73. }
  74. public function auth()
  75. {
  76. return $this->hasOne(Menu::class, 'menu_id','right_id');
  77. }
  78. public function searchLeftIdAttr($query, $value)
  79. {
  80. $query->where('left_id', $value);
  81. }
  82. public function searchRightIdAttr($query, $value)
  83. {
  84. $query->where('right_id', $value);
  85. }
  86. public function searchTypeAttr($query, $value)
  87. {
  88. $query->where('type', $value);
  89. }
  90. }