public function actionDataHistory() { if (Yii::$app->request->isAjax) { $serviceClient = new Client(); $response = $serviceClient->getContent('http://sports.williamhill.com/bet/en-gb/betting/y/5/tm/Football.html'); $parser = new Parser(); $dataLive = $parser->run($response); if (!History::saveInHistory($dataLive)) { $dataHistory = []; } else { $dataHistory = History::find()->orderBy('date DESC')->limit(15)->all(); } echo $this->renderPartial('table', ['dataHistory' => $dataHistory]); exit; } }
public function actionDelete($seed_id, $reason = "", $penalty = 0) { if (!is_numeric($penalty) || !is_numeric($seed_id)) { return ['result' => 'failed', 'extra' => 'illegal param']; } $penalty = intval($penalty); $seed_id = intval($seed_id); /** @var User $user */ $user = User::findOne(Yii::$app->user->identity->getId()); if ($user->priv != 'Admin') { return ['result' => 'failed', 'extra' => 'permission denied']; } /** @var Seed $seed */ $seed = Seed::findOne($seed_id); if (empty($seed) || !$seed->is_valid) { return ['result' => 'failed', 'extra' => 'not exists']; } $ret['result'] = 'success'; $publisher = $seed->publisher; $record = new SeedOperationRecord(); $record->admin_id = $user->user_id; $record->publisher_id = $publisher->user_id; $record->seed_id = $seed->seed_id; $record->operation_type = "DELETE"; $record->detail_info = json_encode(['penalty' => $penalty, 'reason' => $reason]); $record->insert(); $seed->is_valid = false; $seed->save(); $publisher->stat_up -= intval($penalty) * (1 << 30); $publisher->save(); $tmp = $seed->attributes; $tmp['discuz_pub_uid'] = $publisher->discuz_user_id; //查询所有下载过这个种子的人 $res = History::find()->leftJoin(User::tableName(), User::tableName() . '.user_id=' . History::tableName() . ".user_id")->where(['seed_id' => $seed->seed_id])->groupBy([History::tableName() . ".user_id", "history_id"])->all(); Yii::info($res); foreach ($res as $r) { $tmp['discuz_use_uid'][] = $r->user->discuz_user_id; } $ret['extra'] = $tmp; Yii::info($ret); return $ret; }
/** * @return \yii\db\ActiveQuery */ public function getHistories() { return $this->hasMany(History::className(), ['seed_id' => 'seed_id']); }
public function actionHistory() { History::deleteAll(); SeedEvent::deleteAll(); $offset = 0; $limit = 1000; QUERY: $sql = <<<SQL SELECT * FROM `ngpt_ngpt_history` LIMIT {$limit} OFFSET {$offset}; SQL; $res = $this->fdb->createCommand($sql)->queryAll(); foreach ($res as $ohis) { $his = new History(); $his->record_date = $this->date($ohis['lastupdate']); /** @var User $user */ $user = User::findOne(['discuz_user_id' => $ohis['uid']]); /** @var Seed $seed */ $seed = Seed::findOne(['info_hash' => strtoupper($ohis['infohash'])]); if (!$seed) { continue; } $his->user_id = $user->user_id; $his->seed_id = $seed->seed_id; $his->stat_up = $ohis['uploaded']; $his->stat_down = $ohis['downloaded']; $his->real_up = $ohis['realup']; $his->real_down = $ohis['realdown']; $seed_event = new SeedEvent(); $seed_event->user_id = $user->user_id; $seed_event->seed_id = $seed->seed_id; $seed_event->event_type = 'Downloaded'; $res = $his->insert() && $seed_event->insert(); if (!$res) { var_dump($his->errors); var_dump($seed_event->errors); return; } var_dump($his->attributes); var_dump($seed_event->attributes); } if (count($res)) { $offset += $limit; goto QUERY; } return; }