Reclamation.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ];
  43. public function order(): BelongsTo
  44. {
  45. return $this->belongsTo(Order::class)->withoutGlobalScopes();
  46. }
  47. public function status(): BelongsTo
  48. {
  49. return $this->belongsTo(ReclamationStatus::class);
  50. }
  51. public function skus(): BelongsToMany
  52. {
  53. return $this->belongsToMany(
  54. ProductSKU::class,
  55. 'reclamation_product_sku',
  56. 'reclamation_id',
  57. 'product_sku_id')
  58. ->withoutGlobalScopes();
  59. }
  60. public function user(): BelongsTo
  61. {
  62. return $this->belongsTo(User::class);
  63. }
  64. public function brigadier(): BelongsTo
  65. {
  66. return $this->belongsTo(User::class, 'brigadier_id', 'id');
  67. }
  68. public function photos_before(): BelongsToMany
  69. {
  70. return $this->belongsToMany(File::class, 'reclamation_photo_before');
  71. }
  72. public function photos_after(): BelongsToMany
  73. {
  74. return $this->belongsToMany(File::class, 'reclamation_photo_after');
  75. }
  76. public function documents(): BelongsToMany
  77. {
  78. return $this->belongsToMany(File::class, 'reclamation_document');
  79. }
  80. public function acts(): BelongsToMany
  81. {
  82. return $this->belongsToMany(File::class, 'reclamation_act');
  83. }
  84. public function details(): HasMany
  85. {
  86. return $this->hasMany(ReclamationDetail::class);
  87. }
  88. }