findUserWalletAddr($platform_id, $uid, $currency_code); if($mode == WalletPlatformUserWalletAddrHistoryModel::TYPE_BIND && $resOldModel){ //默认检测是否已经绑定过 throw new ModelException('已经绑定过地址'); } try { DB::beginTransaction(); //从钱包地址表取值 $walletAddrModel = new WalletAddrModel(); $oWalletPlatformUserWalletAddrHistoryModel = new WalletPlatformUserWalletAddrHistoryModel(); $walletAddrModel = $walletAddrModel->findUnusedAddrPutUsing($currency_code); if(!$walletAddrModel) throw new ModelException('获取新地址失败'); if($mode == WalletPlatformUserWalletAddrHistoryModel::TYPE_UNBIND){ if($resOldModel){ $res = $this->delItem($resOldModel->id); if(!$res) throw new ModelException('删除原有地址失败'); $res = $oWalletPlatformUserWalletAddrHistoryModel->addUserWalletAddrHistory($resOldModel->toArray(),WalletPlatformUserWalletAddrHistoryModel::TYPE_UNBIND); if(!$res) throw new ModelException('增加历史绑定地址失败'); } } $insert = [ 'platform_id' => $platform_id, 'uid' => $uid, 'wallet_addr_id' => $walletAddrModel->id, 'wallet_addr' => $walletAddrModel->addr, 'currency_id' => $walletAddrModel->currency_id, 'currency_code' => $walletAddrModel->currency_code, 'created_at' => Times::getNowDateTime(), ]; $resModel = $this->addItem($insert); if($resModel) $oWalletPlatformUserWalletAddrHistoryModel->addUserWalletAddrHistory($resModel->toArray(),WalletPlatformUserWalletAddrHistoryModel::TYPE_BIND); DB::commit(); }catch (\Exception $e) { DB::rollBack(); throw $e; } return $resModel; } function findUserWalletAddr($platform_id, $uid, $currency_code): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null { return $this->findItemByWhere(['platform_id' => $platform_id, 'uid' => $uid, 'currency_code' => $currency_code]); } function findByWalletAddrId($wallet_addr_id): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null { return $this->findItemByWhere(['from_wallet_addr_id' => $wallet_addr_id]); } }