Reclamation.php 2.4 KB

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