WalletAddress.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Module\Ulogic\Models;
  3. use App\Module\Ulogic\Enum\WALLET_ADDRESS_STATUS;
  4. use App\Module\Ulogic\Enum\WALLET_ADDRESS_TYPE;
  5. use Dcat\Admin\Traits\HasDateTimeFormatter;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. use Illuminate\Support\Str;
  9. /**
  10. * 用户钱包地址
  11. * *
  12. * * field start
  13. * * @property int $id 主键id
  14. * * @property int $user_id 用户id
  15. * * @property string $type 地址类型 1:URAUS 2:BNB 3:USDT
  16. * * @property int $status 状态 0删除 1生效
  17. * * @property string $address 地址
  18. * * @property \Carbon\Carbon $created_at
  19. * * @property \Carbon\Carbon $updated_at
  20. * * @property \Carbon\Carbon $deleted_at
  21. * * field end
  22. */
  23. class WalletAddress extends Model
  24. {
  25. use HasDateTimeFormatter;
  26. use SoftDeletes;
  27. protected $table = 'wallet_address';
  28. /**
  29. * @return string
  30. * 生成uraus地址
  31. */
  32. public static function createAddress()
  33. {
  34. do {
  35. $address = Str::lower(Str::random(25)); // 加密安全的随机字符串
  36. } while (
  37. self::query()
  38. ->where(['address' => $address])
  39. ->exists()
  40. );
  41. return $address;
  42. }
  43. /**
  44. * @param $userId
  45. * @param $type
  46. * @param $address
  47. * @return void
  48. * 新增钱包地址
  49. */
  50. public static function createRow($userId, $address)
  51. {
  52. $addressModel = new WalletAddress();
  53. $addressModel->user_id = $userId;
  54. $addressModel->address = $address;
  55. $addressModel->save();
  56. }
  57. /**
  58. * @param $field
  59. * @param $where
  60. * @return null
  61. * 获取数据
  62. */
  63. public static function getInfoByCondition($field, $where)
  64. {
  65. $query = self::query();
  66. $query->where($field, $where);
  67. return $query->first();
  68. }
  69. }