12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/4
- * Time: 9:36 AM
- */
- namespace App\Models;
- trait BikeTraitModel
- {
- // public static $redis = new \Redis();
- private static $redis_bike_no_tags = 'box_no_and_bike_no';
- private static $redis_bike_no_to_area_id_tags = 'bike_no_to_area_id';
- /**
- * 根据box_no获取车的no
- * @param $box_no
- * @return mixed
- * User: Mead
- */
- public function byBoxNoGetBikeNo($box_no)
- {
- return $this->redis->hget(self::$redis_bike_no_tags, $box_no);
- }
- /**
- * 根据box_no获取车的no
- * @param $box_no
- * @return mixed
- * User: Mead
- */
- public static function byBoxNoGetBikeNoStatic($box_no)
- {
- return self::$redis->hget(self::$redis_bike_no_tags, $box_no);
- }
- /**
- * 根据box_no 获取车的area_id
- * User: Mead
- */
- public function byBoxNoGetAreaId($box_no)
- {
- $area_id = $this->redis->get(self::$redis_bike_no_to_area_id_tags . $box_no);
- if ($area_id) {
- return $area_id;
- }
- $area_id = $this->db->select('put_area_id')->from('bikes')->where("box_no = " . $box_no)->single();
- if (!$area_id) return false;
- $this->redis->setex(self::$redis_bike_no_to_area_id_tags . $box_no, 24 * 60 * 60, $area_id);
- return $area_id;
- }
- }
|