AddressService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Module\App\Service;
  3. use App\Module\Ulogic\Enum\USER_ADDRESS_TYPE;
  4. use App\Module\Ulogic\Services\UserAddressService;
  5. use Uraus\App\WalletAddress;
  6. class AddressService
  7. {
  8. /**
  9. * @param $userId
  10. * @param $type
  11. * @return array
  12. * 用户保存地址列表
  13. */
  14. public static function list($userId, $type)
  15. {
  16. $map = [
  17. 1 => USER_ADDRESS_TYPE::URAUS->value(),
  18. 2 => USER_ADDRESS_TYPE::USDT->value(),
  19. 3 => USER_ADDRESS_TYPE::BNB->value(),
  20. ];
  21. $coinType = $map[$type] ?? 0;
  22. $list = UserAddressService::list($userId, $coinType);
  23. $resList = [];
  24. foreach ($list as $address) {
  25. $obj = new WalletAddress();
  26. $obj->setAddressId($address->id);
  27. $obj->setType($address->type);
  28. $obj->setAddressName($address->nickname);
  29. $obj->setAddress($address->address);
  30. $resList[] = $obj;
  31. }
  32. return $resList;
  33. }
  34. /**
  35. * @param $userId
  36. * @param $addressType
  37. * @param $addressName
  38. * @param $address
  39. * @return bool
  40. * 添加地址
  41. */
  42. public static function addAddress($userId, $addressType, $addressName, $address)
  43. {
  44. $res = UserAddressService::add($userId, $addressType, $addressName, $address);
  45. if (!$res) {
  46. return false;
  47. }
  48. return true;
  49. }
  50. /**
  51. * @param $userId
  52. * @param $addressId
  53. * @return int
  54. * 删除地址
  55. */
  56. public static function deleteAddress($addressId)
  57. {
  58. $isDelete = UserAddressService::delete($addressId);
  59. if (!$isDelete) {
  60. return false;
  61. }
  62. return true;
  63. }
  64. public static function getDataByAddress($address)
  65. {
  66. return UserAddressService::getDataByAddress($address);
  67. }
  68. }