Reclamation.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. class Reclamation extends Model
  8. {
  9. const DEFAULT_SORT_BY = 'created_at';
  10. const STATUS_NEW = 1;
  11. const STATUS_IN_WORK = 2;
  12. const STATUS_SUBSCRIBE_ACT = 3;
  13. const STATUS_DONE = 4;
  14. const STATUS_SENT = 5;
  15. const STATUS_DO_DOCS = 6;
  16. const STATUS_HANDOVER_TO_CHECK = 7;
  17. const STATUS_PAID = 8;
  18. const STATUS_CLOSED_NO_PAY = 9;
  19. const STATUS_NAMES = [
  20. self::STATUS_NEW => 'Новая',
  21. self::STATUS_IN_WORK => 'В работе',
  22. self::STATUS_SUBSCRIBE_ACT => 'Подпись акта',
  23. self::STATUS_DONE => 'Исправлена',
  24. self::STATUS_SENT => 'Отправлена',
  25. self::STATUS_DO_DOCS => 'Подготовка документов',
  26. self::STATUS_HANDOVER_TO_CHECK => 'Передана на проверку',
  27. self::STATUS_PAID => 'Оплачена',
  28. self::STATUS_CLOSED_NO_PAY => 'Закрыта, не оплачивается',
  29. ];
  30. protected $fillable = [
  31. 'order_id',
  32. 'user_id',
  33. 'status_id',
  34. 'reason',
  35. 'guarantee',
  36. 'whats_done',
  37. 'create_date',
  38. 'finish_date',
  39. 'start_work_date',
  40. 'work_days',
  41. 'brigadier_id',
  42. 'comment',
  43. ];
  44. public function order(): BelongsTo
  45. {
  46. return $this->belongsTo(Order::class)->withoutGlobalScopes();
  47. }
  48. public function status(): BelongsTo
  49. {
  50. return $this->belongsTo(ReclamationStatus::class);
  51. }
  52. public function skus(): BelongsToMany
  53. {
  54. return $this->belongsToMany(
  55. ProductSKU::class,
  56. 'reclamation_product_sku',
  57. 'reclamation_id',
  58. 'product_sku_id')
  59. ->withoutGlobalScopes();
  60. }
  61. public function user(): BelongsTo
  62. {
  63. return $this->belongsTo(User::class);
  64. }
  65. public function brigadier(): BelongsTo
  66. {
  67. return $this->belongsTo(User::class, 'brigadier_id', 'id');
  68. }
  69. public function photos_before(): BelongsToMany
  70. {
  71. return $this->belongsToMany(File::class, 'reclamation_photo_before');
  72. }
  73. public function photos_after(): BelongsToMany
  74. {
  75. return $this->belongsToMany(File::class, 'reclamation_photo_after');
  76. }
  77. public function documents(): BelongsToMany
  78. {
  79. return $this->belongsToMany(File::class, 'reclamation_document');
  80. }
  81. public function acts(): BelongsToMany
  82. {
  83. return $this->belongsToMany(File::class, 'reclamation_act');
  84. }
  85. public function details(): HasMany
  86. {
  87. return $this->hasMany(ReclamationDetail::class);
  88. }
  89. }