Reclamation.php 2.6 KB

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