1
|
|
|
<?php |
2
|
|
|
class BackgroundController extends CronController |
3
|
|
|
{ |
4
|
|
|
public function actionFinishChallenges() |
5
|
|
|
{ |
6
|
|
|
$mc = new MaintenanceChallenge; |
7
|
|
|
$mc->fetchFinishable(); |
8
|
|
|
$mc->process(); |
9
|
|
|
|
10
|
|
|
echo 'ok'; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function actionReset() |
14
|
|
|
{ |
15
|
|
|
$mp = new MaintenancePlayer; |
16
|
|
|
|
17
|
|
|
$user = Yii::app()->request->getParam('user', 'x'); |
18
|
|
|
echo $user . '<br/>'; |
19
|
|
|
|
20
|
|
|
if ($user) { |
21
|
|
|
$mp->setUid($user); |
22
|
|
|
} |
23
|
|
|
$mp->reset(); |
24
|
|
|
|
25
|
|
|
$this->render('//site/dummy', ['log'=>$mp->log]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function actionContestStart($addPoints = 0) |
29
|
|
|
{ |
30
|
|
|
$contest = new Contest; |
31
|
|
|
if ($contest->activeId) { |
32
|
|
|
return true; |
33
|
|
|
} |
34
|
|
|
echo 'started, '; |
35
|
|
|
|
36
|
|
|
$contest->create(); |
37
|
|
|
|
38
|
|
|
if ($addPoints) { |
39
|
|
|
for ($i=0; $i<1000; $i++) { |
40
|
|
|
$contest->addPoints(rand(1981, 2100), Contest::ACT_MISSION, 1, 1, 1); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function actionContestStop() |
46
|
|
|
{ |
47
|
|
|
$contest = new Contest; |
48
|
|
|
if (time() > $contest->activeId + CONTEST::LIFETIME) { |
49
|
|
|
echo 'stopped:'. $contest->activeId; |
50
|
|
|
$contest->complete(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function actionContestStartStop($addPoints = 0) |
55
|
|
|
{ |
56
|
|
|
$this->actionContestStart($addPoints); |
57
|
|
|
$this->actionContestStop(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function actionNewLevelRevards() |
61
|
|
|
{ |
62
|
|
|
$res = Yii::app()->db->createCommand() |
63
|
|
|
->select('uid, routine') |
64
|
|
|
->from('visited') |
65
|
|
|
->where('routine >= 9') |
66
|
|
|
->order('uid') |
67
|
|
|
->queryAll(); |
68
|
|
|
$users = []; |
69
|
|
|
foreach ($res as $d) { |
70
|
|
|
//pay for gold routine |
71
|
|
|
@$users[$d['uid']]['gold'] += 30; |
|
|
|
|
72
|
|
|
@$users[$d['uid']]['r_gold']++; |
|
|
|
|
73
|
|
|
|
74
|
|
|
//pay for diamand |
75
|
|
|
if ($d['routine'] >= 81) { |
76
|
|
|
$users[$d['uid']]['gold'] += 70; |
77
|
|
|
@$users[$d['uid']]['r_diamant']++; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$log = print_r($users, true); |
82
|
|
|
$wall = new Wall(); |
83
|
|
|
foreach ($users as $uid => $award) { |
84
|
|
|
Yii::app()->db->createCommand("UPDATE main SET gold=gold+{$award['gold']} WHERE uid={$uid}")->execute(); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$wall->content_type = Wall::TYPE_NEW_AWARD; |
87
|
|
|
$wall->uid = $uid; |
88
|
|
|
$wall->add([ |
89
|
|
|
'award'=>$award['gold'], |
90
|
|
|
'r_gold'=>$award['r_gold'], |
91
|
|
|
'r_diamant'=>(int)@$award['r_diamant'] |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
$this->render('//site/dummy', ['log'=>$log]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: