deleteExpireBehaviorDelta($six_month_ago); //统计今日增量 $today = date('Y-m-d'); $today_data = $obj->getBehaviorByDate($today); $today_data = array_column($today_data, null, 'wid'); $yesterday = date('Y-m-d', strtotime('-1 day')); $yesterday_data = $obj->getBehaviorByDate($yesterday); $yesterday_data = array_column($yesterday_data, null, 'wid'); if (empty($yesterday_data)) return true; foreach ($today_data as $k => $v) { $yesterday_reposts_count = 0; $yesterday_comments_count = 0; $yesterday_attitudes_count = 0; if (isset($yesterday_data[$k])) { $yesterday_reposts_count = $yesterday_data[$k]['reposts_count']; $yesterday_comments_count = $yesterday_data[$k]['comments_count']; $yesterday_attitudes_count = $yesterday_data[$k]['attitudes_count']; } $delta = array( 'uid' => $v['uid'], 'wid' => $v['wid'], 'reposts_delta' => $v['reposts_count'] - $yesterday_reposts_count, 'comments_delta' => $v['comments_count'] - $yesterday_comments_count, 'attitudes_delta' => $v['attitudes_count'] - $yesterday_attitudes_count, 'date' => $v['date'], ); $res = $obj->saveBehaviorDelta($delta); if (!$res) { $this->writeLog('spider', 'insert_error.log', json_encode($delta)); } } return true; } } new spiderBehaviorDelta();