| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\NoticeModel;
- use App\Models\PriceModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 价格服务-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class PriceService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * NoticeService constructor.
- */
- public function __construct()
- {
- $this->model = new PriceModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 当前价格
- * @param int $type 1-数字资产,2-绿色积分
- * @param false $refresh
- * @return array|mixed|string
- */
- public function getTodayPrice($type=1, $refresh=false)
- {
- $cacheKey = "caches:prices:today_price_{$type}";
- $data = RedisService::get($cacheKey);
- $price = isset($data['price'])?$data['price']: '0.00';
- if($data && $price && !$refresh){
- return $price;
- }
- $data = $this->model->where(['type'=>$type,'status'=>1,'mark'=>1])
- ->orderBy('date','desc')
- ->first();
- $data = $data?$data->toArray() : [];
- $price = isset($data['price'])?$data['price']: '0.00';
- if($data && $price){
- RedisService::set($cacheKey, $data, rand(300,600));
- }
- return $price;
- }
- public function updatePrice($type=1)
- {
- }
- }
|