shish 11 maanden geleden
bovenliggende
commit
9768d409a4
2 gewijzigde bestanden met toevoegingen van 41 en 15 verwijderingen
  1. 15 15
      app-mall/controllers/UserController.php
  2. 26 0
      biz-mall/user/classes/UserClass.php

+ 15 - 15
app-mall/controllers/UserController.php

@@ -44,7 +44,7 @@ class UserController extends BaseController
         $floor = $post['floor'] ?? '';
         $fullAddress = $address . $floor;
         $post['fullAddress'] = $fullAddress;
-        UserClass::updateById($userId, $post);
+        UserClass::updateUserInfo($user, $post);
         util::complete();
     }
 
@@ -138,8 +138,8 @@ class UserController extends BaseController
     public function actionMiniFullInfo()
     {
         $post = Yii::$app->request->post();
-        $iv = isset($post['iv']) ? $post['iv'] : '';
-        $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
+        $iv = $post['iv'] ?? '';
+        $encryptedData = $post['encryptedData'] ?? '';
         $merchant = WxOpenClass::getMallWxMiniBase();
         $appId = $merchant['miniAppId'];
         $miniOpenId = $post['miniOpenId'];
@@ -186,7 +186,7 @@ class UserController extends BaseController
             util::fail('解密失败');
         }
         $arr = Json::decode($result);
-        $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
+        $mobile = $arr['purePhoneNumber'] ?? '';
         if (empty($mobile)) {
             util::fail('没有取到手机号,请重试');
         }
@@ -197,9 +197,9 @@ class UserController extends BaseController
     public function actionPassword()
     {
         $post = Yii::$app->request->post();
-        $old = isset($post['old']) ? $post['old'] : '';
-        $new = isset($post['new']) ? $post['new'] : '';
-        $confirm = isset($post['confirm']) ? $post['confirm'] : '';
+        $old = $post['old'] ?? '';
+        $new = $post['new'] ?? '';
+        $confirm = $post['confirm'] ?? '';
         if (empty($new)) {
             util::fail('请输入新密码');
         }
@@ -212,7 +212,7 @@ class UserController extends BaseController
             if (empty($old)) {
                 util::fail('请填写旧密码');
             }
-            if (password_verify($old, $user['payPassword']) == false) {
+            if (!password_verify($old, $user['payPassword'])) {
                 util::fail('旧密码错误');
             }
         }
@@ -224,8 +224,8 @@ class UserController extends BaseController
     public function actionApplyMember()
     {
         $post = Yii::$app->request->post();
-        $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
-        if (stringUtil::isMobile($mobile) == false) {
+        $mobile = $post['mobile'] ?? 0;
+        if (!stringUtil::isMobile($mobile)) {
             util::fail('请输入手机号');
         }
         $userId = $this->userId;
@@ -233,16 +233,16 @@ class UserController extends BaseController
         if (isset($asset['member']) && $asset['member'] != -1) {
             util::fail('已经是会员了');
         }
-        $code = isset($post['code']) ? $post['code'] : '';
+        $code = $post['code'] ?? '';
         $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
         if (empty($cacheCode) || $cacheCode != $code) {
             util::fail('验证码错误');
         }
         $update = [];
-        if (isset($post['realName']) && !empty($post['realName'])) {
+        if (!empty($post['realName'])) {
             $update['realName'] = $post['realName'];
         }
-        if (isset($post['birthday']) && !empty($post['birthday'])) {
+        if (!empty($post['birthday'])) {
             $update['birthday'] = $post['birthday'];
         }
         $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]);
@@ -253,7 +253,7 @@ class UserController extends BaseController
             util::fail('手机号已经注册过了');
         }
         $update['mobile'] = $mobile;
-        $userInfo = isset($this->user->attributes) ? $this->user->attributes : [];
+        $userInfo = $this->user->attributes ?? [];
         UserService::becomeMember($userInfo, $this->sj->attributes, $update);
         util::complete('注册成功');
     }
@@ -261,7 +261,7 @@ class UserController extends BaseController
     //登陆客户的信息 ssh 2020.3.12
     public function actionLoginDetail()
     {
-        $user = isset($this->user->attributes) ? $this->user->attributes : [];
+        $user = $this->user->attributes ?? [];
         util::success($user);
     }
 

+ 26 - 0
biz-mall/user/classes/UserClass.php

@@ -57,6 +57,32 @@ class UserClass extends BaseClass
         'system' => ['id' => 5, 'name' => 'system'],
     ];
 
+    public static function updateUserInfo($user, $data)
+    {
+        $userId = $user->id ?? 0;
+        UserClass::updateById($userId, $data);
+
+        //更新客户相关信息
+        if (isset($data['name'])) {
+            $originName = $user->name ?? '';
+            $newName = $data['name'];
+            if ($originName != $newName) {
+                $customList = CustomClass::getAllByCondition(['userId' => $userId], null, '*', null, true);
+                if (!empty($customList)) {
+                    foreach ($customList as $custom) {
+                        if ($custom->originName == $custom->name) {
+                            $custom->originName = $newName;
+                            $custom->name = $newName;
+                            $custom->save();
+                        }
+                    }
+                }
+            }
+            unset($data['name']);
+        }
+        CustomClass::updateByCondition(['userId' => $userId], $data);
+    }
+
     //组合客户基本和资产信息
     public static function groupUserBaseInfo($list)
     {