WarningLogTraitModel.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/9/4
  6. * Time: 9:36 AM
  7. */
  8. namespace App\Models;
  9. use App\Maps\WarningLogMap;
  10. trait WarningLogTraitModel
  11. {
  12. /**
  13. * 电量数据包
  14. * @param $bike_no
  15. * @param $box_no
  16. * @param $body
  17. * @param $source_body
  18. * @param $source
  19. * User: Mead
  20. */
  21. public function warningLogBatteryLow($bike_no, $box_no, $body, $source_body, $source)
  22. {
  23. $this->db->insert('warning_logs')->cols([
  24. 'bike_no' => $bike_no,
  25. 'box_no' => $box_no,
  26. 'body' => serialize($body),
  27. 'source_body' => implode(' ', $source_body),
  28. 'type' => WarningLogMap::TYPE_BATTERY_LOW,
  29. 'error_grade' => WarningLogMap::ERROR_GRADE_MAJOR,
  30. 'source' => $source,
  31. 'created_at' => date('Y-m-d H:i:s')
  32. ])->query();
  33. }
  34. /**
  35. * 车辆离线
  36. * @param $bike_no
  37. * @param $box_no
  38. * @param $body
  39. * @param $source_body
  40. * @param $source
  41. * User: Mead
  42. */
  43. public function warningLogBikeOffLine($bike_no, $box_no, $source)
  44. {
  45. $body = [];
  46. $source_body = [];
  47. $this->db->insert('warning_logs')->cols([
  48. 'bike_no' => $bike_no,
  49. 'box_no' => $box_no,
  50. 'body' => serialize($body),
  51. 'source_body' => implode(' ', $source_body),
  52. 'type' => WarningLogMap::TYPE_BIKE_OFF_LINE,
  53. 'error_grade' => WarningLogMap::ERROR_GRADE_CRITICAL,
  54. 'source' => $source,
  55. 'created_at' => date('Y-m-d H:i:s')
  56. ])->query();
  57. }
  58. public static function warningLogBikeOffLineStatic($bike_no, $box_no, $source)
  59. {
  60. $body = [];
  61. $source_body = [];
  62. self::$db->insert('warning_logs')->cols([
  63. 'bike_no' => $bike_no,
  64. 'box_no' => $box_no,
  65. 'body' => serialize($body),
  66. 'source_body' => implode(' ', $source_body),
  67. 'type' => WarningLogMap::TYPE_BIKE_OFF_LINE,
  68. 'error_grade' => WarningLogMap::ERROR_GRADE_CRITICAL,
  69. 'source' => $source,
  70. 'created_at' => date('Y-m-d H:i:s')
  71. ])->query();
  72. }
  73. /**
  74. * 警告数据包
  75. * @param $bike_no
  76. * @param $box_no
  77. * @param $body
  78. * @param $source_body
  79. * @param $type
  80. * @param $error_grade
  81. * User: Mead
  82. */
  83. public function warningLog($bike_no, $box_no, $body, $source_body, $type, $error_grade)
  84. {
  85. $this->db->insert('warning_logs')->cols([
  86. 'bike_no' => $bike_no,
  87. 'box_no' => $box_no,
  88. 'body' => serialize($body),
  89. 'source_body' => implode(' ', $source_body),
  90. 'type' => $type,
  91. 'error_grade' => $error_grade,
  92. 'source' => 'warning',
  93. 'created_at' => date('Y-m-d H:i:s')
  94. ])->query();
  95. }
  96. public function warningFF($bike_no, $box_no, $body, $source_body)
  97. {
  98. $this->db->insert('warning_logs')->cols([
  99. 'bike_no' => $bike_no,
  100. 'box_no' => $box_no,
  101. 'body' => serialize($body),
  102. 'source_body' => implode(' ', $source_body),
  103. 'type' => WarningLogMap::TYPE_WARNING_BIKE_OPEN,
  104. 'error_grade' => WarningLogMap::ERROR_GRADE_MAJOR,
  105. 'source' => 'warning',
  106. 'created_at' => date('Y-m-d H:i:s')
  107. ])->query();
  108. }
  109. }