EtcWithdrawRecordModel.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\common\model;
  3. use fast\Asset;
  4. use fast\Http;
  5. use fast\Random;
  6. use think\Cache;
  7. use think\Log;
  8. use think\Model;
  9. use think\Request;
  10. class EtcWithdrawRecordModel extends Model
  11. {
  12. protected $name = "etc_withdraw_record";
  13. /*
  14. * 获取ETC的USDT价格
  15. */
  16. public function getEtcPrice(){
  17. $etc_price = Cache::remember('etc_price', function(){
  18. $etc_usdt_price = 16;
  19. $url = "https://www.binance.com/api/v1/klines?symbol=ETCUSDT&limit=1&interval=3m";
  20. $body = Http::get($url);
  21. if (empty($body)) {
  22. dump('获取ETC价格接口返回为空');
  23. Log::info('拨币时:获取ETC价格接口返回为空');
  24. return "获取ETC价格接口返回为空";
  25. }
  26. // 转成数组
  27. $rsArr = json_decode($body, true);
  28. $etc_usdt_price = $rsArr[0][2];
  29. return $etc_usdt_price;
  30. }, 36000);
  31. if(empty($etc_price)){
  32. $etc_price = 16;
  33. }
  34. return $etc_price;
  35. }
  36. }