|
|
@@ -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;
|
|
|
}
|
|
|
}
|