Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
00b3f2cd
Commit
00b3f2cd
authored
Jul 24, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
手续费
parent
37dfca0a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
25 deletions
+117
-25
TradeController.php
api/controllers/TradeController.php
+78
-25
CoinHashMemo.php
common/models/psources/CoinHashMemo.php
+39
-0
No files found.
api/controllers/TradeController.php
View file @
00b3f2cd
...
@@ -5,9 +5,11 @@
...
@@ -5,9 +5,11 @@
* Date: 2018/11/14
* Date: 2018/11/14
* Time: 18:53
* Time: 18:53
*/
*/
namespace
api\controllers
;
namespace
api\controllers
;
use
api\base\BaseController
;
use
api\base\BaseController
;
use
common\models\psources\CoinHashMemo
;
use
common\models\psources\CoinTokenTransfer
;
use
common\models\psources\CoinTokenTransfer
;
use
common\service\chain33\Chain33Service
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
Yii
;
...
@@ -16,19 +18,40 @@ use Yii;
...
@@ -16,19 +18,40 @@ use Yii;
class
TradeController
extends
BaseController
class
TradeController
extends
BaseController
{
{
/**
/**
* 添加本地备注
* 添加本地备注
*/
*/
public
function
actionAddMemo
()
public
function
actionAddMemo
()
{
{
$request
=
Yii
::
$app
->
request
;
$request
=
Yii
::
$app
->
request
;
$hash
=
$request
->
post
(
'hash'
);
$hash
=
$request
->
post
(
'hash'
);
$memo
=
$request
->
post
(
'memo'
);
$memo
=
$request
->
post
(
'memo'
);
if
(
$hash
&&
$memo
){
if
(
empty
(
$hash
)
||
empty
(
$memo
))
{
Yii
::
$app
->
redis
->
hset
(
'trade_hash_memo'
,
$hash
,
$memo
);
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值或者本地备注不能为空'
];
return
[
'code'
=>
0
,
'data'
=>
[],
'msg'
=>
'本地备注添加成功'
];
}
}
else
{
$model
=
new
CoinHashMemo
();
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值或者本地备注不能为空'
];
$model
->
setScenario
(
CoinHashMemo
::
SCENARIOS_CREATE
);
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
(),
''
)
&&
$model
->
save
())
{
return
[
'code'
=>
0
,
'data'
=>
[],
'msg'
=>
'本地备注添加成功'
];
}
else
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
current
(
$model
->
firstErrors
)];
}
}
public
function
actionUpdateMemo
()
{
$request
=
Yii
::
$app
->
request
;
$hash
=
$request
->
post
(
'hash'
);
$memo
=
$request
->
post
(
'memo'
);
if
(
empty
(
$hash
)
||
empty
(
$memo
))
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值或者本地备注不能为空'
];
}
$model
=
CoinHashMemo
::
find
()
->
where
([
'hash'
=>
$hash
])
->
one
();
if
(
empty
(
$model
))
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'记录不存在'
];
}
}
CoinHashMemo
::
updateAll
([
'memo'
=>
$memo
],
'hash = :hash'
,[
':hash'
=>
$hash
]);
return
[
'code'
=>
0
,
'data'
=>
[],
'msg'
=>
'本地备注更新成功'
];
}
}
/**
/**
...
@@ -36,27 +59,57 @@ class TradeController extends BaseController
...
@@ -36,27 +59,57 @@ class TradeController extends BaseController
*/
*/
public
function
actionGetMemo
()
public
function
actionGetMemo
()
{
{
$request
=
Yii
::
$app
->
request
;
$request
=
Yii
::
$app
->
request
;
$hash
=
$request
->
post
(
'hash'
);
$hash
=
$request
->
post
(
'hash'
);
if
(
$hash
){
$version
=
$request
->
post
(
'version'
,
''
);
$memo
=
Yii
::
$app
->
redis
->
hget
(
'trade_hash_memo'
,
$hash
);
if
(
empty
(
$hash
))
{
return
[
'code'
=>
0
,
'data'
=>
$memo
];
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值不能为空'
];
}
else
{
}
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值不能为空'
];
$model
=
CoinHashMemo
::
find
()
->
where
([
'hash'
=>
$hash
])
->
asArray
()
->
one
();
if
(
empty
(
$model
))
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'记录不存在'
];
}
}
if
(
empty
(
$version
)){
return
[
'code'
=>
0
,
'data'
=>
$model
[
'memo'
]];
}
return
[
'code'
=>
0
,
'data'
=>
[
'memo'
=>
$model
[
'memo'
],
'coins_fee'
=>
$model
[
'coins_fee'
]
]];
}
public
function
actionSyncToDb
()
{
// $data = [];
// $result = Yii::$app->redis->HGETALL ('trade_hash_memo');
// foreach ($result as $key => $val){
// if (($key + 2) % 2 == 0){
// $data[] = [
// 'hash' => $val,
// 'memo' => $result[$key + 1]
// ];
// }
// }
// foreach ($data as $val){
// if ('0xc080c6a0937f25d1017e5e88bdcff5c3979810c8a6cc1f3a64cf50970da28fc9' == $val['hash']) continue;
// $coin_memo_hash = new CoinHashMemo();
// $coin_memo_hash->hash = $val['hash'];
// $coin_memo_hash->memo = $val['memo'];
// $coin_memo_hash->save();
// }
// exit;
}
}
public
function
actionAddressIsExist
()
public
function
actionAddressIsExist
()
{
{
$get
=
Yii
::
$app
->
request
->
get
();
$get
=
Yii
::
$app
->
request
->
get
();
$to
=
$get
[
'coin_address'
]
??
''
;
$to
=
$get
[
'coin_address'
]
??
''
;
if
(
empty
(
$to
))
{
if
(
empty
(
$to
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
}
}
$coinTokenTransfer
=
CoinTokenTransfer
::
find
()
->
where
([
'coin_address'
=>
$to
,
'code'
=>
1
])
->
one
();
$coinTokenTransfer
=
CoinTokenTransfer
::
find
()
->
where
([
'coin_address'
=>
$to
,
'code'
=>
1
])
->
one
();
if
(
!
$coinTokenTransfer
)
{
if
(
!
$coinTokenTransfer
)
{
return
[
'code'
=>
0
,
'msg'
=>
'record does not exist'
];
return
[
'code'
=>
0
,
'msg'
=>
'record does not exist'
];
}
}
...
@@ -68,12 +121,12 @@ class TradeController extends BaseController
...
@@ -68,12 +121,12 @@ class TradeController extends BaseController
{
{
$get
=
Yii
::
$app
->
request
->
get
();
$get
=
Yii
::
$app
->
request
->
get
();
$to
=
$get
[
'coin_address'
]
??
''
;
$to
=
$get
[
'coin_address'
]
??
''
;
if
(
empty
(
$to
))
{
if
(
empty
(
$to
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
}
}
$coinTokenTransfer
=
CoinTokenTransfer
::
find
()
->
where
([
'coin_address'
=>
$to
,
'code'
=>
1
])
->
one
();
$coinTokenTransfer
=
CoinTokenTransfer
::
find
()
->
where
([
'coin_address'
=>
$to
,
'code'
=>
1
])
->
one
();
if
(
$coinTokenTransfer
)
{
if
(
$coinTokenTransfer
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'record already exists'
];
return
[
'code'
=>
-
1
,
'msg'
=>
'record already exists'
];
}
}
...
@@ -86,8 +139,8 @@ class TradeController extends BaseController
...
@@ -86,8 +139,8 @@ class TradeController extends BaseController
$service
=
new
Chain33Service
();
$service
=
new
Chain33Service
();
$createRawTransaction
=
$service
->
createTokenRawTransaction
(
$to
,
$amount
,
$isToken
,
$tokenSymbol
,
$fee
,
$note
,
$execer
);
$createRawTransaction
=
$service
->
createTokenRawTransaction
(
$to
,
$amount
,
$isToken
,
$tokenSymbol
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createRawTransaction
[
'code'
])
{
if
(
0
!=
$createRawTransaction
[
'code'
])
{
$msg
=
$createRawTransaction
[
'msg'
];
$msg
=
$createRawTransaction
[
'msg'
];
$code
=
-
1
;
$code
=
-
1
;
goto
doEnd
;
goto
doEnd
;
...
@@ -98,7 +151,7 @@ class TradeController extends BaseController
...
@@ -98,7 +151,7 @@ class TradeController extends BaseController
$expire
=
'1m'
;
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
if
(
0
!=
$signRawTx
[
'code'
])
{
$msg
=
$signRawTx
[
'msg'
];
$msg
=
$signRawTx
[
'msg'
];
$code
=
-
1
;
$code
=
-
1
;
goto
doEnd
;
goto
doEnd
;
...
@@ -106,7 +159,7 @@ class TradeController extends BaseController
...
@@ -106,7 +159,7 @@ class TradeController extends BaseController
$sign_str
=
$signRawTx
[
'result'
];
$sign_str
=
$signRawTx
[
'result'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
])
{
if
(
0
!=
$result
[
'code'
])
{
$msg
=
$result
[
'msg'
];
$msg
=
$result
[
'msg'
];
$code
=
-
1
;
$code
=
-
1
;
goto
doEnd
;
goto
doEnd
;
...
...
common/models/psources/CoinHashMemo.php
0 → 100644
View file @
00b3f2cd
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinHashMemo
extends
BaseActiveRecord
{
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_hash_memo}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
function
rules
()
{
return
[
[[
'hash'
,
'memo'
],
'required'
],
[
'coins_fee'
,
'safe'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'hash'
,
'memo'
,
'coins_fee'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment