123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace backend\models;
- use common\models\Area;
- use Yii;
- /**
- * This is the model class for table "{{%auth_area}}".
- *
- * @property string $uid
- * @property integer $area_id
- * @property string $father_area_id
- * @property string $name
- */
- class AuthArea extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%auth_area}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['uid', 'area_id'], 'required'],
- [['uid', 'father_area_id'], 'integer'],
- [['name'], 'string'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'uid' => 'uid',
- 'area_id' => 'area_id',
- 'father_area_id' => 'father_area_id',
- 'name' => 'name',
- ];
- }
- public function settingAuth($uid,$post)
- {
- //先清除已有权限
- if($this::find()->where(['uid'=>$uid])->count() > 0 )
- {
- $this::deleteAll(['uid'=>$uid]);
- }
- if(!empty($post['all']))
- {
- $model = new AuthArea();
- $model->uid = $uid;
- $model->area_id = 'all';
- $model->save();
- }elseif (!empty($post['citys']))
- {
- $datas = array();
- foreach ($post['citys'] as $val)
- {
- $area = Area::queryAdminCityInfo($val);
- $datas[] = [$uid,$val,$area['father_area_id'],$area['area']];
- }
- Yii::$app->db->createCommand()->batchInsert("{{%auth_area}}",['uid','area_id','father_area_id','name'],$datas)->execute();
- }
- }
- /**
- * 获取选中城市
- */
- public function queryCheckbox($uid)
- {
- $result = ['list'=>array(),'all'=>false];
- if($this::find()->where(['uid'=>$uid,'area_id'=>'all'])->count()>0){
- $result['all'] = true;
- return $result;
- }
- $list = $this::find()->where(['uid'=>$uid])->select('area_id')->all();
- if(!empty($list))
- {
- foreach ($list as $value)
- $result['list'][] =$value->area_id;
- }
- return $result;
- }
- /**
- * 获取权限
- */
- static public function queryAuth()
- {
- if(AuthArea::find()->where(['uid'=>Yii::$app->user->id,'area_id'=>'all'])->count()>0)
- return 'all';
- $result = "";
- $list = AuthArea::find()->where(['uid'=>Yii::$app->user->id])->select('area_id')->all();
- if(!empty($list))
- {
- foreach ($list as $value)
- $datas[] =$value->area_id;
- $result = implode(",",$datas);
- }
- return $result;
- }
- }
|