1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Bike extends Model
- {
- protected $guarded = [];
- // redis 中车的标识
- const REDIS_BOX_NO_AND_BIKE_NO_TAG = 'box_no_and_bike_no';
- const REDIS_BIKE_LOCATION_TAG = 'bike_locations';
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停'
- ];
- const LINK_ONLINE = 1;
- const LINK_OFFLINE = 0;
- public static $linkMaps = [
- self::LINK_ONLINE => '在线',
- self::LINK_OFFLINE => '离线'
- ];
- const TROUBLE_YES = 1;
- const TROUBLE_NO = 0;
- public static $troubleMaps = [
- self::TROUBLE_NO => '无故障',
- self::TROUBLE_YES => '有故障'
- ];
- const PUT_STATUS_YES = 1;
- const PUT_STATUS_NO = 0;
- public static $putStatusMaps = [
- self::PUT_STATUS_YES => '已投放',
- self::PUT_STATUS_NO => '未投放'
- ];
- const IN_PARKING_YES = 1;
- const IN_PARKING_NO = 0;
- public static $inParkingMaps = [
- self::IN_PARKING_NO => '不在停车区',
- self::IN_PARKING_YES => '在停车区'
- ];
- const RIDING_YES = 1;
- const RIDING_NO = 0;
- public static $ridingMaps = [
- self::RIDING_YES => '骑行中',
- self::RIDING_NO => '未骑行'
- ];
- const RENT_YES = 1;
- const RENT_NO = 0;
- public static $rentMaps = [
- self::RENT_YES => '租用中',
- self::RENT_NO => '未租用'
- ];
- const BATTERY_POWER_OK = 1;
- const BATTERY_POWER_LOW = 0;
- public static $batteryPowerMaps = [
- self::BATTERY_POWER_OK => '电量正常',
- self::BATTERY_POWER_LOW => '低电量'
- ];
- public function scopeBikeCanRide($query)
- {
- return $query->where('is_link', self::LINK_ONLINE)
- ->where('is_low_battery_power', self::BATTERY_POWER_OK)
- ->where('is_riding', self::RIDING_NO)
- ->where('is_trouble', self::TROUBLE_NO)
- ->where('status', self::STATUS_OK);
- }
- public function getLocationAttribute()
- {
- return js2php($this->attributes['last_location']);
- }
- }
|