|
|
@ -8,9 +8,11 @@ use common\models\CarLogT; |
|
|
|
use common\models\OrderGiftT; |
|
|
|
use common\models\OrderGiftT; |
|
|
|
use common\models\OrderT; |
|
|
|
use common\models\OrderT; |
|
|
|
use common\models\OrderUserT; |
|
|
|
use common\models\OrderUserT; |
|
|
|
|
|
|
|
use common\models\PermissionsT; |
|
|
|
use common\models\SendLogT; |
|
|
|
use common\models\SendLogT; |
|
|
|
use common\models\UserT; |
|
|
|
use common\models\UserT; |
|
|
|
use Yii; |
|
|
|
use Yii; |
|
|
|
|
|
|
|
use yii\db\Exception; |
|
|
|
use yii\web\Response; |
|
|
|
use yii\web\Response; |
|
|
|
use yii\web\UploadedFile; |
|
|
|
use yii\web\UploadedFile; |
|
|
|
use yii\helpers\Json; |
|
|
|
use yii\helpers\Json; |
|
|
@ -831,4 +833,73 @@ class ApiController extends \yii\web\Controller |
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
return $result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function actionRegister(){ |
|
|
|
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
|
|
|
|
|
|
|
$request = Yii::$app->request; |
|
|
|
|
|
|
|
$result = array( |
|
|
|
|
|
|
|
'code' => 0, |
|
|
|
|
|
|
|
'msg' => '请求成功', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$name = trim($request->get('name','')); |
|
|
|
|
|
|
|
$mobile = trim($request->get('mobile','')); |
|
|
|
|
|
|
|
$user = UserT::findOne(['name' => $name, 'phone' => $mobile]); |
|
|
|
|
|
|
|
if($name == '' || !preg_match_all("/^1[345789]\d{9}$/", $mobile)){ |
|
|
|
|
|
|
|
$result['code'] = -1; |
|
|
|
|
|
|
|
$result['msg'] = '参数错误'; |
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if($user) { |
|
|
|
|
|
|
|
$user->password = MyLib::hashPwd('123456',$user->salt); |
|
|
|
|
|
|
|
if(!$user->save()){ |
|
|
|
|
|
|
|
$result['code'] = -1; |
|
|
|
|
|
|
|
$result['msg'] = '保存失败:'.json_encode($user->getErrors()); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$result['data'] = [ |
|
|
|
|
|
|
|
'username' => $user->username, |
|
|
|
|
|
|
|
'password' => '123456', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$user = new UserT(); |
|
|
|
|
|
|
|
$user->username = 'Y'.substr($mobile,-6); |
|
|
|
|
|
|
|
$user->salt = MyLib::randomStr(4); |
|
|
|
|
|
|
|
$user->password = MyLib::hashPwd('123456',$user->salt); |
|
|
|
|
|
|
|
$user->name = $name; |
|
|
|
|
|
|
|
$user->phone = $mobile; |
|
|
|
|
|
|
|
$user->group_id = 12; |
|
|
|
|
|
|
|
$user->is_locked = 0; |
|
|
|
|
|
|
|
$user->is_login = 1; |
|
|
|
|
|
|
|
$user->is_outer = 1; |
|
|
|
|
|
|
|
$user->is_send = 1; |
|
|
|
|
|
|
|
$user->phone_server_id = 0; |
|
|
|
|
|
|
|
$user->role_id = 4; |
|
|
|
|
|
|
|
$user->worktype_id = 0; |
|
|
|
|
|
|
|
$user->is_leave = 0; |
|
|
|
|
|
|
|
$user->is_double = 0; |
|
|
|
|
|
|
|
$permission_info = PermissionsT::findOne(['id' => 26]); |
|
|
|
|
|
|
|
$tran = UserT::getDb()->beginTransaction(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (!$user->save()) { |
|
|
|
|
|
|
|
throw new Exception(json_encode($user->getErrors())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//处理权限 |
|
|
|
|
|
|
|
$user->unlinkAll('permissions', true); |
|
|
|
|
|
|
|
$user->link('permissions', $permission_info); |
|
|
|
|
|
|
|
//处理菜单 |
|
|
|
|
|
|
|
$user->unlinkAll('menus', true); |
|
|
|
|
|
|
|
foreach ($permission_info->menus as $item) { |
|
|
|
|
|
|
|
$user->link('menus', $item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$content = "游客{$name}(${mobile})注册"; |
|
|
|
|
|
|
|
Yii::$app->runAction('new_controller/new_action', $user->id, $content); |
|
|
|
|
|
|
|
$tran->commit(); |
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
$tran->rollBack(); |
|
|
|
|
|
|
|
$result['code'] = -1; |
|
|
|
|
|
|
|
$result['msg'] = $e->getMessage(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|