xiaogang 3 лет назад
Родитель
Сommit
7002408912
1 измененных файлов с 28 добавлено и 23 удалено
  1. 28 23
      app/Services/DynamicService.php

+ 28 - 23
app/Services/DynamicService.php

xqd
@@ -137,39 +137,44 @@ class DynamicService
         DynamicModel::create($data);
 
         //推送消息
+        $push_users = [];
         if($user->sex==1){
             $push_users = User::query()->where(['notice_status'=>1,'sex'=>2])->whereNotNull('registrationId')->get(['id','registrationId'])->toArray();
         }elseif($user->sex==2){
             $push_users = User::query()->where(['notice_status'=>1,'sex'=>1])->whereNotNull('registrationId')->get(['id','registrationId'])->toArray();
         }
 
-        $registrationIds = array_column($push_users,'registrationId');
+        if(!empty($push_users)){
+            $registrationIds = array_column($push_users,'registrationId');
 
-        $user_info = UserInfoModel::query()->where('user_id',$user->id)->first();
+            $user_info = UserInfoModel::query()->where('user_id',$user->id)->first();
 
-        //设置推送的图标
-        if(count($dynamicParam->img_url)>0){
-            $image = ($dynamicParam->img_url)[0];
-        }else{
-            $image = $user_info->avatar;
-        }
+            //设置推送的图标
+            if(count($dynamicParam->img_url)>0){
+                $image = ($dynamicParam->img_url)[0];
+            }else{
+                $image = $user_info->avatar;
+            }
 
 
-        JPushService::pushNotify([
-            //标题
-            'title' => "@".$user_info->nickname."发布了新动态,来打个招呼吧~",
-            //内容
-            'content' => $dynamicParam->content,
-            //设备标识,跟设备相关
-            'reg_id' => $registrationIds,
-            'image' => $image,
-            //扩展字段
-            'extras' => [
-                'type' => 'notice',
-            ],
-            //推送类型
-            'type' => JPushService::PUSH_TYPE_REG_ID,
-        ]);
+            JPushService::pushNotify([
+                //标题
+                'title' => "@".$user_info->nickname."发布了新动态,来打个招呼吧~",
+                //内容
+                'content' => $dynamicParam->content,
+                //设备标识,跟设备相关
+                'reg_id' => $registrationIds,
+                'image' => $image,
+                //扩展字段
+                'extras' => [
+                    'type' => 'notice',
+                ],
+                //推送类型
+                'type' => JPushService::PUSH_TYPE_REG_ID,
+            ]);
+
+        }
+
 
 
         return true;