WalletService.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\ActionLogModel;
  13. use App\Models\WalletModel;
  14. use App\Services\BaseService;
  15. use Illuminate\Support\Facades\Auth;
  16. /**
  17. * 承兑商管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * @package App\Services\Common
  21. */
  22. class WalletService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new WalletModel();
  32. }
  33. /**
  34. * 获取列表
  35. * @param $params 参数
  36. * @param int $pageSize 分页大小:默认 15
  37. * @return array
  38. */
  39. public function getDataList($params, $pageSize = 10, $field = [])
  40. {
  41. $where = ['a.mark' => 1];
  42. if (!empty($params['type'])) {
  43. $where['a.type'] = $params['type'];
  44. }
  45. if (isset($params['status']) && $params['status'] != '') {
  46. $where['a.status'] = $params['status'];
  47. }
  48. $list = $this->model
  49. ->from('wallet as a')
  50. ->where($where)
  51. ->select($field ? $field : ['a.*'])
  52. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  53. $list = $list ? $list->toArray() : [];
  54. if ($list) {
  55. foreach ($list['data'] as &$item){
  56. $item['balance'] = \App\Services\WalletService::make()->getBalance($item['address']);
  57. $usdtData = \App\Services\WalletService::make()->getUsdtBalance($item['address']);
  58. $item['usdt'] = isset($usdtData['amount'])? $usdtData['amount'] : '0.00';
  59. }
  60. }
  61. return [
  62. 'pageSize' => $pageSize,
  63. 'total' => isset($list['total']) ? $list['total'] : 0,
  64. 'list' => isset($list['data']) ? $list['data'] : []
  65. ];
  66. }
  67. /**
  68. * 添加会编辑会员
  69. * @return array
  70. * @since 2020/11/11
  71. * @author laravel开发员
  72. */
  73. public function edit()
  74. {
  75. // 请求参数
  76. $data = request()->all();
  77. if (!isset($data['address']) || $data['address'] == '') {
  78. return message("地址不能为空", false);
  79. }
  80. if(!empty($data['address'])){
  81. if (!\App\Services\WalletService::make()->checkAddress($data['address'])) {
  82. return message('地址验证失败');
  83. }
  84. }
  85. if (!isset($data['type']) || $data['type'] == '') {
  86. return message("钱包类型不能为空", false);
  87. }
  88. if (intval($data['type']) ==2 && (!isset($data['private_key']) || $data['private_key'] == '')) {
  89. return message("秘钥不能为空", false);
  90. }
  91. if (!isset($data['name']) || $data['name'] == '') {
  92. return message("钱包名称不能为空", false);
  93. }
  94. if (!isset($data['status']) || $data['status'] == '') {
  95. return message("状态不能为空", false);
  96. }
  97. ActionLogModel::setTitle("新增/修改平台钱包");
  98. ActionLogModel::record();
  99. return parent::edit($data); // TODO: Change the autogenerated stub
  100. }
  101. }