把这段代码变成批量插入数据库和批量更新数据库 
  while (true) {
            $ad = RedisDB::get_lPop(self::FB_CAMPAIGN_RDS);            
            if(!$ad) break;
            if(!empty($ad['errNum']) && $ad['errNum'] >= 3){
                log_message('error','重新执行3次未成功:'.json_encode($ad));
                continue;
            }
            // 时间
            $starTime = date('Y-m-d',strtotime($ad['start_time']));
            $endTime = date('Y-m-d',strtotime('-1 day', time()));
            
            // 请求参数拼接
            $url = self::JAVA_URL."/fb/campaign/".$ad['campaign_id']."/insights";
            $header = ['t:'.self::JAVA_TOKEN];
            $params = array(
                'id' => $ad['campaign_id'],
                'accessToken' => $this->access_token,
                'insights'    => [
                    "fields"  => 'account_id,campaign_id,adset_id,ad_id,account_name,campaign_name,adset_name,ad_name,impressions,clicks,spend,reach,actions,unique_actions,unique_outbound_clicks',
                    "time_range" => ["since"=>$starTime,"until"=>$endTime],
                    "reqAll"  => true,
                    "time_increment" => 1,
                    "level"   => 'campaign',
                    'breakdowns' => $ad['type'] == 2 ? 'country' : '',
                    'use_unified_attribution_setting' => true,
                ],
            );            
            // 请求中台数据
            $infoJson = _curl_post_json($url,$params,$header[0]);
            $info = json_decode($infoJson,true);
            // 报错处理
            if($info['code'] != 200){
                log_message('error','请求java失败，错误信息：'.$infoJson);
                $errContent = json_decode($info['content'],true);
                if($errContent['error']['code'] == 4 || $errContent['error']['code'] == 80000){
                    $ad['errNum'] += 1;
                    log_message('error','广告系列请求数据量过大，重新插入队列'.json_encode($ad));
                    // sleep(300);
                    RedisDB::rpush(self::FB_CAMPAIGN_RDS,serialize($ad));
                }                
                continue;
            }
            if(count($info['content']) == 0){
                continue;
            }

            foreach ($info['content'] as $content) {
                $unique_actions = array_column($content['unique_actions'],'value','action_type');                
                $actions = array_column($content['actions'],'value','action_type');
                $unique_outbound_clicks = array_column($content['unique_outbound_clicks'],'value','action_type');
                // 月份
                $month = date("Ym",strtotime($content['date_start']));
                // 类型
                if($ad['isExcel'] != 1){
                    $name = explode('_',$content['campaign_name']);
                    $type = strtolower($name[3]) == 'new' ? 2 : 1;                    
                }
                $insert[$month][] = [
                    'biz_date'          => date("Ymd",strtotime($content['date_start'])),
                    'type'              => $type ?? 3,
                    'report_rule_id'    => $ad['rule_id'],
                    'account_id'        => $content['account_id'],
                    'account_name'      => $content['account_name'],
                    'campaign_id'       => $content['campaign_id'],
                    'campaign_name'     => strtolower($content['campaign_name']),
                    'country'           => $content['country'] ?? '',
                    'adset_id'          => $content['adset_id'] ?? '',
                    'adset_name'        => $content['adset_name'] ? strtolower($content['adset_name']) : '',
                    'ad_id'             => $content['ad_id'] ?? '',
                    'ad_name'           => $content['ad_name'] ? strtolower($content['ad_name']) : '',
                    'impression'        => $content['impressions']  ?? 0,
                    'clicks'            => $content['clicks']  ?? 0,
                    'uo_click'          => $unique_outbound_clicks['outbound_click']  ?? 0,
                    'spend'             => $content['spend']  ?? 0,
                    'link_click'        => $actions['link_click']  ?? 0,
                    'reach'             => $content['reach'] ?? 0,
                    'install'           => $actions['mobile_app_install'] ?? 0,
                    'unique_purchases'  => $unique_actions['omni_purchase'] ?? 0,
                ];
                // name补充
                $upd[$month] = [
                    'account_id'    => $content['account_id'],
                    'ad_name'       => $content['ad_name'],
                    'adset_name'    => $content['adset_name'],
                    'campaign_name' => $content['campaign_name'],
                    'account_name'  => $content['account_name'],
                ];
            }            
            if (!empty($insert)) {
                // 关闭再重启mysql
                $this->MonthDb_Z->db->close();
                $this->MonthDb_Z->db->initialize();
                $monthDb = $this->MonthDb_Z;                
                foreach ($insert as $month => $add) {
                    $monthTable = $this->lk_ksh_fb.$month;
                    $monthDb->is_kshFbMonth_table($monthTable);
                    $monthDb->delete($monthTable, [
                        'biz_date >='    => date("Ymd", strtotime($starTime)),
                        'biz_date <='    => date("Ymd", strtotime($endTime)),
                        'report_rule_id' => $ad['rule_id'],
                        'campaign_id'    => $ad['campaign_id']
                    ]);
                    $monthDb->add_batch($monthTable, $add);
                }
            }
            if(!empty($upd)){
                // 关闭再重启mysql
                $this->MonthDb_Z->db->close();
                $this->MonthDb_Z->db->initialize();
                $monthDb = $this->MonthDb_Z;
                foreach ($upd as $month => $update) {
                    $monthTable = $this->lk_ksh_excel.$month;
                    if(!$monthDb->is_table($monthTable)){
                        continue;
                    }
                    $monthDb->update($monthTable,['campaign_id'=>$ad['campaign_id']],$update);
                }
            }
            unset($insert,$upd);
        }