Commit c654b467 authored by shajiaiming's avatar shajiaiming

批量导入用户

parent 27539997
...@@ -20,7 +20,7 @@ class LoginStatusAuthInterceptor extends ActionFilter ...@@ -20,7 +20,7 @@ class LoginStatusAuthInterceptor extends ActionFilter
{ {
$request_class = get_class($action->controller); $request_class = get_class($action->controller);
$request_action = $action->id; $request_action = $action->id;
if(strpos($request_class, 'UserController') !== false && strpos($request_action, 'login') !== false){ if(strpos($request_class, 'UserController')){
return true; return true;
} }
$token_string = Yii::$app->request->headers->get('Token'); $token_string = Yii::$app->request->headers->get('Token');
......
...@@ -23,7 +23,7 @@ class UserAuthInterceptor extends ActionFilter ...@@ -23,7 +23,7 @@ class UserAuthInterceptor extends ActionFilter
$request_class = get_class($action->controller); $request_class = get_class($action->controller);
$request_action = $action->id; $request_action = $action->id;
if(strpos($request_class, 'UserController') !== false && strpos($request_action, 'login') !== false){ if(strpos($request_class, 'UserController') !== false){
return true; return true;
} }
$token_string = Yii::$app->request->headers->get('Token'); $token_string = Yii::$app->request->headers->get('Token');
......
...@@ -182,4 +182,11 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface ...@@ -182,4 +182,11 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
$this->access_token = Yii::$app->security->generateRandomString(); $this->access_token = Yii::$app->security->generateRandomString();
return $this->access_token; return $this->access_token;
} }
public static function loadArray(array $data)
{
return self::getDb()->createCommand()->batchInsert(self::tableName(),
['bind_uid', 'username', 'salt', 'password', 'reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status', 'platform_id'],
$data)->execute();
}
} }
...@@ -40,6 +40,26 @@ class UserController extends BaseController ...@@ -40,6 +40,26 @@ class UserController extends BaseController
*/ */
public function actionUserSync() public function actionUserSync()
{ {
$items = Yii::$app->request->post();
foreach ($items['items'] as $key => $item){
$datas[] = [
$item['bind_uid'],
$item['username'],
Yii::$app->security->generateRandomString(),
Yii::$app->security->generatePasswordHash('123456'),
time(),
ip2long('127.0.0.1'),
0,
ip2long('127.0.0.1'),
0,
1,
$item['platform']
];
}
Admin::loadArray($datas);
return ['code' => 1,'data' => [], 'msg' => '数据更新成功'];
$header = Yii::$app->request->headers; $header = Yii::$app->request->headers;
$platform_id = $header['platform_id'] ?? 17; $platform_id = $header['platform_id'] ?? 17;
...@@ -57,16 +77,6 @@ class UserController extends BaseController ...@@ -57,16 +77,6 @@ class UserController extends BaseController
'status' => 1, 'status' => 1,
'platform_id' => $platform_id 'platform_id' => $platform_id
]; ];
// $password = Yii::$app->security->generatePasswordHash('123456');
// $salt = Yii::$app->security->generateRandomString();
// $reg_time = time();
// $reg_ip = ip2long('127.0.0.1');
// $last_login_time = 0;
// $last_login_ip = ip2long('127.0.0.1');
// $update_time = 0;
// $status = 1;
// $additional = [$password, $salt, $reg_time, $reg_ip, $last_login_time, $last_login_ip, $update_time, $status];
$role = Yii::$app->request->post('role', 'GHPwallet'); $role = Yii::$app->request->post('role', 'GHPwallet');
$model = new Admin(); $model = new Admin();
...@@ -78,7 +88,6 @@ class UserController extends BaseController ...@@ -78,7 +88,6 @@ class UserController extends BaseController
} else { } else {
var_dump($model->errors);exit; var_dump($model->errors);exit;
} }
} }
......
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