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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
namespace api\controllers;
use common\models\psources\Coin;
use common\models\psources\CoinPlatformWithHold;
use common\service\chain33\Chain33Service;
use Yii;
use api\base\BaseController;
use common\models\psources\WalletChain;
use yii\data\Pagination;
class WalletChainController extends BaseController
{
/**
* h5发行链列表
* @param string wallet_address
* @return array
*/
public function actionChains()
{
if (!Yii::$app->request->isGet) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$params = Yii::$app->request->get();
$wallet_address = isset($params['wallet_address']) ? $params['wallet_address'] : '';
if (false == $wallet_address) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
$query = CoinPlatformWithHold::find()
->select('id, token, platform, status, create_time')
->where(['wallet_address' => $wallet_address])
->orderBy('id');
$model = $query->offset(($page - 1) * $size)->orderBy('create_time desc')->limit($size)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$this->data = [
'list' => $model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => $page,
]
];
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
/**
* h5发行链
* @param string platform
* @param string address
* @param string private_key
* @param string fee
* @param string token
* @param string host
* @param string port
* @param string wallet_address
* @param string hash
* @return array
*/
public function actionChain()
{
$request = Yii::$app->request;
$post = $request->post();
if ($request->isPost) {
$model = new CoinPlatformWithHold();
$model->setScenario(CoinPlatformWithHold::SCENARIOS_CREATE);
$params = [
'platform' => isset($post['platform']) ? $post['platform'] : '',
'address' => isset($post['address']) ? $post['address'] : '',
'private_key' => isset($post['private_key']) ? $post['private_key'] : '',
'token' => isset($post['token']) ? strtoupper($post['token']) : '',
'host' => isset($post['host']) ? $post['host'] : '',
'port' => isset($post['port']) ? $post['port'] : '',
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'status' => CoinPlatformWithHold::STATUS_UNPAID,
'origin' => CoinPlatformWithHold::ORIGIN_USER,
'fee' => isset($post['fee']) ? $post['fee'] : '',
'exer' => 'user.p.' . (isset($post['platform']) ? $post['platform'] : '')
];
if ($model->load($params, '') && !$model->validate()) {
$errors = '';
foreach ($model->errors as $error) {
$errors .= $error[0];
}
$this->msg = $errors;
$this->code = -1;
goto doEnd;
}
// $node_params = Yii::$app->params['para'];
// $service = new Chain33Service($node_params);
// $result = $service->addPara($params['platform'], $params['host'] . ':' . $params['port']);
// if (0 != $result['code']) {
// $this->code = $result['code'];
// $this->msg = $result['msg'];
// goto doEnd;
// }
$model->save();
$this->data = (int)Yii::$app->p_sources->getLastInsertID();
goto doEnd;
}
if ($request->isPut) {
$id = isset($post['id']) ? $post['id'] : 0;
$hash = isset($post['hash']) ? $post['hash'] : 0;
if (false == $id || false == $hash) {
$this->msg = '缺少必要的参数';
$this->code = -1;
goto doEnd;
}
$model = CoinPlatformWithHold::findOne($id);
if (empty($model)) {
$this->msg = '数据不存在';
$this->code = -1;
goto doEnd;
}
$model->setScenario(CoinPlatformWithHold::SCENARIOS_UPDATE);
$params = [
'id' => $id,
'hash' => $hash,
'status' => CoinPlatformWithHold::STATUS_CREATEING
];
if ($model->load($params, '') && !$model->save()) {
$errors = '';
foreach ($model->errors as $error) {
$errors .= $error[0];
}
$this->msg = $errors;
$this->code = -1;
goto doEnd;
}
$this->syncCoin(['platform' => $model['platform'], 'token' => $model['token']]);
}
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
/**
* h5发行链
* @param string wallet_address
* @return array
*/
public function actionDetail()
{
if (!Yii::$app->request->isGet) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$params = Yii::$app->request->get();
$id = isset($params['id']) ? $params['id'] : '';
if (false == $id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$model = CoinPlatformWithHold::find()->select('platform, token, address, private_key, fee, host, port, hash, status, create_time')->where(['id' => (int)$id])->asArray()->one();
if (empty($model)) {
goto doEnd;
}
$model['fee'] = $model['fee'] . $model['token'];
$model['charge'] = '10BTY';
$this->data = $model;
goto doEnd;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
public function syncCoin($params = [])
{
$model = new Coin();
$model->nickname = ['ja' => '', 'en-US' => '', 'zh-CN' => ''];
$model->name = $params['token'];
$model->platform = $params['platform'];
$model->chain = 'BTY';
$model->platform_id = 1;
$model->save();
}
}