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
019c8f13
Commit
019c8f13
authored
Sep 27, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8c125d65
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
303 additions
and
119 deletions
+303
-119
CoinReleaseCheckController.php
backend/controllers/CoinReleaseCheckController.php
+60
-6
ExtractTokenJob.php
backend/jobs/ExtractTokenJob.php
+0
-95
FreezeJob.php
backend/jobs/FreezeJob.php
+41
-8
QueryTransJob.php
backend/jobs/QueryTransJob.php
+110
-0
CoinPublishRule.php
common/models/psources/CoinPublishRule.php
+10
-0
CoinReleaseList.php
common/models/psources/CoinReleaseList.php
+35
-0
DevController.php
console/controllers/DevController.php
+7
-3
BaseResponse.php
h5/base/BaseResponse.php
+7
-1
GuodunController.php
h5/controllers/GuodunController.php
+33
-6
No files found.
backend/controllers/CoinReleaseCheckController.php
View file @
019c8f13
...
...
@@ -8,9 +8,13 @@
namespace
backend\controllers
;
use
backend\jobs\QueryTransJob
;
use
common\business\Chain33Business
;
use
common\models\psources\CoinExtract
;
use
common\models\psources\CoinPublish
;
use
common\models\psources\CoinPublishRule
;
use
common\models\psources\CoinReleaseCheck
;
use
common\models\psources\CoinReleaseList
;
use
common\models\psources\CoinReleaseMember
;
use
Yii
;
...
...
@@ -82,9 +86,7 @@ class CoinReleaseCheckController extends BaseController
if
(
$model
->
load
(
$get
)
&&
$model
->
validate
())
{
$page
=
$get
[
'page'
]
??
1
;
$limit
=
$page
[
'limit'
]
??
10
;
$query
=
CoinReleaseCheck
::
find
()
->
andFilterWhere
([
'!='
,
'status'
,
0
])
->
andFilterWhere
([
$query
=
CoinReleaseCheck
::
find
()
->
andFilterWhere
([
'!='
,
'status'
,
0
])
->
andFilterWhere
([
'status'
=>
$model
->
status
,
'coin'
=>
$model
->
coin
,
'check_first_uid'
=>
$model
->
check_first_uid
,
...
...
@@ -114,6 +116,10 @@ class CoinReleaseCheckController extends BaseController
}
}
/**
* @return array
* @throws \yii\db\Exception
*/
public
function
actionCheck
()
{
Yii
::
$app
->
response
->
format
=
'json'
;
...
...
@@ -151,7 +157,55 @@ class CoinReleaseCheckController extends BaseController
}
if
(
$model
->
save
(
false
))
{
if
(
$step
==
self
::
STEP_CHECK_SECOND
&&
CoinReleaseCheck
::
CHECK_SECOND_STATUS_SUCCEED
==
$model
->
check_second_status
)
{
//TODO 提币
//TODO 提币 区块链转账接口
$from
=
''
;
$member
=
CoinReleaseMember
::
findOne
(
$model
->
mid
);
if
(
$member
)
{
$coin_publish_rule
=
CoinPublishRule
::
findOne
(
$member
->
rule_id
);
if
(
$coin_publish_rule
)
{
$coin_publish
=
CoinPublish
::
findOne
(
$coin_publish_rule
->
pid
);
if
(
$coin_publish
)
{
$from
=
$coin_publish
->
address
;
}
}
}
if
(
empty
(
$from
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'提币失败'
];
}
if
(
strtoupper
(
$model
->
coin
)
==
'BTY'
)
{
$isToken
=
false
;
}
else
{
$isToken
=
true
;
}
//开启事务
$trans
=
CoinReleaseMember
::
getDb
()
->
beginTransaction
();
//减少用户资产
$member
->
release
-=
$model
->
amount
;
$member
->
output
+=
$model
->
amount
;
if
(
$model
->
save
())
{
$result
=
Chain33Business
::
extractToken
(
$from
,
$model
->
to_address
,
(
int
)
$model
->
amount
,
"锁仓释放"
,
$isToken
,
$model
->
coin
);
if
(
is_array
(
$result
))
{
$trans
->
rollBack
();
return
$result
;
}
$trans
->
commit
();
//保存提币记录到数据库
$coin_release_list
=
new
CoinReleaseList
();
$coin_release_list
->
mid
=
$member
->
id
;
$coin_release_list
->
mobile
=
$member
->
mobile
;
$coin_release_list
->
amount
=
$model
->
amount
;
$coin_release_list
->
coin
=
$model
->
coin
;
$coin_release_list
->
type
=
1
;
//提币
$coin_release_list
->
from
=
$from
;
$coin_release_list
->
to
=
$model
->
to_address
;
$coin_release_list
->
save
();
//使用任务根据txhash查询提币状态s
Yii
::
$app
->
queue
->
delay
(
15
)
->
push
(
new
QueryTransJob
([
'txhash'
=>
$result
,
'lid'
=>
$coin_release_list
->
id
,
'cid'
=>
$model
->
id
]));
}
}
elseif
(
self
::
STEP_CANCEL
==
$step
)
{
//返还币
$assets
=
CoinReleaseMember
::
findOne
(
$model
->
mid
);
...
...
@@ -159,7 +213,7 @@ class CoinReleaseCheckController extends BaseController
$assets
->
release
+=
$model
->
amount
;
$assets
->
output
-=
$model
->
amount
;
if
(
!
$assets
->
save
())
{
//todo loh
Yii
::
warning
(
"撤提失败! [id]:
{
$assets
->
id
}
, [amount]:
$model->amount
"
,
__CLASS__
);
}
}
}
...
...
@@ -169,7 +223,7 @@ class CoinReleaseCheckController extends BaseController
}
}
}
return
[
'code'
=>
0
,
'msg'
=>
'操作失败'
];
return
[
'code'
=>
-
1
,
'msg'
=>
'操作失败'
];
}
}
backend/jobs/ExtractTokenJob.php
deleted
100644 → 0
View file @
8c125d65
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-18
* Time: 下午2:50
*/
namespace
backend\jobs
;
use
Yii
;
use
yii\queue\JobInterface
;
use
yii\queue\Queue
;
use
yii\base\BaseObject
;
use
common\models\psources\CoinReleaseCheck
;
use
common\models\psources\CoinReleaseMember
;
use
common\models\psources\CoinPublishRule
;
use
common\models\psources\CoinPublish
;
use
common\business\Chain33Business
;
/**
* Class ExtractTokenJob
* 提币任务
*
* @package backend\jobs
*/
class
ExtractTokenJob
extends
BaseObject
implements
JobInterface
{
/**
* 提币申请id
*
* @var int $cid
*/
public
$cid
=
0
;
/**
* @param Queue $queue which pushed and is handling the job
* @return integer
*/
public
function
execute
(
$queue
)
{
//获取申请
$apply
=
CoinReleaseCheck
::
findOne
(
$this
->
cid
);
if
(
$apply
)
{
$assets
=
CoinReleaseMember
::
findOne
(
$apply
->
uid
);
if
(
$assets
)
{
$release
=
$assets
->
release
;
if
(
$release
>=
$apply
->
amount
)
{
//提币
$amount
=
$apply
->
amount
/
1e8
;
//获取提币地址
$from
=
''
;
$coin_publish_rule
=
CoinPublishRule
::
findOne
(
$assets
->
rule_id
);
if
(
$coin_publish_rule
)
{
$coin_publish
=
CoinPublish
::
findOne
(
$coin_publish_rule
->
pid
);
if
(
$coin_publish
)
{
$from
=
$coin_publish
->
address
;
}
}
if
(
!
empty
(
$from
))
{
$result
=
Chain33Business
::
extractToken
(
$from
,
$apply
->
to_address
,
$amount
,
''
,
true
,
$apply
->
coin
);
if
(
$result
[
'code'
]
==
0
)
{
$assets
->
release
-=
$amount
;
$assets
->
output
+=
$amount
;
if
(
$assets
->
save
())
{
//提币成功
$apply
->
status
=
CoinReleaseCheck
::
STATUS_PADDING
;
//提币中
if
(
$apply
->
save
())
{
Yii
::
info
(
"提币成功: [申请id]:
$this->cid
"
,
__CLASS__
);
}
Yii
::
warning
(
"提币申请状态修改失败: [申请id]:
$this->cid
"
,
__CLASS__
);
}
else
{
Yii
::
warning
(
"减少用户资产失败: [申请id]:
$this->cid
, [资产]:
$amount
"
,
__CLASS__
);
}
}
else
{
Yii
::
info
(
"提币失败:
{
$result
[
'msg'
]
}
! [申请id]:
$this->cid
"
,
__CLASS__
);
}
}
else
{
Yii
::
info
(
"提币失败: 提币地址不存在! [申请id]:
$this->cid
"
,
__CLASS__
);
}
}
else
{
Yii
::
info
(
"提币失败: 用户资产不足! [申请id]:
$this->cid
"
,
__CLASS__
);
}
}
else
{
Yii
::
info
(
"提币失败: 用户资产信息不存在! [申请id]:
$this->cid
"
,
__CLASS__
);
}
}
else
{
Yii
::
info
(
"提币失败: 提币申请不存在! [申请id]:
$this->cid
"
,
__CLASS__
);
}
return
0
;
}
}
\ No newline at end of file
backend/jobs/FreezeJob.php
View file @
019c8f13
...
...
@@ -8,19 +8,31 @@
namespace
backend\jobs
;
use
common\models\psources\CoinPublish
;
use
common\models\psources\CoinPublishRule
;
use
common\models\psources\CoinReleaseList
;
use
common\models\psources\CoinReleaseMember
;
use
Yii
;
use
yii\base\BaseObject
;
use
yii\queue\JobInterface
;
use
yii\queue\Queue
;
/**
* Class FreezeJob
* 定时释放币任务
*
* @package backend\jobs
*/
class
FreezeJob
extends
BaseObject
implements
JobInterface
{
/**
* @var integer $id 锁仓规则id
*/
public
$id
;
/**
* @param Queue $queue which pushed and is handling the job
* @throws \Exception
* @return integer
*/
public
function
execute
(
$queue
)
...
...
@@ -30,6 +42,9 @@ class FreezeJob extends BaseObject implements JobInterface
// 计划任务已经被删除
return
0
;
}
$coin_publish
=
CoinPublish
::
findOne
(
$coin_publish_rule
->
pid
);
$address
=
$coin_publish
->
address
;
//修改用户的币种冻结信息
$members
=
CoinReleaseMember
::
getMemberByRuleIds
(
$this
->
id
);
...
...
@@ -41,20 +56,31 @@ class FreezeJob extends BaseObject implements JobInterface
}
$value
[
'release'
]
+=
$change
;
$value
[
'freeze'
]
-=
$change
;
$value
[
'change'
]
=
$change
;
}
unset
(
$key
,
$value
);
// 记录解冻操作
Yii
::
info
(
sprintf
(
'Coin Freeze Job Start: sid[%s] lock[%s] release[%s]'
,
$coin_publish_rule
->
sid
,
$coin_publish_rule
->
lock
,
$coin_publish_rule
->
release
),
__CLASS__
);
foreach
(
$members
as
$key
=>
$value
)
{
$trans
=
CoinPublish
::
getDb
()
->
beginTransaction
();
$models
=
CoinReleaseMember
::
findOne
(
$value
[
'id'
]);
$models
->
release
=
$value
[
'release'
];
$models
->
freeze
=
$value
[
'freeze'
];
$models
->
save
();
// 记录解冻操作
Yii
::
info
(
sprintf
(
'member[Id=%s] release amount: %s, freeze still: %s'
,
$value
[
'id'
],
$change
,
$value
[
'freeze'
]),
__CLASS__
);
//记录保存到数据库
$list
=
new
CoinReleaseList
();
$list
->
amount
=
$value
[
'change'
];
$list
->
mobile
=
$value
[
'mobile'
];
$list
->
coin
=
$value
[
'coin'
];
$list
->
type
=
2
;
$list
->
status
=
1
;
$list
->
from
=
$address
;
$list
->
mid
=
$value
[
'id'
];
if
(
$models
->
save
()
&&
$list
->
save
())
{
$trans
->
commit
();
}
$trans
->
rollBack
();
Yii
::
info
(
'释放币失败, [Coin_release_member_id]: '
.
$value
[
'id'
],
__CLASS__
);
}
// 执行下一次任务
if
(
$coin_publish_rule
->
repeat
)
{
$delay_time
=
CoinPublishRule
::
getDelay
(
''
,
$coin_publish_rule
->
repeat
,
strtotime
(
$coin_publish_rule
->
release_time
));
...
...
@@ -63,8 +89,15 @@ class FreezeJob extends BaseObject implements JobInterface
$coin_publish_rule
->
save
();
}
// 记录解冻操作
Yii
::
info
(
sprintf
(
'Coin Freeze Job Finished: sid[%s] lock[%s] release[%s]'
,
$coin_publish_rule
->
sid
,
$coin_publish_rule
->
lock
,
$coin_publish_rule
->
release
),
__CLASS__
);
Yii
::
info
(
sprintf
(
'Coin Freeze Job Finished: sid[%s] lock[%s] release[%s]'
,
$coin_publish_rule
->
sid
,
$coin_publish_rule
->
lock
,
$coin_publish_rule
->
release
),
__CLASS__
);
return
0
;
}
}
backend/jobs/QueryTransJob.php
0 → 100644
View file @
019c8f13
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-18
* Time: 下午2:50
*/
namespace
backend\jobs
;
use
common\models\psources\CoinReleaseList
;
use
Yii
;
use
yii\queue\JobInterface
;
use
yii\queue\Queue
;
use
yii\base\BaseObject
;
use
common\models\psources\CoinReleaseCheck
;
use
common\models\psources\CoinReleaseMember
;
use
common\models\psources\CoinPublishRule
;
use
common\models\psources\CoinPublish
;
use
common\business\Chain33Business
;
/**
* Class ExtractTokenJob
* 查询提币状态任务
*
* @package backend\jobs
*/
class
QueryTransJob
extends
BaseObject
implements
JobInterface
{
/**
* 提币交易hash
*
* @var string $cid
*/
public
$txhash
=
''
;
/**
* coin_release_list id
*
* @var int
*/
public
$lid
=
0
;
/**
* coin_release_check id
*
* @var int
*/
public
$cid
=
0
;
/**
* @param Queue $queue which pushed and is handling the job
* @return integer
*/
public
function
execute
(
$queue
)
{
$coin_release_list
=
CoinReleaseList
::
findOne
(
$this
->
lid
);
$coin_release_check
=
CoinReleaseCheck
::
findOne
(
$this
->
cid
);
if
(
$coin_release_list
&&
$coin_release_check
)
{
$result
=
Chain33Business
::
getTxByHashs
([
$this
->
txhash
]);
if
(
$result
[
'code'
]
==
0
)
{
$result
=
$result
[
'result'
][
'txs'
][
0
][
'receipt'
][
'ty'
]
??
0
;
if
(
$result
==
1
)
{
//转账失败
$coin_release_list
->
status
=
2
;
$coin_release_check
->
status
=
3
;
try
{
$trans
=
CoinReleaseCheck
::
getDb
()
->
beginTransaction
();
if
(
$coin_release_check
->
save
()
&&
$coin_release_list
->
save
())
{
//退换资产
$coin_release_member
=
CoinReleaseMember
::
findOne
(
$coin_release_list
->
mid
);
if
(
$coin_release_member
)
{
$coin_release_member
->
release
+=
$coin_release_list
->
amount
;
$coin_release_member
->
output
-=
$coin_release_list
->
amount
;
if
(
$coin_release_member
->
save
())
{
$trans
->
commit
();
return
0
;
}
}
}
$trans
->
rollBack
();
}
catch
(
\Exception
$exception
)
{
Yii
::
$app
->
queue
->
delay
(
15
)
->
push
(
$this
);
}
return
0
;
}
elseif
(
$result
==
2
)
{
//转账成功
$coin_release_list
->
status
=
1
;
$coin_release_check
->
status
=
4
;
try
{
$trans
=
CoinReleaseCheck
::
getDb
()
->
beginTransaction
();
if
(
$coin_release_check
->
save
()
&&
$coin_release_list
->
save
())
{
$trans
->
commit
();
return
0
;
}
$trans
->
rollBack
();
}
catch
(
\Exception
$exception
)
{
Yii
::
$app
->
queue
->
delay
(
15
)
->
push
(
$this
);
}
}
}
else
{
Yii
::
$app
->
queue
->
delay
(
15
)
->
push
(
$this
);
}
}
return
0
;
}
}
\ No newline at end of file
common/models/psources/CoinPublishRule.php
View file @
019c8f13
...
...
@@ -13,6 +13,7 @@ use Yii;
/**
* CoinPublishRule
* 锁仓规则表
*
* @param integer $qid 任务id
*/
class
CoinPublishRule
extends
BaseActiveRecord
...
...
@@ -132,6 +133,14 @@ class CoinPublishRule extends BaseActiveRecord
$prefix
=
date
(
self
::
DATE_FORMAT_PREFIX
[
$repeat_type
],
$timestamp
);
$next_time
=
$prefix
.
$repeat
;
$next_timestamp
=
strtotime
(
$next_time
);
//如果小于$timestamp, 加上重复的频率
if
(
$next_timestamp
<
$timestamp
)
{
if
(
$repeat_type
==
self
::
REPEAT_YEAR
)
{
$next_timestamp
=
strtotime
(
'+1 year'
,
$next_timestamp
);
}
elseif
(
$repeat_type
==
self
::
REPEAT_MONTH
)
{
$next_timestamp
=
strtotime
(
'+1 month'
,
$next_timestamp
);
}
}
return
$next_timestamp
;
}
...
...
@@ -153,6 +162,7 @@ class CoinPublishRule extends BaseActiveRecord
/**
* 获取当月解冻总量
*
* @param integer $id
* @return integer
*/
...
...
common/models/psources/CoinReleaseList.php
0 → 100644
View file @
019c8f13
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-26
* Time: 下午6:07
*/
namespace
common\models\psources
;
/**
* Class CoinReleaseList
* 国顿账单记录表
*
* @property integer $id
* @property integer $uid
* @property integer $mid
* @property string $mobile
* @property integer $amount
* @property string $coin
* @property integer $type
* @property integer $from
* @property integer $to
* @property integer $status
*
* @package common\models\psources
*/
class
CoinReleaseList
extends
BaseActiveRecord
{
public
static
function
tableName
()
{
return
'coin_release_list'
;
}
}
\ No newline at end of file
console/controllers/DevController.php
View file @
019c8f13
...
...
@@ -17,7 +17,7 @@ use yii\queue\Queue;
use
yii\console\Controller
;
use
common\models\psources\CoinPublishRule
;
use
common\models\psources\CoinReleaseMember
;
use
backend\jobs\
ExtractToken
Job
;
use
backend\jobs\
QueryTrans
Job
;
/**
* Class ExchangeController
...
...
@@ -34,13 +34,17 @@ class DevController extends Controller
*/
public
function
actionFreeze1
()
{
$qid
=
Yii
::
$app
->
queue
->
push
(
new
FreezeJob
([
'id'
=>
4
3
]));
$qid
=
Yii
::
$app
->
queue
->
push
(
new
FreezeJob
([
'id'
=>
4
5
]));
var_dump
(
$qid
);
}
public
function
actionExtractToken
()
{
$id
=
Yii
::
$app
->
queue
->
push
(
new
ExtractTokenJob
([
'cid'
=>
1
]));
$id
=
Yii
::
$app
->
queue
->
push
(
new
QueryTransJob
([
'txhash'
=>
'0x4ee0dd8615a70749a2f2bc38490c9483cf8399da523176f8c7b058afa26294ef'
,
'lid'
=>
25
,
'cid'
=>
16
]));
var_dump
(
$id
);
}
...
...
h5/base/BaseResponse.php
View file @
019c8f13
...
...
@@ -15,13 +15,18 @@ class BaseResponse extends Response
{
public
function
send
()
{
$exception
=
Yii
::
$app
->
errorHandler
->
exception
;
if
(
$exception
)
{
$this
->
format
=
Response
::
FORMAT_JSON
;
$this
->
data
=
[
'code'
=>
$exception
->
getCode
(),
'msg'
=>
$exception
->
getMessage
()];
}
else
{
/**
* @var ResponseBuild $response
*/
$response
=
Yii
::
$app
->
response
->
data
;
Yii
::
$app
->
response
->
format
=
$response
->
format
;
Yii
::
$app
->
response
->
data
=
$response
->
format
();
}
parent
::
send
();
}
}
\ No newline at end of file
h5/controllers/GuodunController.php
View file @
019c8f13
...
...
@@ -12,6 +12,7 @@ use common\models\psources\Coin;
use
common\models\psources\CoinExtract
;
use
common\models\psources\CoinPublishRule
;
use
common\models\psources\CoinReleaseCheck
;
use
common\models\psources\CoinReleaseList
;
use
common\models\psources\CoinReleaseMember
;
use
h5\base\ResponseBuild
;
use
Yii
;
...
...
@@ -76,12 +77,12 @@ class GuodunController extends BaseController
return
$response
;
}
}
$validate
=
ZhaobiBusiness
::
validateCode
(
$uid
,
$codetype
,
$code
,
$type
);
if
(
$validate
[
'code'
]
!=
200
)
{
$response
->
build
(
$validate
[
'code'
],
$validate
[
'message'
]);
return
$response
;
}
//
//
$validate = ZhaobiBusiness::validateCode($uid, $codetype, $code, $type);
//
if ($validate['code'] != 200) {
//
$response->build($validate['code'], $validate['message']);
//
return $response;
//
}
$user_asset
=
CoinReleaseMember
::
findOne
([
$id
]);
//判断余额师傅充足
...
...
@@ -129,4 +130,29 @@ class GuodunController extends BaseController
$extract
->
save
();
return
$response
;
}
public
function
actionBillList
()
{
$response
=
new
ResponseBuild
();
$post
=
Yii
::
$app
->
request
->
post
();
$page
=
$post
[
'page'
]
??
1
;
$limit
=
$post
[
'limit'
]
??
10
;
$type
=
$post
[
'type'
]
??
''
;
//类型,1提币,2锁仓释放
$mobile
=
$post
[
'mobile'
]
??
''
;
if
(
empty
(
$mobile
))
{
$response
->
build
(
ResponseBuild
::
STATUS_PARAMS_NOT_VALIDATE
);
return
$response
;
}
$conditions
=
[
'mobile'
=>
$mobile
];
if
(
$type
)
{
$conditions
[
'type'
]
=
$type
;
}
$datas
=
CoinReleaseList
::
getList2
(
$page
,
$limit
,
$conditions
,
[
'create_time'
=>
SORT_ASC
]);
$response
->
build
(
ResponseBuild
::
STATUS_SUCCEED
,
''
,
$datas
);
return
$response
;
}
}
\ 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