select('name')->first(); $name = isset($name) ? $name->name : ''; Cache::forever('JC_AreaNameById_' . $id, $name); } return Cache::get('JC_AreaNameById_' . $id); } /** * * @author fatty * @date 2019/1/7 * @description */ public static function getIterationArea($code = 0, $temp = []) { if (!Cache::has('JC_Area')) { $area = Area::whereParentCode($code)->select(['name', 'code'])->get(); if ($area->isNotEmpty()) { foreach ($area as $item) { $temp[] = [ 'name' => $item->name, 'value' => $item->code ]; if ($code != 0) { $temp = array_merge($temp, ['parent' => $code]); } // $temp = self::getIterationArea($item['code'], $temp); } } } return $temp; } /** * 检查省市区的从属关系 * @author lyh * @date 2019/3/21 * @description */ public static function isRealation($province, $city, $district) { if (Area::wherePid($city)->whereId($district)->exists() == false) { return false; } if (Area::wherePid($province)->whereId($city)->exists() == false) { return false; } return true; } /** * 获取地区信息 * @author lyh * @date 2019/4/15 * @param int $province 省id * @param int $city 地级市ID * @param int $district 县区ID * @return string * @description */ public static function getArea($province, $city, $district) { return trim(self::getName($province) . ' ' . self::getName($city) . ' ' . self::getName($district)); } public function UserAddress() { return $this->hasMany('App\Modes\UserAddress', 'id'); } }