调试注册接口

webUi^2
zhaocheng 5 years ago
parent d0b304ee18
commit 1831735a38
  1. 22
      frontend/controllers/ApiController.php

@ -10,6 +10,7 @@ use common\models\OrderT;
use common\models\OrderUserT;
use common\models\PermissionsT;
use common\models\SendLogT;
use common\models\UserLogT;
use common\models\UserT;
use Yii;
use yii\db\Exception;
@ -834,6 +835,10 @@ class ApiController extends \yii\web\Controller
return $result;
}
/**
* 游客注册接口
* @return array
*/
public function actionRegister(){
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
@ -841,10 +846,10 @@ class ApiController extends \yii\web\Controller
'code' => 0,
'msg' => '请求成功',
);
$name = trim($request->get('name',''));
$mobile = trim($request->get('mobile',''));
$name = trim($request->post('name',''));
$mobile = trim($request->post('mobile',''));
$user = UserT::findOne(['name' => $name, 'phone' => $mobile]);
if($name == '' || !preg_match_all("/^1[345789]\d{9}$/", $mobile)){
if($name == '' || !preg_match('/^1[345789]\d{9}$/', $mobile)){
$result['code'] = -1;
$result['msg'] = '参数错误';
return $result;
@ -881,7 +886,7 @@ class ApiController extends \yii\web\Controller
$tran = UserT::getDb()->beginTransaction();
try {
if (!$user->save()) {
throw new Exception(json_encode($user->getErrors()));
throw new \Exception(json_encode($user->getErrors()));
}
//处理权限
$user->unlinkAll('permissions', true);
@ -891,8 +896,13 @@ class ApiController extends \yii\web\Controller
foreach ($permission_info->menus as $item) {
$user->link('menus', $item);
}
$content = "游客{$name}(${mobile})注册";
Yii::$app->runAction('new_controller/new_action', $user->id, $content);
$user_log_info = new UserLogT();
$user_log_info->user_id = $user->id;
$user_log_info->content = "游客{$name}(${mobile})注册";
$user_log_info->ip = MyLib::getIP();
if(!$user_log_info->save()){
throw new \Exception(json_encode($user_log_info->getErrors()));
}
$tran->commit();
} catch (\Exception $e) {
$tran->rollBack();

Loading…
Cancel
Save