| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace App\Modes;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Cache;
- /**
- * App\Modes\Area
- *
- * @property int $id
- * @property string $name 区域名称
- * @property string $short_name 区域简称
- * @property int $code 区域代码
- * @property int $parent_code 上级城市代码
- * @property int $level 区域层级:1-省,2-市,3-区/县,4-乡镇/街道
- * @property int $status 状态:1-正常,2-失效
- * @property \Illuminate\Support\Carbon $created_at
- * @property \Illuminate\Support\Carbon $updated_at
- * @property-read \Illuminate\Database\Eloquent\Collection|\App\Modes\UserAddress[] $UserAddress
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area query()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereCode($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereLevel($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereName($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereParentCode($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereShortName($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereUpdatedAt($value)
- * @mixin \Eloquent
- * @property int $pid 上级id
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area wherePid($value)
- * @property int $area_id 区域ID
- * @property int $sort 排序
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereAreaId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Area whereSort($value)
- */
- class Area extends Model
- {
- protected $table = 'area';
- /**
- * 获取区域名称
- * @author fatty
- * @date 2018/12/21
- * @param $id
- * @description
- */
- public static function getName($id)
- {
- if (empty($id)) {
- return '';
- }
- if (!Cache::has('JC_AreaNameById_' . $id)) {
- $name = Area::whereId($id)->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');
- }
- }
|