Commit fb592e4c authored by rlgy's avatar rlgy

update

parent 1689a706
......@@ -62,6 +62,7 @@ class AdminController extends BaseController
$model->generateAuthKey();
$model->setPassword($data['password']);
$model->group = $role;
/* 保存用户数据到数据库 */
if ($model->save()) {
$auth = Yii::$app->authManager;
......@@ -142,6 +143,7 @@ class AdminController extends BaseController
$model->generateAuthKey();
$model->setPassword($data['password']);
$model->group = $role;
/* 保存用户数据到数据库 */
if ($model->save()) {
$auth = Yii::$app->authManager;
......
......@@ -42,6 +42,9 @@ class CoinController extends BaseController
$recommend = $recommend ? 1 : 0;
$condition[] = ['recommend' => $recommend];
}
if (Yii::$app->user->identity->group != 'administrator') {
$condition[] = ['group' => Yii::$app->user->identity->group];
}
$data = CoinBusiness::getList($page, $limit, $condition);
$data['code'] = 0;
//ajax return
......@@ -62,8 +65,10 @@ class CoinController extends BaseController
/**
* @var $coin \common\models\pwallet\Coin
*/
$coin = Yii::createObject(Coin::className());
$result = $coin->addOne($request->post());
$coin = Yii::createObject(Coin::className());
$data = array_merge($request->post(), ['group' => Yii::$app->user->identity->group]);
unset($data['id']);
$result = $coin->addOne($data);
if ($result === true) {
$this->success('添加成功', '/admin/coin/index');
}
......@@ -91,10 +96,16 @@ class CoinController extends BaseController
$req = Yii::$app->request;
Yii::$app->response->format = 'json';
if ($model->load($req->post()) && $model->validate()) {
$coin = Yii::createObject(Coin::className());
$result = $coin->updateOne($req->post());
if ($result === true) {
return ['code' => 0, 'msg' => 'succeed'];
$role = Yii::$app->user->identity->group;
if ('administrator' != $role) {
$coin = Coin::find()->select(['group'])->where(['id' => $req->post('id')])->one();
if ($role == $coin->group) {
$coin = Yii::createObject(Coin::className());
$result = $coin->updateOne($req->post());
if ($result === true) {
return ['code' => 0, 'msg' => 'succeed'];
}
}
}
}
$errors = $model->errors;
......
......@@ -78,6 +78,12 @@ class Coin extends BaseActiveRecord
*/
public function addOne($params)
{
$params = array_filter($params, function ($value) {
if (null == $value) {
return false;
}
return true;
});
$this->setAttributes($params, false);
try {
return (bool)$this->save();
......@@ -91,6 +97,12 @@ class Coin extends BaseActiveRecord
*/
public function updateOne($params)
{
$params = array_filter($params, function ($value) {
if (null == $value) {
return false;
}
return true;
});
if (isset($params['id']) && !empty($params['id'])) {
$coin = self::findOne(['id' => $params['id']]);
if ($coin === null) {
......
......@@ -35,7 +35,13 @@ class Admin extends \common\core\BaseActiveRecord
{
return [
[['username', 'password', 'salt'], 'required'],
[['username', 'password'], 'filter', 'filter' => function($str){ return HtmlPurifier::process($str); }],
[
['username', 'password'],
'filter',
'filter' => function ($str) {
return HtmlPurifier::process($str);
}
],
[['bind_uid', 'reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status'], 'integer'],
[['username'], 'string', 'max' => 32],
[['password'], 'string', 'min' => 6, 'max' => 60],
......@@ -44,23 +50,24 @@ class Admin extends \common\core\BaseActiveRecord
];
}
/**
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'uid' => 'Uid',
'bind_uid' => 'Bind Uid',
'username' => 'Username',
'password' => 'Password',
'salt' => 'Salt',
'reg_time' => 'Reg Time',
'reg_ip' => 'Reg Ip',
'uid' => 'Uid',
'bind_uid' => 'Bind Uid',
'username' => 'Username',
'password' => 'Password',
'salt' => 'Salt',
'reg_time' => 'Reg Time',
'reg_ip' => 'Reg Ip',
'last_login_time' => 'Last Login Time',
'last_login_ip' => 'Last Login Ip',
'update_time' => 'Update Time',
'status' => 'Status',
'last_login_ip' => 'Last Login Ip',
'update_time' => 'Update Time',
'status' => 'Status',
'group' => 'group'
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment