Reclamation.php 2.9 KB

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