66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\new;
|
|
|
|
use app\api\controller\BaseApiController;
|
|
use app\common\model\dict\DictData;
|
|
use app\common\model\user\User;
|
|
use app\common\service\ConfigService;
|
|
use think\facade\Config;
|
|
|
|
class UserController extends BaseApiController
|
|
{
|
|
|
|
|
|
public function register()
|
|
{
|
|
// 用户注册逻辑
|
|
$params = $this->request->param();
|
|
try {
|
|
// 手机号已被使用
|
|
$mobileUser = User::where(['account' => $params['account']])->find();
|
|
if (!empty($mobileUser)) {
|
|
self::setError('手机号已被注册');
|
|
return false;
|
|
}
|
|
// 生成用户编号
|
|
$userSn = User::createUserSn();
|
|
$passwordSalt = Config::get('project.unique_identification');
|
|
$password = create_password($params['password'], $passwordSalt);
|
|
|
|
if ($params['avatar'] != '') {
|
|
$avatar = $params['avatar'];
|
|
} else {
|
|
$avatar = ConfigService::get('default_image', 'user_avatar');
|
|
}
|
|
|
|
User::create([
|
|
'sn' => $userSn,
|
|
'avatar' => $avatar,
|
|
'is_captain' => $params['is_captain'],
|
|
'nickname' => $params['nickname'],
|
|
'account' => $params['account'],
|
|
'mobile' => $params['account'],
|
|
'id_card' => $params['id_card'],
|
|
'password' => $password,
|
|
'channel' => 0,
|
|
'sex' => $params['sex'],
|
|
'province' => $params['province'],
|
|
'city' => $params['city'],
|
|
'area' => $params['area'],
|
|
'street' => $params['street'],
|
|
'village' => $params['village'],
|
|
'brigade' => $params['brigade'],
|
|
'address' => $params['address'],
|
|
'qualification' => json_encode($params['qualification']),
|
|
'company_id' => $params['company_id'],
|
|
'group_id' => $params['group_id'],
|
|
]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
} |