shish hace 11 meses
padre
commit
a0bb243bb1
Se han modificado 2 ficheros con 12 adiciones y 5 borrados
  1. 1 0
      biz-hd/custom/classes/CustomClass.php
  2. 11 5
      biz-hd/message/services/ChatService.php

+ 1 - 0
biz-hd/custom/classes/CustomClass.php

@@ -759,6 +759,7 @@ class CustomClass extends BaseClass
             $avatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_800,w_800";
             $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
             $bigAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            $list[$key]['shortAvatar'] = $shortAvatar;
             $list[$key]['avatar'] = $avatar;
             $list[$key]['smallAvatar'] = $smallAvatar;
             $list[$key]['bigAvatar'] = $bigAvatar;

+ 11 - 5
biz-hd/message/services/ChatService.php

@@ -8,6 +8,7 @@ use bizHd\message\classes\ChatClass;
 use bizHd\user\classes\UserClass;
 use bizHd\user\services\UserService;
 use common\components\arrayUtil;
+use common\components\imgUtil;
 use Yii;
 
 class ChatService extends BaseService
@@ -190,8 +191,13 @@ class ChatService extends BaseService
         $ids = array_column($arr, 'cId');
         $infoList = CustomClass::getByIds($ids, null, null, 'id,name,mobile,avatar,shopId,userId');
         foreach ($infoList as $customId => $info) {
-            $infoList[$customId]['unReadNum'] = isset($userData[$info['id']]['unReadNum']) ? $userData[$info['id']]['unReadNum'] : 0;
-            $infoList[$customId]['chatTime'] = isset($userData[$info['id']]['time']) ? $userData[$info['id']]['time'] : 0;
+            $infoList[$customId]['unReadNum'] = $userData[$info['id']]['unReadNum'] ?? 0;
+            $infoList[$customId]['chatTime'] = $userData[$info['id']]['time'] ?? 0;
+            //头像
+            $shortAvatar = $info['avatar'] ?? '';
+            $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $infoList[$customId]['shortAvatar'] = $shortAvatar;
+            $infoList[$customId]['smallAvatar'] = $smallAvatar;
         }
         $infoList = arrayUtil::arraySort($infoList, 'chatTime', SORT_DESC);
         return array_values($infoList);
@@ -228,7 +234,7 @@ class ChatService extends BaseService
      * @param string $unit 单位分:个数(person)消息(message)
      * @return int
      */
-    public static function getUnReadMsgCount($shopId, $unit='person')
+    public static function getUnReadMsgCount($shopId, $unit = 'person')
     {
         $cacheKey = ChatClass::getLatestUsersKey($shopId);
         //返回有序集合,从高分到低分排序
@@ -255,9 +261,9 @@ class ChatService extends BaseService
             $unReadNum = intval($decimalPart * 10000 + 0.5); // 加0.5 -- 使用四舍五入来处理浮点数精度问题
 
             //根据未读消息数的单位进行计算总数
-            if ($unit == 'person'){
+            if ($unit == 'person') {
                 $msgCount += ($unReadNum >= 1 ? 1 : 0);
-            } else if ($unit == 'message'){
+            } else if ($unit == 'message') {
                 $msgCount += $unReadNum;
             }
         }