|
|
@@ -139,24 +139,21 @@ class Member extends Api
|
|
|
* 绑定上级
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function bind()
|
|
|
+ public function bind(UserModel $userModel)
|
|
|
{
|
|
|
$mobile = $this->request->post('mobile'); // 手机号
|
|
|
$inviteCode = $this->request->post('inviteCode'); // 邀请码
|
|
|
if (empty($mobile) || empty($inviteCode)) $this->error(__('Invalid parameters'));
|
|
|
|
|
|
- $inviteCode = strtolower($inviteCode); // 转小写
|
|
|
- $msg = '';
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
// 不存在时注册
|
|
|
- $user = (new UserModel())->getByMobile($mobile);
|
|
|
+ $user = $userModel->getByMobile($mobile);
|
|
|
if (empty($user)) throw new Exception(__('账号不存在'));
|
|
|
|
|
|
// 尝试绑定上级
|
|
|
if (empty($user['parent_id'])) {
|
|
|
-
|
|
|
- $parent = (new UserModel())->getByAddress($inviteCode);
|
|
|
+ $parent = (substr($inviteCode, 0, 2) == '0x')? $userModel->getByAddress($inviteCode): $userModel->getByUid($inviteCode);
|
|
|
if (empty($parent)) throw new Exception(__('The invitation code is invalid, please manually bind your superior')) ;
|
|
|
// 创建网体
|
|
|
(new UserPathModel())->createPath($user['id'], $parent->id);
|