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
65
66
67
68
69
70
71
72
73
74
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinAirDropTransfer extends BaseActiveRecord
{
const ORIGIN_IMPORT = 1;
const ORIGIN_ADD = 2;
const ORIGIN_API = 3;
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_airdrop_transfer}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules() {
return [
[['to_address', 'amount', 'coin_name'], 'required','message'=>"请输入{attribute}"],
[['origin', 'txhash', 'msg', 'balance'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'to_address' => '钱包地址',
'amount' => '数量',
'coin_name' => '币种名称',
'origin' => '来源',
'txhash' => '返回hash',
'msg' => '返回结果',
'balance' => '钱包余额',
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['to_address', 'amount','coin_name', 'origin'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
public static function loadArray(array $data)
{
return self::getDb()->createCommand()->batchInsert(self::tableName(),
['to_address', 'coin_name', 'amount', 'origin', 'txhash', 'msg', 'balance'],
$data)->execute();
}
public static function getOrigin()
{
return [
self::ORIGIN_IMPORT => '批量导入',
self::ORIGIN_ADD => '单独添加',
self::ORIGIN_API => '接口导入',
];
}
}