Parcourir la source

usermodel调整

zhangxiaobin il y a 1 an
Parent
commit
cb217cb00f

+ 8 - 1
application/api/controller/Test.php

@@ -137,6 +137,13 @@ class Test extends Api
         dump($sign);
     }
 
-
+/**
+ *
+ * @return void
+ */
+public function test1()
+{
+    echo '<pre>';var_dump(1);exit;
+}
 
 }

+ 7 - 0
application/api/controller/Usercenter.php

@@ -55,6 +55,13 @@ class UserCenter extends Common
         if (!empty($userInfo['pre_avatar']) && $userInfo['pre_avatar'] != $userInfo['avatar']) {
             $userInfo['avatar_status'] = 1;
         }
+        $userInfoA = $this->userModel->getAppendData($userInfo);
+        $userInfo['age_text'] = $userInfoA['age_text'];
+        $userInfo['constellation_text'] = $userInfoA['constellation_text'];
+        $userInfo['province_text'] = $userInfoA['province_text'];
+        $userInfo['city_text'] = $userInfoA['city_text'];
+        $userInfo['friends_num'] = $userInfoA['friends_num'];
+        $userInfo['look_num'] = $userInfoA['look_num'];
         // 获取技能信息
         $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
         $userInfo["skill"] = implode("/",$skillList);

+ 26 - 2
application/common/model/User.php

@@ -17,12 +17,12 @@ class User extends Model
     protected $updateTime = 'updatetime';
     // 追加属性
     protected $append = [
-        'age_text',
+        /*'age_text',
         'constellation_text',
         'province_text',
         'city_text',
         'friends_num',
-        'look_num',
+        'look_num',*/
     ];
 
     public function getAgeTextAttr($value, $data)
@@ -443,11 +443,35 @@ class User extends Model
 
         return $res;
     }
+
+    public function getAppendData(&$userInfo=[])
+    {
+        if (!empty($userInfo)) {
+            $userId = isset($userInfo['id']) ? $userInfo['id'] : 0;
+            $ageId = isset($userInfo['age_id']) ? $userInfo['age_id'] : 0;
+            $constellationId = isset($userInfo['constellation_id']) ? $userInfo['constellation_id'] : 0;
+            $provinceId = isset($userInfo['province_id']) ? $userInfo['province_id'] : 0;
+            $cityId = isset($userInfo['city_id']) ? $userInfo['city_id'] : 0;
+            $userInfo['age_text'] = $this->getAgeTextAttr(false,['age_id' => $ageId]);
+            $userInfo['constellation_text'] = $this->getConstellationTextAttr(false,['constellation_id' => $constellationId]);
+            $areaWhere['id'] = ['in',[$provinceId,$cityId]];
+            $areaData = Db::name('shopro_area')->where($areaWhere)->column('id,name');
+            $userInfo['province_text'] = isset($areaData[$provinceId]) ? $areaData[$provinceId] : '';
+            $userInfo['city_text'] = isset($areaData[$cityId]) ? $areaData[$cityId] : '';
+            $userInfo['friends_num'] = $this->getFriendsNumAttr(false,['id' => $userId]);
+            $userInfo['look_num'] = $this->getLookNumAttr(false,['id' => $userId]);
+        }
+        return $userInfo;
+    }
     
     public function age()
     {
         return $this->hasOne('Age', 'id', 'age_id',[],'LEFT');
     }
+    public function constellation()
+    {
+        return $this->hasOne('Constellation', 'id', 'constellation_id',[],'LEFT');
+    }
     public function useralipay()
     {
         return $this->hasOne('UserAlipay', 'user_id', 'id',[],'LEFT');