Oilstat.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\models\entity;
  3. use phpDocumentor\Reflection\Types\This;
  4. use yii\db\ActiveRecord;
  5. /**
  6. * This is the model class for table "so_oilstat".
  7. *
  8. * @property int $id
  9. * @property string $cond
  10. * @property int $device_id
  11. * @property string $date [varchar(255)]
  12. * @property string $token [varchar(255)]
  13. * @property string $location [varchar(5)]
  14. * @property int $section_number [int(10)]
  15. * @property int $send_date [int(10)] Дата отправки данных timestamp
  16. * @property string $send_ip [varchar(255)] IP с которого запросили данные
  17. *
  18. * @property WheelPairs $wheelpairs
  19. */
  20. class Oilstat extends ActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return 'so_oilstat';
  28. }
  29. public static function getDb()
  30. {
  31. return \Yii::$app->slave_db;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['cond', 'date', 'device_id', 'token'], 'required'],
  40. [['device_id', 'send_date'], 'integer'],
  41. [['cond'], 'string', 'max' => 5],
  42. [['token','date'], 'unique', 'targetAttribute' => ['date', 'token']],
  43. [['date', 'token', 'send_ip'], 'string', 'max' => 255],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => 'ID',
  53. 'cond' => 'Состояние',
  54. 'device_id' => 'Номер устройства(масломер)',
  55. 'date' => 'Дата',
  56. 'token' => 'Метка (rfid)',
  57. 'location' => 'Расположение клёсной пары',
  58. 'section_number' => 'Номер секции',
  59. 'send_date' => 'Дата отправки показаний',
  60. 'send_ip' => 'IP с которого пришли показания'
  61. ];
  62. }
  63. /**
  64. * @return \yii\db\ActiveQuery
  65. */
  66. public function getWheelpairs()
  67. {
  68. return $this->hasOne(WheelPairs::class, ['token' => 'token']);
  69. }
  70. public function getLocation()
  71. {
  72. if ($this->location) return $this->location;
  73. $location = explode('/', $this->token);
  74. return $location[1] ?? null;
  75. }
  76. }