123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\common\model\base\other;
- /**
- * @title : 行政区域模型
- * @desc :
- * @Author : Rock
- * @Date : 2021-11-27 19:49:28
- * @LastEditTime : 2021-11-28 11:44:30
- */
- use app\common\model\Common;
- class Area extends Common{
- protected $name = "system_area";
- protected $pk = 'id';
- protected $append = [
- 'hasChildren',
- 'pname',
- 'pathName',
- 'common_txt'
- ];
- public function getHasChildrenAttr($value,$data)
- {
- $value = $value ? $value : (isset($data['id']) ? $data['id'] : '');
- $where = [];
- $where[] = ['pid','=',$value];
- $where[] = ['level','<',3];
- $where[] = ['name','NOT IN',['市辖区','县']];
- $info = self::where($where)->find();
- return !empty($info);
- }
- public function getPnameAttr($value,$data)
- {
- $value = $value ? $value : (isset($data['pid']) ? $data['pid'] : '');
- $info = self::where('id',$value)->field(['name'=>'title'])->find();
- return $info?$info['title']:'';
- }
- public function getPathNameAttr($value,$data)
- {
- $value = $value ? $value : (isset($data['path']) ? $data['path'] : '');
- if(!empty($value)){
- $pathids = explode(',',$value);
- $list = self::where('id','IN',$pathids)->field(['name'=>'title'])->select()->toArray();
- return implode(',',array_column($list,'title'));
- }else{
- return '';
- }
- }
- public function commonList()
- {
- return [0=>'不常用',1=>'常用'];
- }
- public function getCommonTxtAttr($value,$data)
- {
- $value = $value ? $value : (isset($data['common']) ? $data['common'] : 0);
- $info = $this->commonList();
- return $info[$value];
- }
- }
|