Commit 4f70fb8a authored by rlgy's avatar rlgy

结构规范

parent cf355d7f
...@@ -10,7 +10,6 @@ namespace common\business; ...@@ -10,7 +10,6 @@ namespace common\business;
use common\models\pwallet\Coin; use common\models\pwallet\Coin;
use common\service\coin\CoinFactory; use common\service\coin\CoinFactory;
use common\service\CoinService;
/** /**
* 币种逻辑层 * 币种逻辑层
...@@ -34,7 +33,8 @@ class CoinBusiness ...@@ -34,7 +33,8 @@ class CoinBusiness
$datas = $rows['data']; $datas = $rows['data'];
foreach ($datas as $key => $value) { foreach ($datas as $key => $value) {
//获取交易所信息 //获取交易所信息
$rows['data'][$key]['exchange'] = CoinService::exchange_count($value['sid']); $coin = CoinFactory::createCoin($value['name'], $value['id'], $value['sid']);
$rows['data'][$key]['exchange'] = $coin->exchange_count();
} }
} }
return $rows; return $rows;
...@@ -51,7 +51,8 @@ class CoinBusiness ...@@ -51,7 +51,8 @@ class CoinBusiness
if ($id) { if ($id) {
$coin = Coin::findOne(['id' => $id]); $coin = Coin::findOne(['id' => $id]);
if ($coin) { if ($coin) {
$datas = CoinService::exchange($coin->sid); $model = CoinFactory::createCoin($coin->name, $coin->id, $coin->sid);
$datas = $model->exchange();
if ($datas['count'] > 0) { if ($datas['count'] > 0) {
return $datas['data']; return $datas['data'];
} }
...@@ -73,12 +74,8 @@ class CoinBusiness ...@@ -73,12 +74,8 @@ class CoinBusiness
if ($rows['count'] > 0) { if ($rows['count'] > 0) {
$rows = $rows['data']; $rows = $rows['data'];
foreach ($rows as $key => $value) { foreach ($rows as $key => $value) {
//获取行情信息 $coin = CoinFactory::createCoin($value['name'], $value['id'], $value['sid']);
if (strtoupper($value['name']) == 'BTY') { $rows[$key]['quotation'] = $coin->quotation();
$rows[$key]['quotation'] = CoinService::quotationBTY();
continue;
}
$rows[$key]['quotation'] = CoinService::quotation($value['sid']);
} }
} }
return $rows; return $rows;
...@@ -138,14 +135,11 @@ class CoinBusiness ...@@ -138,14 +135,11 @@ class CoinBusiness
{ {
$row = Coin::find()->where(['id' => $id])->asArray()->One(); $row = Coin::find()->where(['id' => $id])->asArray()->One();
if ($row) { if ($row) {
$coin = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
//TODO 获取行情 //TODO 获取行情
$row['quotation'] = CoinService::quotation($row['sid']); $row['quotation'] = $coin->quotation($row['sid']);
//行情BTY
if (strtoupper($row['name']) == 'BTY') {
$row['quotation'] = CoinService::quotationBTY();
}
//TODO 获取交易所详情 //TODO 获取交易所详情
$row['exchange'] = CoinService::exchange($row['sid']); $row['exchange'] = $coin->exchange($row['sid']);
} }
return $row ? [$row] : []; return $row ? [$row] : [];
} }
......
This diff is collapsed.
...@@ -10,6 +10,23 @@ namespace common\service\coin; ...@@ -10,6 +10,23 @@ namespace common\service\coin;
class CoinBTYService extends Coin implements CoinInterface class CoinBTYService extends Coin implements CoinInterface
{ {
public function exchange()
{
// TODO: Implement exchange() method.
return ['count' => 0, 'data' => []];
}
public function exchange_count()
{
// TODO: Implement exchange_count() method.
return 0;
}
public function quotation()
{
// TODO: Implement quotation() method.
}
public function __construct($id, $sid) public function __construct($id, $sid)
{ {
......
...@@ -18,4 +18,10 @@ interface CoinInterface ...@@ -18,4 +18,10 @@ interface CoinInterface
//币种销毁 //币种销毁
public function __destruct(); public function __destruct();
public function exchange();
public function exchange_count();
public function quotation();
} }
\ No newline at end of file
...@@ -399,18 +399,18 @@ class CoinService extends Coin implements CoinInterface ...@@ -399,18 +399,18 @@ class CoinService extends Coin implements CoinInterface
* @param $name string 币种名称 * @param $name string 币种名称
* @return array * @return array
*/ */
public static function exchange($name = 'eos') public function exchange()
{ {
//缓存数据 //缓存数据
$key = [ $key = [
__CLASS__, __CLASS__,
__METHOD__, __METHOD__,
'coin',//表名 'coin',//表名
$name,//sid $this->sid,//sid
]; ];
$result = Yii::$app->cache->get($key); $result = Yii::$app->cache->get($key);
if ($result === false) { if ($result === false) {
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['coinmarket'] . $name . '/'; $url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['coinmarket'] . $this->sid . '/';
$ch = new Curl(); $ch = new Curl();
try { try {
$content = $ch->get($url, true); $content = $ch->get($url, true);
...@@ -453,17 +453,17 @@ class CoinService extends Coin implements CoinInterface ...@@ -453,17 +453,17 @@ class CoinService extends Coin implements CoinInterface
* @param string $sid * @param string $sid
* @return integer|bool * @return integer|bool
*/ */
public static function exchange_count($sid = 'eos') public function exchange_count()
{ {
$key = [ $key = [
__CLASS__, __CLASS__,
__METHOD__, __METHOD__,
'coin',//表名 'coin',//表名
$sid,//sid $this->sid,//sid
]; ];
$result = Yii::$app->cache->get($key); $result = Yii::$app->cache->get($key);
if (!$result) { if (!$result) {
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['coinmarket'] . $sid . '/'; $url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['coinmarket'] . $this->sid . '/';
$ch = new Curl(); $ch = new Curl();
try { try {
$content = $ch->get($url, true); $content = $ch->get($url, true);
...@@ -490,18 +490,18 @@ class CoinService extends Coin implements CoinInterface ...@@ -490,18 +490,18 @@ class CoinService extends Coin implements CoinInterface
* @param string $sid * @param string $sid
* @return object|string * @return object|string
*/ */
public static function quotation($sid = 'eos') public function quotation()
{ {
//使用缓存 //使用缓存
$key = [ $key = [
__CLASS__, __CLASS__,
__METHOD__, __METHOD__,
'coin',//表名 'coin',//表名
$sid,//sid $this->sid,//sid
]; ];
$result = Yii::$app->cache->get($key); $result = Yii::$app->cache->get($key);
if ($result === false) { if ($result === false) {
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['currencies'] . $sid . '/'; $url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['currencies'] . $this->sid . '/';
$ch = new Curl(); $ch = new Curl();
try { try {
$content = $ch->get($url, true); $content = $ch->get($url, true);
......
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