1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/8
* Time: 11:24
*/
namespace common\models\psources;
use Yii;
class CoinLottery extends BaseActiveRecord
{
public static function tableName()
{
return 'coin_lottery';
}
public function beforeSave($instert)
{
if (parent::beforeSave($instert)) {
if ($this->isNewRecord) {
$this->create_time = Yii::$app->formatter->asTimestamp('now');
} else {
$this->update_time = Yii::$app->formatter->asTimestamp('now');
}
return true;
} else {
return false;
}
}
/**
* 获取指定日期最后的一条记录(stage max)
*/
public static function getMaxStage($date = '')
{
if(!$date){
$date = date('Y-m-d');
}
return self::find()->where(['date' => $date])->orderBy(['stage' => SORT_DESC])->one();
}
public static function addOneRecord($start_height,$last_lottery_height,$stage,$round,$start_date)
{
$coin_lottery = new self();
$coin_lottery->stage = $stage;
$coin_lottery->start_height = $start_height;
$coin_lottery->last_lottery_height = $last_lottery_height;
$coin_lottery->status = 2;
$coin_lottery->round = $round;
$coin_lottery->date = $start_date;
$coin_lottery->save();
}
/**
* @return array|null|\yii\db\ActiveRecord
* 获取最新记录
*/
public static function getLastRecord()
{
return self::find()->orderBy(['id' => SORT_DESC])->asArray()->one();
}
}