| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class TerminalPrinter extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- protected $fillable = ['terminal_id', 'printer_name', 'alias_name', 'print_type'];
- static public $enums = [
- 'print_type' => [
- '菜鸟' => 0,
- '拼多多' => 1,
- '顺丰' => 2,
- '京东' => 3,
- ],
- ];
- function __construct(array $attributes = [])
- {
- foreach (self::$enums as &$enum) {
- $enum = $enum + array_flip($enum);
- }
- parent::__construct($attributes);
- }
- public function getPrintTypeAttribute($value)
- {
- if (!$value && $value !== 0) return '';
- return self::$enums['print_type'][$value];
- }
- public function setPrintTypeAttribute($value)
- {
- if (!$value) return 0;
- $this->attributes['print_type'] = self::$enums['print_type'][$value];
- }
- public function terminal(): BelongsTo
- {
- return $this->belongsTo(Terminal::class);
- }
- }
|