request->get(); $page = $get['page'] ?? 1; $limit = $get['limit'] ?? 10; if (Yii::$app->request->isAjax) { Yii::$app->response->format = 'json'; $condition = []; $data = CoinTransfer::getList($page, $limit, $condition); return $data; } return $this->render('list'); } /** * 导入cvs */ public function actionLoadFile() { Yii::$app->response->format = 'json'; $file = UploadedFile::getInstanceByName('file'); try { $fd = fopen($file->tempName, 'r'); $data = []; while (($row = fgetcsv($fd)) !== false) { $data[] = $row; } if (ctype_digit($data[0][0])) { array_shift($data); } foreach ($data as $key => &$value){ $value[0] = trim($value[0]); $value[1] = trim($value[1]); } if ($data) { if (CoinTransfer::loadArray($data)) { return ['code' => 0, 'msg' => 'succeed']; } } return ['code' => 1, 'msg' => '数据为空']; } catch (\Exception $e) { return ['code' => $e->getCode(), 'msg' => $e->getMessage()]; } } public function actionBatchTransfer() { $model = CoinTransfer::find()->where(['status' => 0])->limit(30)->all(); foreach ($model as $val){ $id = $val->id; $to = $val->address; $amount = $val->amount * 1e8; $fee = 100000; $note = ''; $execer = 'user.p.tschain.coins'; $isExist = CoinTransfer::find()->where(['address' => $val->address, 'status' => 1])->one(); if($isExist) continue; $service = new Chain33Service(); $createRawTransaction = $service->createRawTransaction($to, $amount, $fee, $note, $execer); if(0 != $createRawTransaction['code']){ continue; } $txHex = $createRawTransaction['result']; $privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2'; $expire = '1m'; $signRawTx = $service->signRawTx($privkey, $txHex, $expire); if(0 != $signRawTx['code']){ continue; } $sign_str = $signRawTx['result']; $result = $service->sendTransaction($sign_str); if(0 != $result['code']){ continue; } $hash = $result['result']; $current_model = CoinTransfer::findOne($id); $current_model->hash = $hash; $current_model->status = 1; $current_model->save(); echo $val->address."-----".$hash."
"; } } }