EnergyWalletServices.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Service\Energy;
  3. use App\Model\Energy\EnergyPlatformBot;
  4. use App\Library\Log;
  5. use Hyperf\DbConnection\Db;
  6. class EnergyWalletServices
  7. {
  8. /**
  9. * 获取能量钱包列表
  10. * @param $type [0.读取 1.更新]
  11. */
  12. public function getList($type=0){
  13. $res = EnergyPlatformBot::select('rid','receive_wallet','status','get_tx_time')->where('status',0)->whereRaw('length(receive_wallet) = 34')->orderBy('rid')->get();
  14. $data = array();
  15. if($res->count() > 0){
  16. $res = $res->toArray();
  17. foreach ($res as $key => $v) {
  18. $data[$v['rid']] = $v;
  19. }
  20. }
  21. return $res;
  22. }
  23. /**
  24. * 获取收款钱包ID和名称列表 [key为ID value为名称]
  25. * @param $type [0.列表格式1 1.列表格式2 2.列表格式3]
  26. */
  27. public function IDList($type=0){
  28. $data = $this->getList();
  29. $list = [];
  30. if(!empty($data)){
  31. switch ($type) {
  32. case 1:
  33. foreach ($data as $k => $v) {
  34. $list[$k] = $v['receive_wallet'];
  35. }
  36. break;
  37. case 2:
  38. // key为钱包地址
  39. foreach ($data as $k => $v) {
  40. $list[$v['receive_wallet']] = $v;
  41. }
  42. break;
  43. case 3:
  44. // 定时任务过滤状态
  45. foreach ($data as $k => $v) {
  46. if(in_array($v['status'],[0,2])){
  47. $list[] = $v;
  48. }
  49. }
  50. break;
  51. default:
  52. foreach ($data as $k => $v) {
  53. $list[] = [
  54. 'rid' => $v['rid'],
  55. 'receive_wallet' => $v['receive_wallet'],
  56. ];
  57. }
  58. break;
  59. }
  60. }
  61. return $list;
  62. }
  63. /**
  64. * 记入日志
  65. * @param $log_title [日志路径]
  66. * @param $message [内容,不支持数组]
  67. * @param $remarks [备注]
  68. */
  69. protected function log($log_title,$message,$remarks='info'){
  70. Log::get($remarks,$log_title)->info($message);
  71. }
  72. }