BikeTraitModel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. trait BikeTraitModel
  10. {
  11. // public static $redis = new \Redis();
  12. private static $redis_bike_no_tags = 'box_no_and_bike_no';
  13. private static $redis_bike_no_to_area_id_tags = 'bike_no_to_area_id';
  14. /**
  15. * 根据box_no获取车的no
  16. * @param $box_no
  17. * @return mixed
  18. * User: Mead
  19. */
  20. public function byBoxNoGetBikeNo($box_no)
  21. {
  22. return $this->redis->hget(self::$redis_bike_no_tags, $box_no);
  23. }
  24. /**
  25. * 根据box_no获取车的no
  26. * @param $box_no
  27. * @return mixed
  28. * User: Mead
  29. */
  30. public static function byBoxNoGetBikeNoStatic($box_no)
  31. {
  32. return self::$redis->hget(self::$redis_bike_no_tags, $box_no);
  33. }
  34. /**
  35. * 根据box_no 获取车的area_id
  36. * User: Mead
  37. */
  38. public function byBoxNoGetAreaId($box_no)
  39. {
  40. $area_id = $this->redis->get(self::$redis_bike_no_to_area_id_tags . $box_no);
  41. if ($area_id) {
  42. return $area_id;
  43. }
  44. $area_id = $this->db->select('put_area_id')->from('bikes')->where("box_no = " . $box_no)->single();
  45. if (!$area_id) return false;
  46. $this->redis->setex(self::$redis_bike_no_to_area_id_tags . $box_no, 24 * 60 * 60, $area_id);
  47. return $area_id;
  48. }
  49. }