Commit 7e766367 authored by ZhuChunYang's avatar ZhuChunYang

彩票功能重构

parent 15ec0f4e
...@@ -8,9 +8,8 @@ ...@@ -8,9 +8,8 @@
namespace common\business; namespace common\business;
use common\models\psources\Coin;
use common\service\chain33\LotteryService; use common\service\chain33\LotteryService;
use common\service\coin\CoinFactory; use Yii;
class LotteryBusiness class LotteryBusiness
{ {
...@@ -19,12 +18,14 @@ class LotteryBusiness ...@@ -19,12 +18,14 @@ class LotteryBusiness
*/ */
public static function trade($amount, $number, $way, $fee) public static function trade($amount, $number, $way, $fee)
{ {
$config = Yii::$app->params['lottery'];
$key = $config['key'];
$error = ''; $error = '';
$service = new LotteryService(); $service = new LotteryService();
$trade_result = $service->trade($amount, $number, $way, $fee); $trade_result = $service->trade($amount, $number, $way, $fee);
if ($trade_result['code'] == 0) { //交易成功 if ($trade_result['code'] == 0) { //交易成功
$trade_txhex = $trade_result['result']; $trade_txhex = $trade_result['result'];
$sign_result = $service->sign($trade_txhex); $sign_result = $service->sign($key,$trade_txhex);
if($sign_result['code'] == 0){ //签名成功 if($sign_result['code'] == 0){ //签名成功
$data = $sign_result['result']; $data = $sign_result['result'];
$send_transaction_result = $service->sendTransaction($data); $send_transaction_result = $service->sendTransaction($data);
...@@ -45,12 +46,14 @@ class LotteryBusiness ...@@ -45,12 +46,14 @@ class LotteryBusiness
*/ */
public static function lottery($fee = 0) public static function lottery($fee = 0)
{ {
$config = Yii::$app->params['lottery'];
$key = $config['createor_key'];
$error = ''; $error = '';
$service = new LotteryService(); $service = new LotteryService();
$lottery_result = $service->lottery($fee); $lottery_result = $service->lottery($fee);
if ($lottery_result['code'] == 0) { //交易成功 if ($lottery_result['code'] == 0) { //交易成功
$lottery_txhex = $lottery_result['result']; $lottery_txhex = $lottery_result['result'];
$sign_result = $service->sign($lottery_txhex); $sign_result = $service->sign($key,$lottery_txhex);
if($sign_result['code'] == 0){ //签名成功 if($sign_result['code'] == 0){ //签名成功
$data = $sign_result['result']; $data = $sign_result['result'];
$send_transaction_result = $service->sendTransaction($data); $send_transaction_result = $service->sendTransaction($data);
...@@ -65,4 +68,38 @@ class LotteryBusiness ...@@ -65,4 +68,38 @@ class LotteryBusiness
} }
return ['code' => -1, 'msg' => $error]; 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];
}
} }
...@@ -40,13 +40,15 @@ class CoinLottery extends BaseActiveRecord ...@@ -40,13 +40,15 @@ class CoinLottery extends BaseActiveRecord
return self::find()->where(['date' => $date])->orderBy(['stage' => SORT_DESC])->one(); return self::find()->where(['date' => $date])->orderBy(['stage' => SORT_DESC])->one();
} }
public static function addOneRecord($start_height,$end_height,$stage) public static function addOneRecord($start_height,$last_lottery_height,$stage,$round,$start_date)
{ {
$coin_lottery = new self(); $coin_lottery = new self();
$coin_lottery->stage = $stage; $coin_lottery->stage = $stage;
$coin_lottery->start_height = $start_height; $coin_lottery->start_height = $start_height;
$coin_lottery->end_height = $end_height; $coin_lottery->last_lottery_height = $last_lottery_height;
$coin_lottery->date = date('Y-m-d'); $coin_lottery->status = 2;
$coin_lottery->round = $round;
$coin_lottery->date = $start_date;
$coin_lottery->save(); $coin_lottery->save();
} }
......
...@@ -104,17 +104,47 @@ class LotteryService ...@@ -104,17 +104,47 @@ class LotteryService
return $this->send($params, 'Chain33.CreateRawLotteryDrawTx'); 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 * @param $txhex
* @return array|mixed * @return array|mixed
* 签名 * 签名
*/ */
public function sign($txhex) public function sign($key,$txhex)
{ {
$config = Yii::$app->params['lottery'];
$addr = $config['addr'];
$key = $config['key'];
$params = [ $params = [
//'addr' => $addr, //'addr' => $addr,
'privkey' => $key, 'privkey' => $key,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment