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
7e766367
Commit
7e766367
authored
Oct 31, 2018
by
ZhuChunYang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
彩票功能重构
parent
15ec0f4e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
161 additions
and
53 deletions
+161
-53
LotteryBusiness.php
common/business/LotteryBusiness.php
+41
-4
CoinLottery.php
common/models/psources/CoinLottery.php
+5
-3
LotteryService.php
common/service/chain33/LotteryService.php
+34
-4
LotteryController.php
console/controllers/LotteryController.php
+81
-42
No files found.
common/business/LotteryBusiness.php
View file @
7e766367
...
...
@@ -8,9 +8,8 @@
namespace
common\business
;
use
common\models\psources\Coin
;
use
common\service\chain33\LotteryService
;
use
common\service\coin\CoinFactory
;
use
Yii
;
class
LotteryBusiness
{
...
...
@@ -19,12 +18,14 @@ class LotteryBusiness
*/
public
static
function
trade
(
$amount
,
$number
,
$way
,
$fee
)
{
$config
=
Yii
::
$app
->
params
[
'lottery'
];
$key
=
$config
[
'key'
];
$error
=
''
;
$service
=
new
LotteryService
();
$trade_result
=
$service
->
trade
(
$amount
,
$number
,
$way
,
$fee
);
if
(
$trade_result
[
'code'
]
==
0
)
{
//交易成功
$trade_txhex
=
$trade_result
[
'result'
];
$sign_result
=
$service
->
sign
(
$trade_txhex
);
$sign_result
=
$service
->
sign
(
$
key
,
$
trade_txhex
);
if
(
$sign_result
[
'code'
]
==
0
){
//签名成功
$data
=
$sign_result
[
'result'
];
$send_transaction_result
=
$service
->
sendTransaction
(
$data
);
...
...
@@ -45,12 +46,14 @@ class LotteryBusiness
*/
public
static
function
lottery
(
$fee
=
0
)
{
$config
=
Yii
::
$app
->
params
[
'lottery'
];
$key
=
$config
[
'createor_key'
];
$error
=
''
;
$service
=
new
LotteryService
();
$lottery_result
=
$service
->
lottery
(
$fee
);
if
(
$lottery_result
[
'code'
]
==
0
)
{
//交易成功
$lottery_txhex
=
$lottery_result
[
'result'
];
$sign_result
=
$service
->
sign
(
$lottery_txhex
);
$sign_result
=
$service
->
sign
(
$
key
,
$
lottery_txhex
);
if
(
$sign_result
[
'code'
]
==
0
){
//签名成功
$data
=
$sign_result
[
'result'
];
$send_transaction_result
=
$service
->
sendTransaction
(
$data
);
...
...
@@ -65,4 +68,38 @@ class LotteryBusiness
}
return
[
'code'
=>
-
1
,
'msg'
=>
$error
];
}
/**
* @return array
* 获取当前彩票信息
*/
public
static
function
getLotteryCurrentInfo
()
{
$service
=
new
LotteryService
();
$lottery_current_info
=
$service
->
getLotteryCurrentInfo
();
if
(
$lottery_current_info
[
'code'
]
==
0
)
{
//交易成功
$result
=
$lottery_current_info
[
'result'
];
return
[
'code'
=>
0
,
'result'
=>
$result
];
}
else
{
$error
=
$lottery_current_info
[
'msg'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
$error
];
}
/**
* @param $round
* 获取指定期数中奖号码
*/
public
static
function
getLuckyNumber
(
$round
)
{
$service
=
new
LotteryService
();
$lottery_current_info
=
$service
->
getLuckyNumber
(
$round
);
if
(
$lottery_current_info
[
'code'
]
==
0
)
{
//交易成功
$result
=
$lottery_current_info
[
'result'
];
return
[
'code'
=>
0
,
'result'
=>
$result
];
}
else
{
$error
=
$lottery_current_info
[
'msg'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
$error
];
}
}
common/models/psources/CoinLottery.php
View file @
7e766367
...
...
@@ -40,13 +40,15 @@ class CoinLottery extends BaseActiveRecord
return
self
::
find
()
->
where
([
'date'
=>
$date
])
->
orderBy
([
'stage'
=>
SORT_DESC
])
->
one
();
}
public
static
function
addOneRecord
(
$start_height
,
$
end_height
,
$stag
e
)
public
static
function
addOneRecord
(
$start_height
,
$
last_lottery_height
,
$stage
,
$round
,
$start_dat
e
)
{
$coin_lottery
=
new
self
();
$coin_lottery
->
stage
=
$stage
;
$coin_lottery
->
start_height
=
$start_height
;
$coin_lottery
->
end_height
=
$end_height
;
$coin_lottery
->
date
=
date
(
'Y-m-d'
);
$coin_lottery
->
last_lottery_height
=
$last_lottery_height
;
$coin_lottery
->
status
=
2
;
$coin_lottery
->
round
=
$round
;
$coin_lottery
->
date
=
$start_date
;
$coin_lottery
->
save
();
}
...
...
common/service/chain33/LotteryService.php
View file @
7e766367
...
...
@@ -104,17 +104,47 @@ class LotteryService
return
$this
->
send
(
$params
,
'Chain33.CreateRawLotteryDrawTx'
);
}
/**
* 获取lottery当前信息
*/
public
function
getLotteryCurrentInfo
()
{
$config
=
Yii
::
$app
->
params
[
'lottery'
];
$lotterId
=
$config
[
'lotteryId'
];
$params
=
[
"execer"
=>
'lottery'
,
"funcName"
=>
"GetLotteryCurrentInfo"
,
"payload"
=>
[
'lotteryId'
=>
$lotterId
]
];
return
$this
->
send
(
$params
,
'Chain33.Query'
);
}
/**
* @param $round
* @return array|mixed
* 获取中奖号码
*/
public
function
getLuckyNumber
(
$round
)
{
$config
=
Yii
::
$app
->
params
[
'lottery'
];
$lotterId
=
$config
[
'lotteryId'
];
$params
=
[
"execer"
=>
'lottery'
,
"funcName"
=>
"GetLotteryRoundLuckyNumber"
,
"payload"
=>
[
'lotteryId'
=>
$lotterId
,
'round'
=>
$round
]
];
return
$this
->
send
(
$params
,
'Chain33.Query'
);
}
/**
* @param $txhex
* @return array|mixed
* 签名
*/
public
function
sign
(
$txhex
)
public
function
sign
(
$
key
,
$
txhex
)
{
$config
=
Yii
::
$app
->
params
[
'lottery'
];
$addr
=
$config
[
'addr'
];
$key
=
$config
[
'key'
];
$params
=
[
//'addr' => $addr,
'privkey'
=>
$key
,
...
...
console/controllers/LotteryController.php
View file @
7e766367
This diff is collapsed.
Click to expand it.
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