Commit 0a3a1a39 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/c2c' into develop

parents a79cf8cd 10d8c5b2
<?php
namespace api\controllers;
use Yii;
use yii\data\Pagination;
use api\base\BaseController;
use common\models\psources\CoinCTocTransfer;
class OrderController extends BaseController
{
public function actionIndex()
{
$code = -1;
$request = Yii::$app->request;
if (!$request->isPost) {
$msg = '请求错误!';
goto doEnd;
}
$post = $request->post();
if (2 != count($post['txs'])) {
$msg = '交易笔数错误!';
goto doEnd;
}
$data['is_sell'] = (false == $post['isSell']) ? 0 : 1;
$data['type'] = $post['type'];
$data['address'] = $post['address'];
$data['token_name'] = $post['token_name'];
$data['market_name'] = $post['market_name'];
$data['price'] = $post['price'];
$data['amount'] = $post['amount'];
$data['transfer_number'] = date('YmdHis') . self::getrandnums();
$redis = Yii::$app->redis;
if ($redis->exists('C2C_' . $post['address'] . '_' . $data['is_sell'])) {
$msg = '尚存在一笔未完成的交易!';
goto doEnd;
}
$redis->set('C2C_' . $post['address'] . '_' . $data['is_sell'], time());
foreach ($post['txs'] as $key => $val) {
$model = new CoinCTocTransfer();
$data['txhex'] = $val['tx'];
$data['transfer_url'] = $val['url'];
$data['step'] = $val['step'];
$model->load($data, '');
$model->save();
}
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
public function actionFixOrder()
{
$code = -1;
$request = Yii::$app->request;
if (!$request->isPost) {
$msg = '请求错误!';
goto doEnd;
}
$post = $request->post();
$data['is_sell'] = (false == $post['isSell']) ? 0 : 1;
$data['type'] = $post['type'];
$data['address'] = $post['address'];
foreach ($post['txs'] as $key => $val) {
$model = CoinCTocTransfer::find()->where(['is_sell' => $data['is_sell']])
->andWhere(['type' => $data['type']])
->andWhere(['address' => $data['address']])
->andWhere(['step' => $val['step']])
->andWhere(['<>', 'msg', 'success'])
->one();
$model->txhex = $val['tx'];
$model->transfer_url = $val['url'];
$model->send_result = 0;
$model->query_result = 0;
$model->msg = 0;
$model->save();
continue;
}
$redis = Yii::$app->redis;
$redis->set('C2C_' . $post['address'] . '_' . $data['is_sell'], time());
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
public function actionOrderList()
{
$address = Yii::$app->request->get('address', '');
$is_sell = Yii::$app->request->get('isSell', -1);
$type = Yii::$app->request->get('type', '');
$page = Yii::$app->request->get('page', 1);
if(empty($address)){
$msg = '请求参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = CoinCTocTransfer::find()
->where('address= :address',[':address' => $address])
->orderBy('create_time desc')
->groupBy('address, is_sell');
if ($is_sell > -1) {
$query->andWhere('is_sell= :is_sell',[':is_sell' => $is_sell]);
}
if (false != $type) {
$query->andWhere('type= :type',[':type' => $type]);
}
$data = $query->offset(($page - 1) * 20)->limit(20)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]);
$data = [
'list' => $data,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 20,
'currentPage' => $page,
]
];
$code = 1;
$msg = 'success';
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);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinCTocTransfer extends BaseActiveRecord
{
const TYPE_SELL = 1; //卖单
const TYPE_BUY = 0; //买单
const TYPE_ORDER = 1; //挂单
const TYPE_TRANSFER = 2; //交易
const TYPE_REVOKE = 3; //撤消
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_ctoc_transfer}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
public function rules()
{
return [
[['is_sell', 'type', 'address', 'token_name', 'market_name', 'price', 'amount', 'step', 'txhex', 'transfer_url', 'transfer_number'], 'required'],
[['send_result', 'query_result', 'msg'], 'safe']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['is_sell', 'type', 'address', 'token_name', 'market_name', 'price', 'amount', 'step', 'txhex', 'transfer_url', 'transfer_number'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
...@@ -35,8 +35,8 @@ class ZhaobiBuilder extends FactoryService ...@@ -35,8 +35,8 @@ class ZhaobiBuilder extends FactoryService
$explode_arr = explode($coin, $val['symbol']); $explode_arr = explode($coin, $val['symbol']);
if (2 == count($explode_arr) && empty($explode_arr[1])) { if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin; $temp['symbol'] = ('BCC' == strtoupper($explode_arr[0])) ? 'BCH' . '/' . $coin : strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]); $temp['currency'] = ('BCC' == strtoupper($explode_arr[0])) ? 'BCH' : strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin); $temp['base_currency'] = strtoupper($coin);
$temp['close'] = number_format($val['last'], 6, '.', ''); $temp['close'] = number_format($val['last'], 6, '.', '');
if ('0.000000' == $temp['close']) continue; if ('0.000000' == $temp['close']) continue;
...@@ -86,11 +86,11 @@ class ZhaobiBuilder extends FactoryService ...@@ -86,11 +86,11 @@ class ZhaobiBuilder extends FactoryService
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100); $temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp); array_push($ticker, $temp);
} }
$ticker_sort_close= $this->arraySort($ticker,'close'); $ticker_sort_close = $this->arraySort($ticker, 'close');
foreach ($ticker_sort_close as $val) { foreach ($ticker_sort_close as $val) {
$this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']); $this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']);
} }
$ticker_change_close= $this->arraySort($ticker,'change'); $ticker_change_close = $this->arraySort($ticker, 'change');
foreach ($ticker_change_close as $val) { foreach ($ticker_change_close as $val) {
$this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']); $this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']);
} }
...@@ -107,7 +107,7 @@ class ZhaobiBuilder extends FactoryService ...@@ -107,7 +107,7 @@ class ZhaobiBuilder extends FactoryService
$res['data']['abstract'] = str_replace(' ', '', str_replace('&nbsp;', '', $res['data']['abstract'])); $res['data']['abstract'] = str_replace(' ', '', str_replace('&nbsp;', '', $res['data']['abstract']));
$res['data']['content'] = str_replace(' ', '', str_replace('&nbsp;', '', $res['data']['content'])); $res['data']['content'] = str_replace(' ', '', str_replace('&nbsp;', '', $res['data']['content']));
$res['data']['source'] = '找币'; $res['data']['source'] = '找币';
$res['data']['share_url'] = \Yii::$app->params['service']['ZhaobiService']['h5_url']. '/account/help/' . $params['id']; $res['data']['share_url'] = \Yii::$app->params['service']['ZhaobiService']['h5_url'] . '/account/help/' . $params['id'];
return ['code' => $this->code, 'notice' => $res['data']]; return ['code' => $this->code, 'notice' => $res['data']];
} else { } else {
return ['code' => $this->code, 'notice' => $res['data'], 'msg' => $res['message']]; return ['code' => $this->code, 'notice' => $res['data'], 'msg' => $res['message']];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment