127 lines
3.1 KiB
PHP
127 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-12-2
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\api\models;
|
|
|
|
use function AlibabaCloud\Client\value;
|
|
use app\models\Coach;
|
|
use app\models\Goods;
|
|
use app\models\Store;
|
|
use app\models\User;
|
|
use app\components\auth\AToken;
|
|
use app\components\EncryptHelper;
|
|
use app\models\UserInformation;
|
|
use app\modules\api\components\ApiHelper;
|
|
use yii\data\Pagination;
|
|
|
|
|
|
class UserModifyForm extends ApiModel
|
|
{
|
|
|
|
public $cx_mch_id;
|
|
// public $user_id;
|
|
public $real_name;
|
|
public $mobile_phone;
|
|
public $gender;
|
|
public $is_view;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
|
|
[['real_name'], 'required'],
|
|
[['gender'], 'required'],
|
|
[['is_view'], 'required'],
|
|
[['mobile_phone'], 'required'],
|
|
[['mobile_phone'], 'filter', 'filter' => 'trim'],
|
|
[['mobile_phone'], 'match', 'pattern' => '/^[1][34578][0-9]{9}$/'],
|
|
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'mobile_phone' => '手机号',
|
|
'real_name' => '姓名',
|
|
'gender' => '性别',
|
|
'is_view' => '鞋码',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 会员注册
|
|
*/
|
|
public function modify_user()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
|
|
|
|
$form = new LoginForm();
|
|
|
|
$user = User::findOne(['mobile_phone' => $this->mobile_phone]);
|
|
if (!empty($user->mobile_phone) && !empty($user->is_view)) {
|
|
$form = new LoginForm();
|
|
$form->cx_mch_id = 0;
|
|
$form->username = $user->username;
|
|
$form->password = '123456';
|
|
$form->token_type = 3;
|
|
return $form->login();
|
|
}
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
|
|
$username = User::generateUsername();
|
|
$password = '123456';
|
|
$password_encryption = \Yii::$app->security->generatePasswordHash($password);
|
|
|
|
|
|
$user = new User();
|
|
$user->cx_mch_id = 0;
|
|
$user->real_name = $this->real_name;
|
|
$user->mobile_phone = $this->mobile_phone;
|
|
$user->gender = $this->gender;
|
|
$user->is_view = $this->is_view;
|
|
$user->mobile_prefix = '86';
|
|
$user->nickname = $this->real_name;
|
|
$user->avatar_url = User::DEFAULT_AVATAR_URL;
|
|
$user->access_token = \Yii::$app->security->generateRandomString();
|
|
$user->type = User::TYPE_USER;
|
|
$user->username = $username;
|
|
$user->password = $password_encryption;
|
|
$user->auth_key = \Yii::$app->security->generateRandomString();;
|
|
|
|
if (!$user->save()) {
|
|
$t->rollBack();
|
|
return $this->getModelError($user);
|
|
}
|
|
$t->commit();
|
|
|
|
|
|
$form->username = $username;
|
|
$form->password = $password;
|
|
$data = $form->login();
|
|
|
|
|
|
return $data;
|
|
} catch (\Exception $e) {
|
|
$t->rollBack();
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '失败',
|
|
];
|
|
}
|
|
}
|
|
} |