request; if (!$request->isPost) { $msg = '请求错误!'; goto doEnd; } $post = $request->post(); if (2 != count($post['txs'])) { $msg = '交易笔数错误!'; goto doEnd; } $data['is_with_draw'] = $post['isWithdraw']; $data['address'] = $post['address']; $data['transfer_number'] = date('YmdHis') . self::getrandnums(); $model = CoinCrossChain::find()->where(['address' => $post['address'], 'current_step' => CoinCrossChain::STEP_DEFAULT, 'is_with_draw' => CoinCrossChain::RECHARGE])->one(); if ($model) { $msg = '存在未完成的交易!'; goto doEnd; } $model = new CoinCrossChain(); foreach ($post['txs'] as $key => $val) { if (1 == $val['step']) { $seq = 'first'; } else if (2 == $val['step']) { $seq = 'second'; } else { $seq = 'first'; } $data['txhex_' . $seq] = $val['tx']; $data['transfer_url_' . $seq] = $val['url']; } $model->setScenario(CoinCrossChain::SCENARIOS_CREATE); if ($model->load($data, '') && $model->save()) { $msg = 'success'; $code = 0; } else { $msg = current($model->firstErrors); } doEnd : return ['code' => $code, 'msg' => $msg]; } public function actionTransferStatus() { $code = -1; $msg = 'fail'; $data = null; $request = Yii::$app->request; if (!$request->isGet) { $msg = '请求错误!'; goto doEnd; } $address = $request->get('address', ''); $is_with_draw = $request->get('isWithdraw', ''); if (empty($address)) { $msg = '参数错误!'; goto doEnd; } $model = CoinCrossChain::find()->where(['address' => $address, 'is_with_draw' => $is_with_draw])->orderBy("id desc")->limit(1)->asArray()->one(); if (empty($model)) { $msg = '数据不存在!'; goto doEnd; } if (false == $model['txhash'] && false == $model['msg']) { $data = [ 'step' => $model['current_step'] ]; $code = 0; $msg = '交易尚未执行'; goto doEnd; } if (false == $model['txhash'] && false != $model['msg']) { $data = [ 'step' => $model['current_step'] ]; $msg = $model['msg']; goto doEnd; } if (true == $model['txhash'] && false == $model['msg']) { $data = [ 'step' => $model['current_step'] ]; $code = 0; $msg = $model['txhash']; goto doEnd; } doEnd : return ['code' => $code, 'msg' => $msg, 'data' => $data]; } public static function getrandnums() { $arr = array(); while (count($arr) < 6) { $arr[] = rand(0, 9); $arr = array_unique($arr); } return implode("", $arr); } }