海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
837 B

4 years ago
  1. <?php
  2. namespace App\Models;
  3. use App\Common\ProductStatus;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. class AgentProduct extends BaseModel
  7. {
  8. use HasFactory, SoftDeletes;
  9. protected $guarded = ['id'];
  10. public function product()
  11. {
  12. return $this->belongsTo(Product::class)->where('status', ProductStatus::ON_SALE);
  13. }
  14. public function coupon()
  15. {
  16. return $this->hasMany(Coupon::class);
  17. }
  18. public function fav()
  19. {
  20. return $this->hasOne(UserFav::class);
  21. }
  22. public function agent()
  23. {
  24. return $this->belongsTo(Agent::class);
  25. }
  26. public function category()
  27. {
  28. return $this->belongsTo(Category::class);
  29. }
  30. public function setChannelIdAttribute($value)
  31. {
  32. if (is_array($value)) {
  33. $this->attributes['channel_id'] = join(',', array_filter($value));
  34. }
  35. }
  36. }