TerminalPrinter.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelTimeFormat;
  4. use Illuminate\Database\Eloquent\Model;
  5. use App\Traits\ModelLogChanging;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. class TerminalPrinter extends Model
  8. {
  9. use ModelLogChanging;
  10. use ModelTimeFormat;
  11. protected $fillable = ['terminal_id', 'printer_name', 'alias_name', 'print_type'];
  12. static public $enums = [
  13. 'print_type' => [
  14. '菜鸟' => 0,
  15. '拼多多' => 1,
  16. '顺丰' => 2,
  17. '京东' => 3,
  18. ],
  19. ];
  20. function __construct(array $attributes = [])
  21. {
  22. foreach (self::$enums as &$enum) {
  23. $enum = $enum + array_flip($enum);
  24. }
  25. parent::__construct($attributes);
  26. }
  27. public function getPrintTypeAttribute($value)
  28. {
  29. if (!$value && $value !== 0) return '';
  30. return self::$enums['print_type'][$value];
  31. }
  32. public function setPrintTypeAttribute($value)
  33. {
  34. if (!$value) return 0;
  35. $this->attributes['print_type'] = self::$enums['print_type'][$value];
  36. }
  37. public function terminal(): BelongsTo
  38. {
  39. return $this->belongsTo(Terminal::class);
  40. }
  41. }