| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace backend\models;
- use Yii;
- /**
- *
- * This is the model class for table "{{%admin_role}}".
- *
- * @property int $id
- * @property int $role_id 角色id
- * @property int $admin_id 账号id
- * @property int|null $created_at 添加时间
- * @property int|null $updated_at 修改时间
- */
- class AdminRole extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%admin_role}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['role_id', 'admin_id', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'role_id' => 'Role ID',
- 'admin_id' => 'Admin ID',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(array $post){
- try{
- if(!empty($post['id'])){
- $model = self::findOne(['id' => $post['id']]);
- if(empty($model)) throw new \Exception('服务不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- isset($post['role_id']) && $model->role_id = $post['role_id'];
- isset($post['admin_id']) && $model->admin_id = $post['admin_id'];
- $res = $model->save();
- if($res === false) throw new \Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|