Commit 4f70fb8a authored by rlgy's avatar rlgy

结构规范

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