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
b3f99fb6
Commit
b3f99fb6
authored
Jul 24, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/trade-memo' into 'master'
Feature/trade memo See merge request
!61
parents
37dfca0a
f1cc960c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
17 deletions
+108
-17
TradeController.php
api/controllers/TradeController.php
+69
-17
CoinHashMemo.php
common/models/psources/CoinHashMemo.php
+39
-0
No files found.
api/controllers/TradeController.php
View file @
b3f99fb6
...
...
@@ -5,9 +5,11 @@
* Date: 2018/11/14
* Time: 18:53
*/
namespace
api\controllers
;
use
api\base\BaseController
;
use
common\models\psources\CoinHashMemo
;
use
common\models\psources\CoinTokenTransfer
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
...
...
@@ -22,13 +24,33 @@ class TradeController extends BaseController
{
$request
=
Yii
::
$app
->
request
;
$hash
=
$request
->
post
(
'hash'
);
if
(
empty
(
$hash
))
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值不能为空'
];
}
$model
=
new
CoinHashMemo
();
$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
(
$hash
&&
$memo
){
Yii
::
$app
->
redis
->
hset
(
'trade_hash_memo'
,
$hash
,
$memo
);
return
[
'code'
=>
0
,
'data'
=>
[],
'msg'
=>
'本地备注添加成功'
];
}
else
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值或者本地备注不能为空'
];
if
(
empty
(
$hash
))
{
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'
=>
'本地备注更新成功'
];
}
/**
...
...
@@ -38,25 +60,55 @@ class TradeController extends BaseController
{
$request
=
Yii
::
$app
->
request
;
$hash
=
$request
->
post
(
'hash'
);
if
(
$hash
){
$memo
=
Yii
::
$app
->
redis
->
hget
(
'trade_hash_memo'
,
$hash
);
return
[
'code'
=>
0
,
'data'
=>
$memo
];
}
else
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'交易hash值不能为空'
];
$version
=
$request
->
post
(
'version'
,
''
);
if
(
empty
(
$hash
))
{
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
()
{
$get
=
Yii
::
$app
->
request
->
get
();
$to
=
$get
[
'coin_address'
]
??
''
;
if
(
empty
(
$to
))
{
if
(
empty
(
$to
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
}
$coinTokenTransfer
=
CoinTokenTransfer
::
find
()
->
where
([
'coin_address'
=>
$to
,
'code'
=>
1
])
->
one
();
if
(
!
$coinTokenTransfer
)
{
if
(
!
$coinTokenTransfer
)
{
return
[
'code'
=>
0
,
'msg'
=>
'record does not exist'
];
}
...
...
@@ -68,12 +120,12 @@ class TradeController extends BaseController
{
$get
=
Yii
::
$app
->
request
->
get
();
$to
=
$get
[
'coin_address'
]
??
''
;
if
(
empty
(
$to
))
{
if
(
empty
(
$to
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
}
$coinTokenTransfer
=
CoinTokenTransfer
::
find
()
->
where
([
'coin_address'
=>
$to
,
'code'
=>
1
])
->
one
();
if
(
$coinTokenTransfer
)
{
if
(
$coinTokenTransfer
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'record already exists'
];
}
...
...
@@ -87,7 +139,7 @@ class TradeController extends BaseController
$service
=
new
Chain33Service
();
$createRawTransaction
=
$service
->
createTokenRawTransaction
(
$to
,
$amount
,
$isToken
,
$tokenSymbol
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createRawTransaction
[
'code'
])
{
if
(
0
!=
$createRawTransaction
[
'code'
])
{
$msg
=
$createRawTransaction
[
'msg'
];
$code
=
-
1
;
goto
doEnd
;
...
...
@@ -98,7 +150,7 @@ class TradeController extends BaseController
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
if
(
0
!=
$signRawTx
[
'code'
])
{
$msg
=
$signRawTx
[
'msg'
];
$code
=
-
1
;
goto
doEnd
;
...
...
@@ -106,7 +158,7 @@ class TradeController extends BaseController
$sign_str
=
$signRawTx
[
'result'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
])
{
if
(
0
!=
$result
[
'code'
])
{
$msg
=
$result
[
'msg'
];
$code
=
-
1
;
goto
doEnd
;
...
...
common/models/psources/CoinHashMemo.php
0 → 100644
View file @
b3f99fb6
<?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'
],
'required'
],
[[
'coins_fee'
,
'memo'
],
'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