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
573eb440
Commit
573eb440
authored
Sep 03, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue coin
parent
4596440c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
525 additions
and
0 deletions
+525
-0
IssueCoinController.php
api/controllers/IssueCoinController.php
+101
-0
CoinIssueCoin.php
common/models/psources/CoinIssueCoin.php
+62
-0
CoinIssueCoinForm.php
common/models/psources/CoinIssueCoinForm.php
+114
-0
CommonActiveRecord.php
common/models/psources/CommonActiveRecord.php
+146
-0
IssueCoinController.php
wallet/controllers/IssueCoinController.php
+102
-0
No files found.
api/controllers/IssueCoinController.php
0 → 100644
View file @
573eb440
<?php
namespace
api\controllers
;
use
Yii
;
class
IssueCoinController
extends
BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public
function
actionList
()
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
===
$platform_id
)
{
$platforms
=
CoinPlatform
::
find
()
->
select
(
'id, name'
)
->
asArray
()
->
all
();
}
else
{
$platforms
=
CoinPlatform
::
find
()
->
select
(
'id, name'
)
->
where
([
'id'
=>
$platform_id
])
->
asArray
()
->
all
();
}
return
[
'code'
=>
0
,
'msg'
=>
'ok'
,
'data'
=>
$platforms
];
}
public
function
actionWalletBallance
()
{
$current_platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
===
$current_platform_id
)
{
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
1
);
$platform_id
=
empty
(
$platform_id
)
?
1
:
$platform_id
;
}
else
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
}
if
(
!
isset
(
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
])){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'此钱包节点尚未开通'
];
}
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
1
);
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
15
);
$currency
=
Yii
::
$app
->
request
->
get
(
'currency '
,
''
);
$params
=
[
'type'
=>
$type
,
'page'
=>
$page
,
'size'
=>
$size
,
'currency'
=>
$currency
];
$time
=
time
();
$appKey
=
isset
(
$node_params
[
'appKey'
])
?
$node_params
[
'appKey'
]
:
null
;
$appSecret
=
isset
(
$node_params
[
'appSecret'
])
?
$node_params
[
'appSecret'
]
:
null
;
$signature
=
self
::
getSign
(
$params
,
$appKey
,
$appSecret
,
$time
);
$headers
=
[
'FZM-Wallet-Signature'
=>
$signature
,
'FZM-Wallet-Timestamp'
=>
$time
,
'FZM-Wallet-AppKey'
=>
$appKey
,
'FZM-Wallet-AppIp'
=>
Yii
::
$app
->
request
->
userIP
];
$service
=
new
TrusteeShipService
(
$node_params
,
$headers
);
$result
=
$service
->
getWalletBalance
(
$params
);
if
(
200
!==
$result
[
'code'
])
{
return
[
'code'
=>
$result
[
'code'
],
'data'
=>
[],
'msg'
=>
$result
[
'msg'
]];
}
return
[
'code'
=>
1
,
'data'
=>
$result
[
'msg'
],
'msg'
=>
'success'
];
}
public
function
actionUserAsset
()
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$uid
=
Yii
::
$app
->
request
->
get
(
'uid'
,
''
);
$params
=
[
'uid'
=>
$uid
];
$time
=
time
();
$appKey
=
isset
(
$node_params
[
'appKey'
])
?
$node_params
[
'appKey'
]
:
null
;
$appSecret
=
isset
(
$node_params
[
'appSecret'
])
?
$node_params
[
'appSecret'
]
:
null
;
$signature
=
self
::
getSign
(
$params
,
$appKey
,
$appSecret
,
$time
);
$headers
=
[
'FZM-Wallet-Signature'
=>
$signature
,
'FZM-Wallet-Timestamp'
=>
$time
,
'FZM-Wallet-AppKey'
=>
$appKey
,
'FZM-Wallet-AppIp'
=>
Yii
::
$app
->
request
->
userIP
];
$service
=
new
TrusteeShipService
(
$node_params
,
$headers
);
$result
=
$service
->
getUserAsset
(
$params
);
if
(
200
!==
$result
[
'code'
])
{
return
[
'code'
=>
$result
[
'code'
],
'data'
=>
[],
'msg'
=>
$result
[
'msg'
]];
}
return
[
'code'
=>
1
,
'data'
=>
$result
[
'msg'
],
'msg'
=>
'success'
];
}
}
\ No newline at end of file
common/models/psources/CoinIssueCoin.php
0 → 100644
View file @
573eb440
<?php
namespace
common\models
;
use
Yii
;
use
yii\db\Expression
;
class
CoinIssueCoin
extends
CommonActiveRecord
{
const
STATUS_SUCCESS
=
1
;
//发行成功
const
STATUS_FAIL
=
0
;
//发行失败
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
function
fields
()
{
return
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'chain_id'
,
];
}
public
static
function
tableName
()
{
return
'{{%coin_issue_coin}}'
;
}
public
function
attributeLabels
()
{
return
[
'name'
=>
'Token简称'
,
'symbol'
=>
'Token全称'
,
'total'
=>
'发行数量'
,
'owner'
=>
'接收地址'
,
'introduction'
=>
'Token简介'
,
'category'
=>
'是否增加发'
,
'chain_id'
=>
'平行链名称'
,
'msg'
=>
'失败原因'
];
}
/**
* 获取状态数组
* @return array
*/
public
static
function
getAgentStatus
()
{
return
[
self
::
STATUS_SUCCESS
=>
'发行成功'
,
self
::
STATUS_FAIL
=>
'发行失败'
,
];
}
}
\ No newline at end of file
common/models/psources/CoinIssueCoinForm.php
0 → 100644
View file @
573eb440
<?php
namespace
common\models
;
use
yii\base\Model
;
class
CoinIssueCoinForm
extends
Model
{
public
$name
;
public
$symbol
;
public
$total
;
public
$owner
;
public
$introduction
;
public
$category
;
public
$platform_id
;
public
$chain_id
;
private
$_issue_coin_list
;
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
function
rules
()
{
return
[
[[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
],
'required'
],
[[
'total'
,
'category'
,
'platform_id'
,
'chain_id'
],
'integer'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
],
self
::
SCENARIOS_UPDATE
=>
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
attributeLabels
()
{
return
[
'name'
=>
'Token简称'
,
'symbol'
=>
'Token全称'
,
'total'
=>
'发行数量'
,
'owner'
=>
'接收地址'
,
'introduction'
=>
'Token简介'
,
'category'
=>
'是否增加发'
,
'chain_id'
=>
'平行链名称'
];
}
public
function
getIsNewRecord
()
{
return
$this
->
_issue_coin_list
===
null
;
}
public
function
getIssueList
(
$id
)
{
$this
->
_issue_coin_list
=
CoinIssueCoinForm
::
find
()
->
where
(
'agent_id = :agent_id'
,
[
':agent_id'
=>
$id
])
->
one
();
if
(
$this
->
_issue_coin_list
)
{
$this
->
agent_id
=
$this
->
_issue_coin_list
->
agent_id
;
$this
->
title
=
$this
->
_issue_coin_list
->
title
;
$this
->
etitle
=
$this
->
_issue_coin_list
->
etitle
;
$this
->
description
=
$this
->
_issue_coin_list
->
description
;
$this
->
requirement
=
$this
->
_issue_coin_list
->
requirement
;
$this
->
status
=
$this
->
_issue_coin_list
->
status
;
}
return
$this
->
_issue_coin_list
;
}
/**
* 保存代理人
* @return boolean
*/
public
function
save
()
{
if
(
$this
->
validate
())
{
if
(
$this
->
getIsNewRecord
())
{
$this
->
_issue_coin_list
=
new
Agent
();
$isNew
=
true
;
}
else
{
$isNew
=
false
;
}
$this
->
_issue_coin_list
->
agent_id
=
$this
->
agent_id
;
$this
->
_issue_coin_list
->
title
=
$this
->
title
;
$this
->
_issue_coin_list
->
etitle
=
$this
->
etitle
;
$this
->
_issue_coin_list
->
description
=
$this
->
description
;
$this
->
_issue_coin_list
->
requirement
=
$this
->
requirement
;
$this
->
_issue_coin_list
->
status
=
$this
->
status
;
return
$this
->
_issue_coin_list
->
save
();
}
else
{
return
false
;
}
}
}
\ No newline at end of file
common/models/psources/CommonActiveRecord.php
0 → 100644
View file @
573eb440
<?php
namespace
common\models
;
use
Yii
;
use
yii\db\ActiveRecord
;
use
yii\helpers\ArrayHelper
;
use
yii\web\Linkable
;
use
yii\web\Link
;
class
CommonActiveRecord
extends
ActiveRecord
{
public
$cacheKeyStorage
=
[];
//缓存key寄存器
public
function
toArray
(
array
$fields
=
[],
array
$expand
=
[],
$recursive
=
true
)
{
$data
=
[];
$cachePrefix
=
__CLASS__
;
$cache
=
Yii
::
$app
->
cache
;
foreach
(
$this
->
resolveFields
(
$fields
,
$expand
)
as
$field
=>
$definition
)
{
if
(
strpos
(
$field
,
'.'
))
{
$fieldChunks
=
explode
(
'.'
,
$field
);
$primaryKey
=
is_array
(
$this
->
primaryKey
)
?
implode
(
'-'
,
$this
->
primaryKey
)
:
$this
->
primaryKey
;
$uniqueRelationCacheKey
=
"
{
$cachePrefix
}
_
{
$primaryKey
}
_
{
$fieldChunks
[
0
]
}
"
;
$this
->
addCacheKeyToStorage
(
$uniqueRelationCacheKey
);
$relation
=
$cache
->
get
(
$uniqueRelationCacheKey
);
if
(
!
$relation
)
{
$relation
=
$this
->
{
$fieldChunks
[
0
]};
$cache
->
set
(
$uniqueRelationCacheKey
,
$relation
);
}
if
(
is_array
(
$relation
))
{
foreach
(
$relation
as
$relatedField
=>
$relatedObject
)
{
if
(
!
is_object
(
$relatedObject
))
{
continue
;
}
$data
[
$fieldChunks
[
0
]][
$relatedField
][
$fieldChunks
[
1
]]
=
$this
->
getRelationField
(
$relatedObject
,
$fieldChunks
[
1
]);
}
}
else
{
if
(
!
is_object
(
$relation
))
{
continue
;
}
$data
[
$fieldChunks
[
0
]][
$fieldChunks
[
1
]]
=
$this
->
getRelationField
(
$relation
,
$fieldChunks
[
1
]);
}
}
else
{
$data
[
$field
]
=
is_string
(
$definition
)
?
$this
->
$definition
:
call_user_func
(
$definition
,
$this
,
$field
);
}
}
$this
->
deleteStorageCaches
();
if
(
$this
instanceof
Linkable
)
{
$data
[
'_links'
]
=
Link
::
serialize
(
$this
->
getLinks
());
}
return
$recursive
?
ArrayHelper
::
toArray
(
$data
)
:
$data
;
}
/**
* This method also will check relations which are declared in [[extraFields()]]
* to determine which related fields can be returned.
* @inheritdoc
*/
protected
function
resolveFields
(
array
$fields
,
array
$expand
)
{
$result
=
[];
foreach
(
$this
->
fields
()
as
$field
=>
$definition
)
{
if
(
is_integer
(
$field
))
{
$field
=
$definition
;
}
if
(
empty
(
$fields
)
||
in_array
(
$field
,
$fields
,
true
))
{
$result
[
$field
]
=
$definition
;
}
}
if
(
empty
(
$expand
))
{
return
$result
;
}
$extraFieldsKeys
=
array_keys
(
$this
->
extraFields
());
foreach
(
$expand
as
$expandedAttribute
)
{
if
(
in_array
(
explode
(
'.'
,
$expandedAttribute
)[
0
],
$this
->
extraFields
()))
{
$result
[
$expandedAttribute
]
=
$expandedAttribute
;
}
else
if
(
in_array
(
$expandedAttribute
,
$extraFieldsKeys
))
{
$result
[
$expandedAttribute
]
=
$this
->
extraFields
()[
$expandedAttribute
];
}
}
return
$result
;
}
/**
* Additional method to check the related model has specified field
*/
private
function
getRelationField
(
$relatedRecord
,
$field
)
{
if
(
!
$relatedRecord
->
hasAttribute
(
$field
)
&&
!
$relatedRecord
->
isRelationPopulated
(
$field
))
{
throw
new
\yii\web\ServerErrorHttpException
(
sprintf
(
"Related record '%s' does not have attribute '%s'"
,
get_class
(
$relatedRecord
),
$field
)
);
}
if
(
$relatedRecord
->
hasAttribute
(
$field
))
{
return
ArrayHelper
::
toArray
(
$relatedRecord
)[
$field
];
}
else
{
return
$relatedRecord
->
{
$field
};
}
}
public
static
function
quoteDbName
(
$dbname
)
{
return
'`'
.
$dbname
.
'`'
;
}
/**
* 添加cache key到寄存器
* @param type $cacheKey
*/
public
function
addCacheKeyToStorage
(
$cacheKey
)
{
if
(
!
in_array
(
$cacheKey
,
$this
->
cacheKeyStorage
))
{
$this
->
cacheKeyStorage
[]
=
$cacheKey
;
}
}
/**
* 删除寄存器里所有的cache
*/
public
function
deleteStorageCaches
()
{
foreach
(
$this
->
cacheKeyStorage
as
$cacheKey
)
{
Yii
::
$app
->
cache
->
delete
(
$cacheKey
);
}
}
}
\ No newline at end of file
wallet/controllers/IssueCoinController.php
0 → 100644
View file @
573eb440
<?php
namespace
wallet\controllers
;
use
Yii
;
use
common\models\Admin
;
class
IssueCoinController
extends
BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public
function
actionList
()
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
===
$platform_id
)
{
$platforms
=
CoinPlatform
::
find
()
->
select
(
'id, name'
)
->
asArray
()
->
all
();
}
else
{
$platforms
=
CoinPlatform
::
find
()
->
select
(
'id, name'
)
->
where
([
'id'
=>
$platform_id
])
->
asArray
()
->
all
();
}
return
[
'code'
=>
0
,
'msg'
=>
'ok'
,
'data'
=>
$platforms
];
}
public
function
actionWalletBallance
()
{
$current_platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
===
$current_platform_id
)
{
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
1
);
$platform_id
=
empty
(
$platform_id
)
?
1
:
$platform_id
;
}
else
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
}
if
(
!
isset
(
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
])){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'此钱包节点尚未开通'
];
}
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
1
);
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
15
);
$currency
=
Yii
::
$app
->
request
->
get
(
'currency '
,
''
);
$params
=
[
'type'
=>
$type
,
'page'
=>
$page
,
'size'
=>
$size
,
'currency'
=>
$currency
];
$time
=
time
();
$appKey
=
isset
(
$node_params
[
'appKey'
])
?
$node_params
[
'appKey'
]
:
null
;
$appSecret
=
isset
(
$node_params
[
'appSecret'
])
?
$node_params
[
'appSecret'
]
:
null
;
$signature
=
self
::
getSign
(
$params
,
$appKey
,
$appSecret
,
$time
);
$headers
=
[
'FZM-Wallet-Signature'
=>
$signature
,
'FZM-Wallet-Timestamp'
=>
$time
,
'FZM-Wallet-AppKey'
=>
$appKey
,
'FZM-Wallet-AppIp'
=>
Yii
::
$app
->
request
->
userIP
];
$service
=
new
TrusteeShipService
(
$node_params
,
$headers
);
$result
=
$service
->
getWalletBalance
(
$params
);
if
(
200
!==
$result
[
'code'
])
{
return
[
'code'
=>
$result
[
'code'
],
'data'
=>
[],
'msg'
=>
$result
[
'msg'
]];
}
return
[
'code'
=>
1
,
'data'
=>
$result
[
'msg'
],
'msg'
=>
'success'
];
}
public
function
actionUserAsset
()
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$uid
=
Yii
::
$app
->
request
->
get
(
'uid'
,
''
);
$params
=
[
'uid'
=>
$uid
];
$time
=
time
();
$appKey
=
isset
(
$node_params
[
'appKey'
])
?
$node_params
[
'appKey'
]
:
null
;
$appSecret
=
isset
(
$node_params
[
'appSecret'
])
?
$node_params
[
'appSecret'
]
:
null
;
$signature
=
self
::
getSign
(
$params
,
$appKey
,
$appSecret
,
$time
);
$headers
=
[
'FZM-Wallet-Signature'
=>
$signature
,
'FZM-Wallet-Timestamp'
=>
$time
,
'FZM-Wallet-AppKey'
=>
$appKey
,
'FZM-Wallet-AppIp'
=>
Yii
::
$app
->
request
->
userIP
];
$service
=
new
TrusteeShipService
(
$node_params
,
$headers
);
$result
=
$service
->
getUserAsset
(
$params
);
if
(
200
!==
$result
[
'code'
])
{
return
[
'code'
=>
$result
[
'code'
],
'data'
=>
[],
'msg'
=>
$result
[
'msg'
]];
}
return
[
'code'
=>
1
,
'data'
=>
$result
[
'msg'
],
'msg'
=>
'success'
];
}
}
\ 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