| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | <?phpnamespace Ad\Lib;use Dever;class Cron{	public function run($data)	{		$source = $data[0];		$desc = $data[1];		$up = $data[2];		if ($desc) {			$update = array();			foreach ($desc as $k => $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'];			Dever::db('ad/stat')->update($data);		}	}}
 |