$v) { if (!isset($v['param']['ad_data_id'])) { continue; } $key = 'key_' . $up['time'] . '_' . $v['param']['ad_data_id']; if (!isset($update[$key])) { $update[$key] = array(); $update[$key]['time'] = $up['time']; $update[$key]['data_id'] = $v['param']['ad_data_id']; if (isset($v['param']['ad_info_id'])) { $update[$key]['info_id'] = $v['param']['ad_info_id']; } if (isset($v['param']['ad_page_id'])) { $update[$key]['page_id'] = $v['param']['ad_page_id']; } $update[$key]['year'] = $up['year']; $update[$key]['month'] = $up['month']; $update[$key]['day'] = $up['day']; $update[$key]['hour'] = $up['hour']; $update[$key]['pv_click'] = 0; $update[$key]['uv_click'] = 0; $update[$key]['pv_view'] = 0; $update[$key]['uv_view'] = 0; } if ($v['param']['project'] == 'ad_click') { $update[$key]['pv_click']++; $update[$key]['uv_click']++; } else { $update[$key]['pv_view']++; $update[$key]['uv_view']++; } } if ($update) { foreach ($update as $k => $v) { $this->update($v); } } } } private function update($data) { $where = array(); $where['data_id'] = $data['data_id']; $where['time'] = $data['time']; $info = Dever::db('ad/stat')->one($where); if (!$info) { Dever::db('ad/stat')->insert($data); } else { $data['where_id'] = $info['id']; if ($info['pv_click'] >= $data['pv_click']) { unset($data['pv_click']); } if ($info['uv_click'] >= $data['uv_click']) { unset($data['uv_click']); } if ($info['pv_view'] >= $data['pv_view']) { unset($data['pv_view']); } if ($info['uv_view'] >= $data['uv_view']) { unset($data['uv_view']); } Dever::db('ad/stat')->update($data); } } }