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
<?php
namespace common\models\psources;
class CoinSupportedSymbol extends BaseActiveRecord
{
public static function tableName()
{
return '{{%coin_supported_symbol}}';
}
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->all();
return ['count' => $count, 'data' => $data, 'code' => 0];
}
public function addOne($params)
{
$params = array_filter($params, function ($value) {
if (null == $value) {
return false;
}
return true;
});
$this->setAttributes($params, false);
try {
return (bool)$this->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
// public function attributes()
// {
// return array_merge(parent::attributes(), ['code']);
// }
public function getCoinInfo()
{
return $this->hasOne(Coin::class, ['id' => 'currency']);
}
public function getBaseCurrencyInfo()
{
return $this->hasOne(Coin::class, ['id' => 'base_currency']);
}
}