WalletAddress.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * field end
  14. */
  15. class WalletAddress extends Model
  16. {
  17. use HasDateTimeFormatter;
  18. use SoftDeletes;
  19. protected $table = 'wallet_address';
  20. /**
  21. * @return string
  22. * 生成uraus地址
  23. */
  24. public static function createAddress()
  25. {
  26. do {
  27. $address = Str::lower(Str::random(25)); // 加密安全的随机字符串
  28. } while (
  29. self::query()
  30. ->where(['address' => $address])
  31. ->exists()
  32. );
  33. return $address;
  34. }
  35. /**
  36. * @param $userId
  37. * @param $type
  38. * @param $address
  39. * @return void
  40. * 新增钱包地址
  41. */
  42. public static function createRow($userId, $address)
  43. {
  44. $addressModel = new WalletAddress();
  45. $addressModel->user_id = $userId;
  46. $addressModel->address = $address;
  47. $addressModel->save();
  48. }
  49. /**
  50. * @param $field
  51. * @param $where
  52. * @return null
  53. * 获取数据
  54. */
  55. public static function getInfoByCondition($field, $where)
  56. {
  57. $query = self::query();
  58. $query->where($field, $where);
  59. return $query->first();
  60. }
  61. }