def post(self): request_data = self.get_argument_dict() # query information search_user_id = request_data.get("search_user_id", None) user_name = request_data.get("user_name", None) email = request_data.get("email", None) user_mobile = request_data.get("user_mobile", None) register_time_start = request_data.get("register_time_start", None) register_time_end = request_data.get("register_time_end", None) source = request_data.get("user_source", None) recharge_time_start = request_data.get("recharge_time_start", None) recharge_time_end = request_data.get("recharge_time_end", None) # page information page_num = request_data.get("offset", 1) page_limit = request_data.get("limit", 10) service = AccountService() result = service.get_user_list(search_user_id, user_name, email, user_mobile, register_time_start, register_time_end, source, recharge_time_start, recharge_time_end, page_num, page_limit) return self.utctime_to_localtime(result)
def change_account_amount(client_id, account_id): try: content = request.get_json() try: withdrawal_amount = content['withdrawal'] account = Account(int(account_id), "", float(withdrawal_amount), int(client_id)) update_item = AccountService.get_withdrawal(account).json() return jsonify( AccountService.update_account_amount(update_item)), 200 except KeyError: print("caught key error") pass deposit_amount = content['deposit'] account = Account(int(account_id), "", float(deposit_amount), int(client_id)) update_item = AccountService.get_deposit(account) return jsonify( AccountService.update_account_amount(update_item)), 200 except ResourceNotFound as r: return r.message, 404 except ResourceAmountInsufficient as rai: return rai.message, 422 except ResourceUnavailable as ru: return ru.message, 403
def post(self): request_data = self.get_argument_dict() user_id = request_data.get("search_user_id", None) user_name = request_data.get("user_name", None) change_type = request_data.get("change_type", None) page_num = request_data.get("offset", 1) page_limit = request_data.get("limit", 10) token_id = request_data.get("token_id", None) water_id = request_data.get("water_id", None) finish_time_start = request_data.get("finish_time_start", None) finish_time_end = request_data.get("finish_time_end", None) account_service = AccountService() result = account_service.list_all_account_water( user_id=user_id, change_type=change_type, page_num=page_num, page_limit=page_limit, token_id=token_id, water_id=water_id, finish_time_start=finish_time_start, user_name=user_name, finish_time_end=finish_time_end, ) return self.utctime_to_localtime(result)
def post_account(client_id): try: account = Account.json_parse(request.json) AccountService.create_account(account, client_id) return jsonify(account.json()), 201 except ResourceNotFound as r: return r.message, 404
def post(self): request_data = self.get_argument_dict(must_keys=[ 'user_id', 'pay_password', 'coin_id', 'withdraw_amount', 'withdraw_fee', 'withdraw_address', 'source' ], check_form_token=True) user_id = request_data['user_id'] pay_password = request_data['pay_password'] coin_id = request_data['coin_id'] withdraw_amount = request_data['withdraw_amount'] withdraw_fee = request_data['withdraw_fee'] withdraw_address = request_data['withdraw_address'] source = request_data['source'] memo = request_data.get('memo', '') account_service = AccountService() # 校验支付密码 account_service.check_pay_password(user_id, pay_password) result = account_service.apply_withdraw(user_id, coin_id, withdraw_amount, withdraw_fee, withdraw_address, source, memo=memo) return result
def patch_account(client_id, account_id): is_withdraw = 'withdraw' in request.json is_deposit = 'deposit' in request.json if is_withdraw: amount = request.json['withdraw'] try: AccountService.remove_funds(client_id, account_id, amount) return f"Successfully withdrew {amount} from account {account_id}", 200 except ValueError as e: return "Incorrect Value Type", 400 except InsufficientFunds as f: return f.message, 422 except ResourceNotFound as r: return r.message, 404 elif is_deposit: amount = request.json['deposit'] try: AccountService.add_funds(client_id, account_id, amount) return f"Successfully deposited {amount} into account {account_id}", 200 except ValueError as e: return "Incorrect Value Type", 400 except ResourceNotFound as r: return r.message, 404 else: abort( 400, "Body must contain a JSON with either a 'withdraw' or 'deposit' property" )
def post(self): request_data = self.get_argument_dict(must_keys=['user_id']) user_id = request_data['user_id'] account_service = AccountService() result = account_service.get_inviter_code(user_id) return {"url": get_host_url() + '/login?inviter_code=' + result}
def transfer_between_accounts(id_from, id_into): try: try: content = request.get_json() withdrawal_amount = float(content['amount']) account_from = Account(id_from, "", withdrawal_amount, 5) update_item = AccountService.get_transfer_account_from( account_from) final_account_something = AccountService.update_accounts_after_transfer( update_item) except KeyError: print("caught key error") pass deposit_amount = content['amount'] account_into = Account(id_into, "", deposit_amount, 5) update_item = AccountService.get_transfer_account_into( account_into) return (jsonify( final_account_something, AccountService.update_accounts_after_transfer(update_item)) ), 200 except ResourceNotFound as r: return r.message, 404 except ResourceAmountInsufficient as rai: return rai.message, 422 except ResourceUnavailable as ru: return ru.message, 403
def post(self): request_data = self.get_argument_dict(must_keys=['user_id']) user_id = request_data['user_id'] account_service = AccountService() result = account_service.lottery(user_id) return result
def post(self, inviter_code=None): request_data = self.get_argument_dict(must_keys=['user_id']) user_id = request_data['user_id'] nick_name = request_data.get("nick_name", "") user_mobile = request_data.get("user_mobile", "") mobile_country_code = request_data.get("mobile_country_code", "") email = request_data.get("email", "") user_name = request_data.get("user_name", "") source = request_data.get("register_source", "") register_ip = request_data.get("register_ip", "") inviter_code = request_data.get("inviter_code", None) profile_picture = request_data.get("profile_picture", "") account_service = AccountService() result = account_service.user_generate_account( user_id, nick_name=nick_name, user_mobile=user_mobile, email=email, mobile_country_code=mobile_country_code, user_name=user_name, source=source, register_ip=register_ip, code=inviter_code, profile_picture=profile_picture) return result
def post(self): request_data = self.get_argument_dict(must_keys=['user_id', 'email']) user_id = request_data['user_id'] email = request_data['email'] account_service = AccountService() response_data = account_service.set_email(user_id, email) return response_data
def put_account(cl_id, account_id): account = Account.json_parse_account(request.json) account.account_id = int(account_id) try: AccountService.update_account(account) return jsonify(account.json()), 200 except ValueError: print("Not Found")
def post(self): request_data = self.get_argument_dict(must_keys=['user_id', 'avatar']) user_id = request_data['user_id'] avatar = request_data['avatar'] account_service = AccountService() response_data = account_service.set_avatar(user_id, avatar) return response_data
def delete_account(client_id, account_id): try: AccountService.delete_account(client_id, account_id) return '', 204 except ValueError as e: return "Incorrect value type", 400 except ResourceNotFound as r: return r.message, 404
def run(): '''run app''' #initial logging logging config logging.config.dictConfig(app_settings.LOGGING) OrderService.get_service_name() AccountService.get_service_name() OrderService.get_path()
def post(self): request_data = self.get_argument_dict( must_keys=['user_id', 'profile_picture']) user_id = request_data['user_id'] profile_picture = request_data['profile_picture'] account_service = AccountService() result = account_service.update_user_profile_picture( user_id, profile_picture) return result
def post(self): request_data = self.get_argument_dict( must_keys=['user_id', 'nick_name']) user_id = request_data['user_id'] nick_name = request_data['nick_name'] account_service = AccountService() response_data = account_service.set_nick_name(user_id, nick_name) return response_data
def post(self): request_data = self.get_argument_dict( must_keys=['user_id', 'password']) user_id = request_data['user_id'] password = request_data['password'] account_service = AccountService() response_data = account_service.reset_pay_password(user_id, password) return response_data
def post(self): request_data = self.get_argument_dict(must_keys=['user_id', 'coin_id']) user_id = request_data['user_id'] coin_id = request_data['coin_id'] do_reset = request_data.get("do_reset", False) account_service = AccountService() result = account_service.apply_recharge(user_id, coin_id, do_reset) return result
def update_account(client_id, account_id): try: account = Account.json_parse(request.json) account.account_id = int(account_id) account.account_client_id = int(client_id) AccountService.update_account(account) return jsonify(account.json()), 201 except ResourceNotFound as r: return r.message, 404
def dice_chip_in_new(self, user_id, user_channel_id, coin_id, bet_amount, user_dice): change_type_31 = '31' # 扣款 change_type_32 = '32' # 返还 change_type_33 = '33' # 中奖 with MysqlTools().session_scope() as session: # 查询用户资产 account_service = AccountService() user_info = account_service.get_inner_user_account_by_token( session, user_id, coin_id) if isinstance(user_info, int): if user_info == 20001: return self.return_error(20001) balance = get_decimal(user_info.get("balance"), digits=8, decimal_type="down") # 账户余额 < 需要下注金额 bet_number = get_decimal(bet_amount, digits=4, decimal_type="down") if balance < bet_number: return self.return_error(60005) dice_serial = dice_generate_phase() dice_time = get_timestamp() dice_part_in_model = DiceParticipateInModel( dice_serial=dice_serial, user_id=user_id, user_dice=user_dice, channel=user_channel_id, bet_number=bet_number, bet_token=coin_id, reward_token=coin_id, reward_quantity=bet_number, dice_timestamp=dice_time) session.add(dice_part_in_model) session.flush() # 提交扣款申请 dice_part_id = dice_part_in_model._id result = account_service.do_bet( session, user_id, coin_id, bet_number, 'dice_bet' + str(dice_part_in_model._id), 1, dice_serial, user_channel_id, change_type_31) if result != 0: session.rollback() raise_logger("do_bet result" + str(result), "game_bet_in", "info") session.commit() return { 'user_dice': user_dice, 'dice_timestamp': timestamp_to_str(dice_time, format_style="%Y-%m-%d %H:%M:%S"), 'dice_id': str(dice_part_id), 'dice_serial': dice_serial }
def delete_accounts(userid, accounts_id): try: if UserService.get_user(userid): AccountService.get_account_id(accounts_id) AccountService.delete_account(accounts_id) return '', 204 except ResourceNotFound as rf: rf.message return "Account does not exist", 404
def put_account(client_id, account_id): try: account = Account.json_parse(request.json) account.account_id = int(account_id) account.client_id = int(client_id) AccountService.update_account(account) return jsonify(account.json()), 200 except ValueError as e: return "Incorrect Value Type", 400 except ResourceNotFound as r: return r.message, 404
def post(self): request_data = self.get_argument_dict( must_keys=['user_id', 'user_mobile', 'mobile_country_code']) user_id = request_data['user_id'] user_mobile = request_data['user_mobile'] mobile_country_code = request_data['mobile_country_code'] account_service = AccountService() response_data = account_service.set_mobile(user_id, user_mobile, mobile_country_code) return response_data
def get_accounts(client_id): less_than = request.args.get('amountLessThan') greater_than = request.args.get('amountGreaterThan') accounts = [] if less_than is not None and greater_than is not None: accounts = AccountService.get_account_by_client_between( client_id, less_than, greater_than) else: accounts = AccountService.get_accounts_by_client(client_id) return (jsonify(accounts), 200) if accounts else ("Accounts Not Found", 404)
def post(self): request_data = self.get_argument_dict(must_keys=['user_id', 'coin_id']) user_id = request_data['user_id'] coin_id = str(request_data['coin_id']) page_num = request_data.get("offset", 1) page_limit = request_data.get("limit", 10) start_id = request_data.get("start_id", None) account_service = AccountService() result = account_service.get_account_token_water( user_id, coin_id, page_num, page_limit, start_id) return self.utctime_to_localtime(result)
def post(self): request_data = self.get_argument_dict(must_keys=['user_id']) user_id = request_data['user_id'] source = request_data.get("source", "") login_ip = request_data.get("login_ip", "") account_service = AccountService() result = account_service.user_login( user_id, source=source, login_ip=login_ip, ) return result
def edit_account_balance(client_id, account_id): action = request.json["action"] if action == 'withdraw': return AccountService.withdrawal_account(client_id, account_id, request.json["amount"]) elif action == 'deposit': return AccountService.deposit_account(client_id, account_id, request.json["amount"]) else: logger.log(f"{request.json}") return """Body must contain a JSON with an action property and values of withdrawal or deposit and an amount property with a valid number""", 400
def get_game_instance(self, user_id=''): with MysqlTools().session_scope() as session: account_service = AccountService() instance_info = session.query(InstantGameInstanceModel). \ order_by(InstantGameInstanceModel.created_at.desc()).first() if instance_info is None: self.return_error(40005) balance_btc = '' balance_eth = '' balance_usdt = '' balance_eos = '' balance_exp = '' if user_id != '': account_balance = account_service.get_user_token_list( user_id, None, 1, 10)['content'][0] balance_btc = account_balance['BTC'] balance_eth = account_balance['ETH'] if account_balance.get('EOS', None) is not None: balance_eos = account_balance['EOS'] else: balance_eos = 0 balance_usdt = account_balance['USDT'] balance_exp = account_balance['USDT_EXPERIENCE'] result = { 'instance': { 'id': instance_info._id, 'game_serial': instance_info.game_serial, 'game_title': instance_info.game_title, 'game_describe': instance_info.game_describe, 'need': instance_info.need, 'status': instance_info.status, 'bet_token': self.get_coin_name(instance_info.bet_token), 'max_bet_ratio': instance_info.max_bet_ratio }, 'current_price': { 'from': get_exchange_rate(int(_COIN_ID_BTC))['from'], 'eth': get_exchange_rate(int(_COIN_ID_ETH))['price'], 'btc': get_exchange_rate(int(_COIN_ID_BTC))['price'], 'eos': get_exchange_rate(int(_COIN_ID_EOS))['price'] }, 'balance': { 'btc': decimal_to_str(balance_btc, 8), 'eth': decimal_to_str(balance_eth, 8), 'eos': decimal_to_str(balance_eos, 8), 'usdt': decimal_to_str(balance_usdt, 4), 'exp': decimal_to_str(balance_exp, 4), } } return result
def transfer_funds(client_id, account_id, dest_id): if "amount" in request.json: amount = request.json["amount"] try: AccountService.transfer_funds(client_id, account_id, dest_id, amount) return f"Successfully transferred ${amount} from account {account_id} to {dest_id}", 200 except ValueError as e: return "Incorrect Value Type", 400 except ResourceNotFound as r: return r.message, 404 except InsufficientFunds as f: return f.message, 422 else: abort(400, "Body must contain a JSON with an 'amount' property")
def get_all_acct(userid): try: if UserService.get_user(userid): return jsonify(AccountService.all_account()), 200 except ResourceNotFound as r: r.message return "This client does not exist", 404