WalletService.php 3.6 KB

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