Bike.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Bike extends Model
  5. {
  6. protected $guarded = [];
  7. // redis 中车的标识
  8. const REDIS_BOX_NO_AND_BIKE_NO_TAG = 'box_no_and_bike_no';
  9. const REDIS_BIKE_LOCATION_TAG = 'bike_locations';
  10. const STATUS_OK = 1;
  11. const STATUS_PAUSE = 0;
  12. public static $statusMaps = [
  13. self::STATUS_OK => '正常',
  14. self::STATUS_PAUSE => '暂停'
  15. ];
  16. const LINK_ONLINE = 1;
  17. const LINK_OFFLINE = 0;
  18. public static $linkMaps = [
  19. self::LINK_ONLINE => '在线',
  20. self::LINK_OFFLINE => '离线'
  21. ];
  22. const TROUBLE_YES = 1;
  23. const TROUBLE_NO = 0;
  24. public static $troubleMaps = [
  25. self::TROUBLE_NO => '无故障',
  26. self::TROUBLE_YES => '有故障'
  27. ];
  28. const PUT_STATUS_YES = 1;
  29. const PUT_STATUS_NO = 0;
  30. public static $putStatusMaps = [
  31. self::PUT_STATUS_YES => '已投放',
  32. self::PUT_STATUS_NO => '未投放'
  33. ];
  34. const IN_PARKING_YES = 1;
  35. const IN_PARKING_NO = 0;
  36. public static $inParkingMaps = [
  37. self::IN_PARKING_NO => '不在停车区',
  38. self::IN_PARKING_YES => '在停车区'
  39. ];
  40. const RIDING_YES = 1;
  41. const RIDING_NO = 0;
  42. public static $ridingMaps = [
  43. self::RIDING_YES => '骑行中',
  44. self::RIDING_NO => '未骑行'
  45. ];
  46. const RENT_YES = 1;
  47. const RENT_NO = 0;
  48. public static $rentMaps = [
  49. self::RENT_YES => '租用中',
  50. self::RENT_NO => '未租用'
  51. ];
  52. const BATTERY_POWER_OK = 1;
  53. const BATTERY_POWER_LOW = 0;
  54. public static $batteryPowerMaps = [
  55. self::BATTERY_POWER_OK => '电量正常',
  56. self::BATTERY_POWER_LOW => '低电量'
  57. ];
  58. public function scopeBikeCanRide($query)
  59. {
  60. return $query->where('is_link', self::LINK_ONLINE)
  61. ->where('is_low_battery_power', self::BATTERY_POWER_OK)
  62. ->where('is_riding', self::RIDING_NO)
  63. ->where('is_trouble', self::TROUBLE_NO)
  64. ->where('status', self::STATUS_OK);
  65. }
  66. public function getLocationAttribute()
  67. {
  68. return js2php($this->attributes['last_location']);
  69. }
  70. }