| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Module\Ulogic\Models;
- use App\Module\Ulogic\Enum\WALLET_ADDRESS_STATUS;
- use App\Module\Ulogic\Enum\WALLET_ADDRESS_TYPE;
- use Dcat\Admin\Traits\HasDateTimeFormatter;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Support\Str;
- /**
- * 用户钱包地址
- * *
- * * field start
- * * @property int $id 主键id
- * * @property int $user_id 用户id
- * * @property string $type 地址类型 1:URAUS 2:BNB 3:USDT
- * * @property int $status 状态 0删除 1生效
- * * @property string $address 地址
- * * @property \Carbon\Carbon $created_at
- * * @property \Carbon\Carbon $updated_at
- * * @property \Carbon\Carbon $deleted_at
- * * field end
- */
- class WalletAddress extends Model
- {
- use HasDateTimeFormatter;
- use SoftDeletes;
- protected $table = 'wallet_address';
- /**
- * @return string
- * 生成uraus地址
- */
- public static function createAddress()
- {
- do {
- $address = Str::lower(Str::random(25)); // 加密安全的随机字符串
- } while (
- self::query()
- ->where(['address' => $address])
- ->exists()
- );
- return $address;
- }
- /**
- * @param $userId
- * @param $type
- * @param $address
- * @return void
- * 新增钱包地址
- */
- public static function createRow($userId, $address)
- {
- $addressModel = new WalletAddress();
- $addressModel->user_id = $userId;
- $addressModel->address = $address;
- $addressModel->save();
- }
- /**
- * @param $field
- * @param $where
- * @return null
- * 获取数据
- */
- public static function getInfoByCondition($field, $where)
- {
- $query = self::query();
- $query->where($field, $where);
- return $query->first();
- }
- }
|