BoxBinding.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. class BoxBinding extends Model
  6. {
  7. use ModelHelpers;
  8. //
  9. protected $table = "box_binding";
  10. protected $guarded = [];
  11. const BINDING_YES = 1;
  12. const BINDING_NO = 0;
  13. public static $bindingMaps = [
  14. self::BINDING_NO => '未绑定',
  15. self::BINDING_YES => '已绑定',
  16. ];
  17. const TBT = 1;
  18. const WKM = 2;
  19. public static $manufacturerMaps = [
  20. self::TBT => '泰比特',
  21. self::WKM => '威科姆',
  22. ];
  23. public function getBlekgAttribute($value)
  24. {
  25. if ($value == 1) {
  26. return true;
  27. } else {
  28. return false;
  29. }
  30. }
  31. public function setBlekgAttribute($value)
  32. {
  33. $this->attributes['blekg'] = $value ? 1 : 0;
  34. }
  35. public function bikes()
  36. {
  37. return $this->belongsTo(Bike::class, 'box_no', 'box_no');
  38. }
  39. public function updateBox($box_no, $data)
  40. {
  41. return $this->query()->where('box_no', $box_no)->update($data);
  42. }
  43. }