Ejemplo n.º 1
0
class locked_warehouse_CNYT(object):
    """CNYT锁仓活动用户数据及推荐奖励"""

    locked_money = 100.000  # 锁仓金额
    locked_phone = "17700000020"  # 锁仓用户

    # 一级推荐人
    referrer_first = connect_mysql().connect2mysql("SELECT inviter_id FROM member WHERE mobile_phone = '{}';".format(locked_phone))[0][0]
    print("用户{}的一级推荐人:{}".format(locked_phone, referrer_first))
    print("一级推荐人{}推荐返佣金额为:{}".format(referrer_first, locked_money * 0.03 * 0.15))

    # 二级推荐人
    referrer_second = connect_mysql().connect2mysql("SELECT inviter_id FROM member WHERE id = {};".format(referrer_first))[0][0]
    if referrer_second is None:
        print("用户{}无二级推荐人!!!".format(locked_phone))
    else:
        print("用户{}的二级推荐人为:{}".format(locked_phone, referrer_second))
        print("二级推荐人{}推荐返佣金额为:{}".format(referrer_second, locked_money * 0.03 * 0.09))

        # 三级推荐人
        referrer_third = connect_mysql().connect2mysql("SELECT inviter_id FROM member WHERE id = {};".format(referrer_second))[0][0]
        if referrer_third is None:
            print("用户{}无三级推荐人!!!".format(locked_phone))
        else:
            print("用户{}的三级推荐人为:{}".format(locked_phone, referrer_third))
            print("三级推荐人{}推荐返佣金额为:{}".format(referrer_third, locked_money * 0.03 * 0.06))
Ejemplo n.º 2
0
    def insert_member_and_memberwallet(self):
        """
        @description: 写入member表及memberwallet表用户数据
        :return: 
        """

        for index in range(1, 10001):

            try:
                # 注册手机号
                mobile_phone = str(int(self.registerd_test_phone) + index)
                # 注册推荐码
                promotion_code = "U" + str(
                    int(self.registerd_test_memberID) + index) + "AT"
                # 用户memberID
                member_id = int(self.registerd_test_memberID) + index

                sql_insert_member = """INSERT INTO member (appeal_success_times, appeal_times, certified_business_status, first_level, country, login_count, member_level, mobile_phone, 
                `password`, promotion_code, real_name_status, registration_time, salt, second_level, `status`, third_level, transactions, username, `local`, google_state, publish_advertise, 
                transaction_status, sign_in_ability, ip) 
                VALUES 
                (0, 0, 0, 0, '中国', 0, 0, {}, '{}', '{}', 0, '2018-10-24 15:57:00', {}, 
                0, 0, 0, 0, {}, '中国', 0, 1, 1, 1, '172.16.1.74');""".format(
                    mobile_phone, self.defualt_password, promotion_code,
                    self.defualt_salt, mobile_phone)
                connect_mysql().connect2mysql(sql_insert_member)
                logger.info("写入member表成功:{}".format(mobile_phone))
                print("写入member表成功:{}".format(mobile_phone))

                for coin_id in self.defualt_coin_id:
                    sql_insert_memberwallet = """INSERT INTO member_wallet (balance, frozen_balance, member_id, version, coin_id, is_lock, lock_balance, enabled_in, enabled_out) 
                    VALUES 
                    (0.00000000, 0.00000000, {}, 0, '{}', 0, 0.00000000, 1, 1);""".format(
                        member_id, coin_id)
                    connect_mysql().connect2mysql(sql_insert_memberwallet)
                    logger.info("写入member_wallet表成功:{}-{}".format(
                        member_id, coin_id))
                    print("写入member_wallet表成功:{}-{}".format(
                        member_id, coin_id))
            except Exception as e:
                logger.error("写入数据库错误:{}".format(e))
                print("写入数据库错误:{}".format(e))
                break
Ejemplo n.º 3
0
    def test_otc_order_cancel_buy(self):
        """买币取消订单"""

        # # 查询账户余额及冻结余额
        # try:
        #     check_mysql = connect_mysql().connect2mysql(self.inquire_member_wallet_CNYT_sql)
        #     parameter_name = ["coin_id", "balance", "frozen_balance", "lock_balance"]  # 查询字段名称拼装成字典形式内容
        #     before_member_wallet = DKApiBase().mysqlResultFormat(check_mysql, parameter_name)
        #     # print(before_member_wallet)
        #     before_Silubium_balance = before_member_wallet[0]["balance"]  # 变动前slb余额
        #     before_Silubium_frozen_balance = before_member_wallet[0]["frozen_balance"]  # 变动前slb冻结余额
        #     berore_USDT_balance = before_member_wallet[1]["balance"]  # 变动前USDT余额
        # except Exception as e:
        #     print("账户信息查询出错{}".format(e))

        # 查询可用c2c卖出USDT广告
        try:
            using_advertise = connect_mysql().connect2mysql(
                self.Inquire_advertise_sql_sale)
            # 处理查询结果
            parameter_name = [
                "id", "advertise_type", "max_limit", "min_limit",
                "remain_amount", "price", "coin_id", "member_id"
            ]
            advertise_data = DKApiBase().mysqlResultFormat(
                using_advertise, parameter_name)[0]
        except Exception as e:
            print("可用C2C广告信息查询出错{}".format(e))
            self.assertTrue(False, "查询可用广告失败")

        # 用户买入订单
        server = "otc/order/buy"
        data = {
            "id": advertise_data["id"],  # 广告id
            "coinId": advertise_data["coin_id"],  # 币种id,otc_coin表ID
            "price": advertise_data["price"],  # 当前价格
            "money": self.amount * advertise_data["price"],  # 金额
            "amount": self.amount,  # 数量
            "remark": "自动脚本测试买币",  # 要求、备注,非必传
            "mode": ""  # 计算方式,金额/价格=数量为0,数量*价格=金额为1,非必传,默认为0
        }
        r_cancel_buy = request2DKApi(server, data, self.header).send()
        print(r_cancel_buy)

        # 用户取消买入订单
        orderSn_cancel_buy = DKApiBase().str2json(
            r_cancel_buy[2])["data"]  # 下单结果获取交易订单号
        server = "otc/order/cancel"
        data = {"orderSn": orderSn_cancel_buy}
        r_cancel = request2DKApi(server, data, self.header).send()
        print(r_cancel)
        self.assertRegexpMatches(r_cancel[2], '"message" : "取消成功"', "结果断言失败")
Ejemplo n.º 4
0
    def setUpClass(cls):
        # @classmethod修饰setUpClass(cls):类方法,让setUpClass(cls):只需要执行一次,setUp(self)则会在每一个def test_*(self)开始前执行
        # 如setUpClass(cls):抛出异常则不会执行tearDownclass(cls):

        # 预定义的参数
        cls.symbol = "SLU"  # 币种名称
        cls.symbol_base = "USDT"  # 基币名称

        # 获取活动查询结果
        try:
            cls.activitie_id_sql = """SELECT id, `name`, activitie_id FROM lock_coin_activitie_setting WHERE coin_symbol = 'SLU' AND damages_calc_type = 1 ORDER BY id DESC;"""
            cls.activitie_result = DKApiBase().mysqlResultFormat(connect_mysql().connect2mysql(cls.activitie_id_sql), ["id", "name", "activitie_id"])
        except Exception as e:
            print("数据库查询错误:{}".format(e))

        # 查询用户全部锁仓记录
        try:
            cls.LockCoin_sql = """SELECT id, coin_unit, member_id, type, `status` FROM lock_coin_detail 
            WHERE coin_unit = 'SLU' AND member_id = (SELECT id FROM member WHERE token = '{}') ORDER BY id DESC;""".format(COMMON_TOKEN)
            cls.LockCoin_result = DKApiBase().mysqlResultFormat(connect_mysql().connect2mysql(cls.LockCoin_sql), ["id", "coin_unit", "member_id", "type", "status"])
        except Exception as e:
            print("数据库查询错误:{}".format(e))
Ejemplo n.º 5
0
 def uc_approve_transaction_password_batch(self):
     """
             4.6.1 批量设置资金密码
             :return: 
             """
     server = "uc/approve/transaction/password"
     data = {"jyPassword": "******"}
     sql_result = connect_mysql().connect2mysql(
         "SELECT token FROM member WHERE token LIKE '1111%';")
     result = DKApiBase().mysqlResultFormat(sql_result, ["token"])
     print(result)
     for token in result:
         print({"access-auth-token": token["token"]})
         r = request2DKApi(server, data, {
             "access-auth-token": token["token"]
         }).send()
         print(r)
     print("设置完毕")
Ejemplo n.º 6
0
    def setUp(self):

        # 获取订单明细接口订单号
        self.exchange_order_orderInfo_sql = '''SELECT order_id FROM exchange_order 
        WHERE member_id = '74773' AND completed_time IS NOT NULL ORDER BY completed_time DESC LIMIT 5;'''  # 查询最近成交的订单号
        try:
            # 获取查询到的第一条订单号
            self.exchange_order_orderInfo = DKApiBase().mysqlResultFormat(
                connect_mysql().connect2mysql(
                    self.exchange_order_orderInfo_sql),
                ["order_id"])[0]["order_id"]
        except Exception as e:
            print("获取订单明细查询订单号错误{}".format(e))

        self.announcementID = "8"  # 公告内容接口公告ID
        self.coinId = "5"  # 获取制定币种接口币种ID
        self.coinName = "SLB"  # 资产查询接口币种ID
        self.symbol = "SLB/USDT"  # 币种对
        self.fromdate = "2018-07-23 00:00:00"  # 查询K线数据起始时间
Ejemplo n.º 7
0
    def test_otc_order_cancel_sale(self):
        """卖币取消订单"""

        # 查询可用c2c买入USDT广告
        try:
            using_advertise = connect_mysql().connect2mysql(
                self.Inquire_advertise_sql_buy)
            # 处理查询结果
            parameter_name = [
                "id", "advertise_type", "max_limit", "min_limit",
                "remain_amount", "price", "coin_id", "member_id"
            ]
            advertise_data = DKApiBase().mysqlResultFormat(
                using_advertise, parameter_name)[0]
        except Exception as e:
            print("可用C2C广告信息查询出错{}".format(e))
            self.assertTrue(False, "查询可用广告失败")

        # 用户卖出订单
        server = "otc/order/sell"
        data = {
            "id": advertise_data["id"],  # 广告id
            "coinId": advertise_data["coin_id"],  # 币种id,otc_coin表ID
            "price": advertise_data["price"],  # 当前价格
            "money": advertise_data["price"] * self.amount,  # 金额
            "amount": self.amount,  # 数量
            "remark": "测试卖币",  # 要求、备注,非必传
            "mode": ""  # 计算方式,金额/价格=数量为0,数量*价格=金额为1,非必传,默认为0
        }
        r_cancel_sale = request2DKApi(server, data, self.header).send()
        print(r_cancel_sale)

        # 用户取消买入订单(发起买入USDT的商家)
        orderSn_cancel_sale = DKApiBase().str2json(
            r_cancel_sale[2])["data"]  # 下单结果获取交易订单号
        server = "otc/order/cancel"
        data = {"orderSn": orderSn_cancel_sale}
        r_cancel = request2DKApi(server, data).send()
        print(r_cancel)
        self.assertRegexpMatches(r_cancel[2], '"message" : "取消成功"', "结果断言失败")
Ejemplo n.º 8
0
class batch_register(object):
    """
    @description: 测试环境批量注册用户
    测试账号盐值、密码可传相同数值;推荐码为“U”+member表主键ID+两位随机字符或数字
    """
    # 开始写入前查询member表中已经注册过的测试手机号最大数值和memberID,注:默认批量添加过程中不被别人插入数据
    sql_select_registerd_test_phone = "SELECT mobile_phone FROM member WHERE mobile_phone LIKE '17700%' ORDER BY mobile_phone DESC LIMIT 1;"
    sql_select_registerd_test_memberID = "SELECT id FROM member ORDER BY id DESC LIMIT 1;"
    registerd_test_phone = connect_mysql().connect2mysql(
        sql_select_registerd_test_phone)[0][0]  # 手机号
    registerd_test_memberID = connect_mysql().connect2mysql(
        sql_select_registerd_test_memberID)[0][0]  # memberID
    print("起始手机号:{}--起始memberID:{}".format(registerd_test_phone,
                                           registerd_test_memberID))
    defualt_password = "******"  # 默认密码cs111111
    defualt_salt = "3836313237363938373730303036303136"  # 默认盐值
    defualt_coin_id = [
        "BCH", "Bitcoin", "BTMC", "CALL", "CNYT", "DARING5920", "Dogecoin",
        "EOS", "ETC", "Ethereum", "Litecoin", "mmb", "NB", "Silubium", "SLU",
        "SOG"
    ]

    # 写入member表用户数据
    def insert_member_and_memberwallet(self):
        """
        @description: 写入member表及memberwallet表用户数据
        :return: 
        """

        for index in range(1, 10001):

            try:
                # 注册手机号
                mobile_phone = str(int(self.registerd_test_phone) + index)
                # 注册推荐码
                promotion_code = "U" + str(
                    int(self.registerd_test_memberID) + index) + "AT"
                # 用户memberID
                member_id = int(self.registerd_test_memberID) + index

                sql_insert_member = """INSERT INTO member (appeal_success_times, appeal_times, certified_business_status, first_level, country, login_count, member_level, mobile_phone, 
                `password`, promotion_code, real_name_status, registration_time, salt, second_level, `status`, third_level, transactions, username, `local`, google_state, publish_advertise, 
                transaction_status, sign_in_ability, ip) 
                VALUES 
                (0, 0, 0, 0, '中国', 0, 0, {}, '{}', '{}', 0, '2018-10-24 15:57:00', {}, 
                0, 0, 0, 0, {}, '中国', 0, 1, 1, 1, '172.16.1.74');""".format(
                    mobile_phone, self.defualt_password, promotion_code,
                    self.defualt_salt, mobile_phone)
                connect_mysql().connect2mysql(sql_insert_member)
                logger.info("写入member表成功:{}".format(mobile_phone))
                print("写入member表成功:{}".format(mobile_phone))

                for coin_id in self.defualt_coin_id:
                    sql_insert_memberwallet = """INSERT INTO member_wallet (balance, frozen_balance, member_id, version, coin_id, is_lock, lock_balance, enabled_in, enabled_out) 
                    VALUES 
                    (0.00000000, 0.00000000, {}, 0, '{}', 0, 0.00000000, 1, 1);""".format(
                        member_id, coin_id)
                    connect_mysql().connect2mysql(sql_insert_memberwallet)
                    logger.info("写入member_wallet表成功:{}-{}".format(
                        member_id, coin_id))
                    print("写入member_wallet表成功:{}-{}".format(
                        member_id, coin_id))
            except Exception as e:
                logger.error("写入数据库错误:{}".format(e))
                print("写入数据库错误:{}".format(e))
                break
Ejemplo n.º 9
0
class crazy_BTMCGame_up(object):
    """
    @descreption: 疯狂的比特游戏新规则数据核对
    展示数据:总奖池累计;中奖用户数;本期中奖奖池;BTMC中奖价格;本期红包奖励总数;本期推荐分红总数;本期回购总数;
    本期沉淀总数;本期用户投币总数;本期中奖系数;本期已分佣BTMC数量;本期已领取奖励BTMC数量;本期已领取红包BTMC数量;
    本期单个用户中奖BTMC计算;本期分配后累计到下期BTMC数量;本期红包领取后剩余数量;本期共进BTMC及本期共出BTMC数量
    """

    # 游戏期数
    configid = 63
    # 用户单注投注金额
    user_bet_money = 10

    # 数据库基础数据查询
    print("************由数据库查询获得的基础数据************")
    # 上期奖池总结余=上期分配结余+上期红包结余
    try:
        before_money = float(connect_mysql().connect2mysql(
            "SELECT (jackpot_balance + redpacket_balance) FROM pg_jackpot WHERE id = (SELECT id - 1 FROM pg_jackpot ORDER BY id DESC LIMIT 1);"
        )[0][0])
    except Exception as e:
        # print(e)
        before_money = 0
        # before_money = 35380.44968840 + 2527.17497775
    print("上期奖池余额:{}".format(before_money))

    # 本期用户总投币数
    all_bet_num = float(connect_mysql().connect2mysql(
        "SELECT SUM(bet_num) FROM pg_betting_record WHERE period_id = {};".
        format(configid))[0][0])
    print("本期用户总投币数:{}".format(all_bet_num))

    # 本期总奖池累计=上期奖池总结余+本期用户总投币数
    all_money = all_bet_num + before_money
    print("本期奖池总金额:{}".format(all_money))

    # 本期已分配的分佣金额
    try:
        push_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(amount) FROM pg_branch_record WHERE period_id = {} AND business_type = 1;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        push_money = 0
    print("本期已分配的分佣金额:{}".format(push_money))

    # 本期中奖BTMC总数
    try:
        happy_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(bet_num) FROM pg_betting_record WHERE period_id = {} AND `status` = 2;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        happy_money = 0
    print("本期中奖BTMC总数:{}".format(happy_money))

    # 本期中奖用户数
    try:
        this_winning_user = float(connect_mysql().connect2mysql(
            "SELECT COUNT(*) FROM pg_betting_record WHERE period_id = {} AND `status` = 2;"
            .format(configid))[0][0])
    except Exception as e:
        this_winning_user = 0
    print("本期中奖用户数:{}".format(this_winning_user))

    # 本期参与总人数
    try:
        this_user_num = float(connect_mysql().connect2mysql(
            "SELECT count(distinct member_id) FROM pg_betting_record WHERE period_id = {};"
            .format(configid))[0][0])
        print("本期参与总人数:{}".format(this_user_num))
    except Exception as e:
        print("本期参与总人数查询结果错误:{}".format(e))

    # 本期投票总次数
    try:
        this_vote_num = float(connect_mysql().connect2mysql(
            "SELECT COUNT(*) FROM pg_betting_record WHERE period_id = {};".
            format(configid))[0][0])
        print("本期投票总次数:{}".format(this_vote_num))
    except Exception as e:
        print("本期投票总次数查询结果错误:{}".format(e))

    # 本期参与新用户数
    try:
        this_new_user_num = connect_mysql().connect2mysql(
            """SELECT COUNT(*) FROM member m RIGHT JOIN 
        (SELECT distinct pr.member_id memberID, pc.begin_time bgt, pc.end_time edt FROM pg_betting_config pc LEFT JOIN pg_betting_record pr ON pc.id = pr.period_id WHERE pr.period_id = {}) b 
        ON m.id = b.memberID WHERE m.registration_time >= b.bgt AND m.registration_time <= b.edt;"""
            .format(configid))[0][0]
        print("本期参与新用户数:{}".format(this_new_user_num))
    except Exception as e:
        print("本期参与新用户数查询结果错误:{}".format(e))

    # 本期新用户投票总次数
    try:
        this_new_user_vote_num = connect_mysql().connect2mysql(
            """SELECT COUNT(*) FROM pg_betting_record WHERE member_id IN (SELECT id FROM member m RIGHT JOIN 
        (SELECT distinct pr.member_id memberID, pc.begin_time bgt, pc.end_time edt FROM pg_betting_config pc LEFT JOIN pg_betting_record pr ON pc.id = pr.period_id WHERE pr.period_id = {}) b 
        ON m.id = b.memberID WHERE m.registration_time >= b.bgt AND m.registration_time <= b.edt) AND period_id = {};"""
            .format(configid, configid))[0][0]
        print("本期新用户投票总次数:{}".format(this_new_user_vote_num))
    except Exception as e:
        print("本期新用户投票总次数查询结果错误:{}".format(e))

    # 本期新用户投票总额
    try:
        this_new_user_vote_amount = connect_mysql().connect2mysql(
            """SELECT SUM(bet_num) FROM pg_betting_record WHERE member_id IN (SELECT id FROM member m RIGHT JOIN 
        (SELECT distinct pr.member_id memberID, pc.begin_time bgt, pc.end_time edt FROM pg_betting_config pc LEFT JOIN pg_betting_record pr ON pc.id = pr.period_id WHERE pr.period_id = {}) b 
        ON m.id = b.memberID WHERE m.registration_time >= b.bgt AND m.registration_time <= b.edt) AND period_id = {};"""
            .format(configid, configid))[0][0]
        if this_new_user_vote_amount is None:
            print("本期新用户投票总额:{}".format(0))
        else:
            print("本期新用户投票总额:{}".format(float(this_new_user_vote_amount)))
    except Exception as e:
        print("本期新用户投票总额查询结果错误:{}".format(e))

    # 本期新用户中奖人数
    try:
        this_new_user_winner = connect_mysql().connect2mysql(
            """SELECT COUNT(*) FROM pg_betting_record WHERE member_id IN (SELECT id FROM member m RIGHT JOIN 
        (SELECT distinct pr.member_id memberID, pc.begin_time bgt, pc.end_time edt FROM pg_betting_config pc LEFT JOIN pg_betting_record pr ON pc.id = pr.period_id WHERE pr.period_id = {} AND pr.`status` = 2) b 
        ON m.id = b.memberID WHERE m.registration_time >= b.bgt AND m.registration_time <= b.edt) AND period_id = {};"""
            .format(configid, configid))[0][0]
        print("本期新用户中奖人数:{}".format(this_new_user_winner))
    except Exception as e:
        print("本期新用户中奖人数查询结果错误:{}".format(e))

    # 本期新用户中奖金额
    try:
        this_new_user_winning_num = connect_mysql().connect2mysql(
            """SELECT SUM(bet_num) FROM pg_betting_record WHERE member_id IN (SELECT id FROM member m RIGHT JOIN 
        (SELECT distinct pr.member_id memberID, pc.begin_time bgt, pc.end_time edt FROM pg_betting_config pc LEFT JOIN pg_betting_record pr ON pc.id = pr.period_id WHERE pr.period_id = {} AND pr.`status` = 2) b 
        ON m.id = b.memberID WHERE m.registration_time >= b.bgt AND m.registration_time <= b.edt) AND period_id = {};"""
            .format(configid, configid))[0][0]
        if this_new_user_winning_num is None:
            print("本期新用户中奖金额:{}".format(0))
        else:
            print("本期新用户中奖金额:{}".format(float(this_new_user_winning_num)))
    except Exception as e:
        print("本期新用户中奖金额查询结果错误:{}".format(e))

    # 本期老用户中奖人数
    try:
        this_old_user_winner = connect_mysql().connect2mysql(
            """SELECT COUNT(*) FROM pg_betting_record WHERE member_id IN (SELECT id FROM member m RIGHT JOIN 
        (SELECT distinct pr.member_id memberID, pc.begin_time bgt, pc.end_time edt FROM pg_betting_config pc LEFT JOIN pg_betting_record pr ON pc.id = pr.period_id WHERE pr.period_id = {} AND pr.`status` = 2) b 
        ON m.id = b.memberID WHERE m.registration_time <= b.bgt or m.registration_time >= b.edt) AND period_id = {};"""
            .format(configid, configid))[0][0]
        print("本期老用户中奖人数:{}".format(this_old_user_winner))
    except Exception as e:
        print("本期老用户中奖人数查询结果错误:{}".format(e))

    # 本期老用户中奖金额=中奖金额-新用户中奖金额
    if this_new_user_winning_num is None:
        this_old_user_winning_num = all_money * 0.65 - 0
    else:
        this_old_user_winning_num = all_money * 0.65 - float(
            this_new_user_winning_num)
    print("本期老用户中奖金额:{}".format(this_old_user_winning_num))

    # 本期已领取中奖奖励
    try:
        received_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(reward_num) FROM pg_reward WHERE period_id = {} AND business_type = 0 AND `status` = 1;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        received_money = 0
    print("本期已领取的中奖奖励:{}".format(received_money))

    # 本期已领取红包金额
    try:
        received_redpacket_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(reward_num) FROM pg_reward WHERE period_id = {} AND business_type = 1 AND `status` = 4;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        received_redpacket_money = 0
    print("本期已领取红包金额:{}".format(received_redpacket_money))

    # 计算数据
    print("************计算获得数据************")
    # 本期中奖奖池=总奖池*0.65
    this_winning_pool = all_money * 0.65
    print("本期中奖奖池:{}".format(this_winning_pool))

    # 本期红包奖励总数=总奖池*0.05
    this_red_envelope = all_money * 0.05
    print("本期红包奖励:{}".format(this_red_envelope))

    # 本期推荐分红总数=总奖池*0.1
    this_recommended_dividends = all_money * 0.1
    print("本期推荐分红:{}".format(this_recommended_dividends))

    # 本期回购总数=总奖池*0.15
    this_repurchase = all_money * 0.15
    print("本期SLU回购:{}".format(this_repurchase))

    # 本期沉淀总数=总奖池*0.05
    this_precipitation = all_money * 0.05
    print("本期奖池沉淀:{}".format(this_precipitation))

    # 本期中奖系数=中奖奖池/本期中奖BTMC总数
    if happy_money != 0:
        this_winning_factor = this_winning_pool / happy_money
    else:
        this_winning_factor = 0
    print("本期中奖系数:{}".format(this_winning_factor))

    # 本期单个用户中奖数额计算=本期中奖系数*投注金额
    this_user_wins_num = this_winning_factor * user_bet_money
    print("本期单个用户中奖数额计算:{}".format(this_user_wins_num))

    # 下期奖池沉淀总数=5%总奖池固定沉淀+中奖用户未领取部分+红包未领取部分
    next_pool_precipitation = this_precipitation + (
        this_winning_pool - received_money) + (this_red_envelope -
                                               received_redpacket_money)
    print("下期奖池沉淀总数:{}".format(next_pool_precipitation))

    # 本期奖池剩余=5%总奖池固定沉淀+中奖用户未领取部分
    next_pool_money = this_precipitation + (this_winning_pool - received_money)
    print("本期奖池剩余:{}".format(next_pool_money))

    # 本期红包剩余
    next_redpacket_money = this_red_envelope - received_redpacket_money
    print("本期红包剩余:{}".format(next_redpacket_money))

    # 本期回购总金额=15%总奖池固定回购+无推荐用户的分佣部分
    this_total_repurchase = this_repurchase + (this_recommended_dividends -
                                               push_money)
    print("本期回购总金额:{}".format(this_total_repurchase))

    # 本期支出总金额=下期奖池沉淀+本期回购总金额+本期已分配的分佣金额+本期已领取中奖奖励+本期已领取红包金额
    this_total_expenditure = next_pool_precipitation + this_total_repurchase + push_money + received_money + received_redpacket_money
    if this_total_expenditure == all_money:
        print("本期支出金额总数:{} = 本期收入总金额:{}".format(this_total_expenditure,
                                                all_money))
    else:
        print("本期支出金额总数:{} != 本期收入总金额:{}".format(this_total_expenditure,
                                                 all_money))
Ejemplo n.º 10
0
class crazy_BTCGame(object):
    """
    :descreption: 疯狂的比特游戏奖池分配测试数据核对
    """

    # 游戏期数
    configid = 16
    # 用户单注投注金额
    user_bet_money = 100
    # 是否开启红包:1-是,0-否
    isredpackge = 1

    # 当期用户总投币数
    all_bet_num = float(connect_mysql().connect2mysql(
        "SELECT SUM(bet_num) FROM pg_betting_record WHERE period_id = {};".
        format(configid))[0][0])
    print("当期用户总投币数: {}".format(all_bet_num))

    # 上期奖池余额
    try:
        before_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(jackpot_balance + redpacket_balance) FROM pg_jackpot WHERE period_id = {};"
            .format(configid - 1))[0][0])
    except Exception as e:
        # print(e)
        before_money = 0
    print("上期奖池余额: {}".format(before_money))

    # 当期奖池总金额
    all_money = all_bet_num + before_money
    print("当期奖池总金额: {}".format(all_money))

    # 当期分佣金额
    try:
        push_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(amount) FROM pg_branch_record WHERE period_id = {} AND business_type = 1;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        push_money = 0
    print("当期分佣金额: {}".format(push_money))

    # 当期回购金额
    repurchase_money = all_money * 0.15
    print("当期回购金额:{}".format(repurchase_money))

    # 当期中奖金额
    try:
        happy_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(bet_num) FROM pg_betting_record WHERE period_id = {} AND `status` = 2;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        happy_money = 0
    print("当期中奖金额: {}".format(happy_money))

    # 当期已领取的奖励
    try:
        received_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(reward_num) FROM pg_reward WHERE period_id = {} AND business_type = 0 AND `status` = 1;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        received_money = 0
    print("当期已领取的奖励: {}".format(received_money))

    # 本期分配红包总金额
    if isredpackge == 1:
        this_redpacket_money = all_money * 0.05
    elif isredpackge == 0:
        this_redpacket_money = 0
    print("本期分配红包总金额: {}".format(this_redpacket_money))

    # 当期已领取红包金额
    try:
        received_redpacket_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(reward_num) FROM pg_reward WHERE period_id = {} AND business_type = 1 AND `status` = 4;"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        received_redpacket_money = 0
    print("当期已领取红包金额: {}".format(received_redpacket_money))

    # 本期累计到下期奖池总金额
    try:
        this_follow_money = float(connect_mysql().connect2mysql(
            "SELECT SUM(jackpot_balance + redpacket_balance) FROM pg_jackpot WHERE period_id = {};"
            .format(configid))[0][0])
    except Exception as e:
        # print(e)
        this_follow_money = 0
    print("本期累计到下期奖池总金额: {}".format(this_follow_money))

    # 奖金计算
    # 当期中奖分配奖池金额
    if isredpackge == 1:
        this_money = all_money - all_money * 0.25 - push_money
    elif isredpackge == 0:
        this_money = all_money - all_money * 0.2 - push_money
    print("当期中奖分配奖池金额: {}".format(this_money))

    # 用户奖励计算
    if received_money == 0:
        print("当期中奖金额为0,不产生奖励")
        user_get_money = 0
    else:
        if isredpackge == 1:
            user_get_money = (all_money - all_money * 0.25 -
                              push_money) / happy_money * user_bet_money
        elif isredpackge == 0:
            user_get_money = (all_money - all_money * 0.2 -
                              push_money) / happy_money * user_bet_money
    print("******")
    # print("(当期奖池总金额{} - 25%当期用户总投币数{} - 当期分佣金额{}) / 当期中奖金额{} * 用户单注投注金额{} = {}".format(all_money, all_money * 0.25, push_money, happy_money, user_bet_money, user_get_money))
    print("用户获取奖励:{}".format(user_get_money))

    # 下期奖池沉淀计算  下期结余=奖池金额+本期沉淀-已经领取的奖励
    if isredpackge == 1:
        follow_money = this_money + all_money * 0.05 - received_money
    elif isredpackge == 0:
        follow_money = this_money + all_money * 0.05 - received_money
    # print("当期奖池金额{} + 5%下期沉淀{} - 当期已领取的奖励{} = {}".format(this_money, all_bet_num * 0.05, received_money, follow_money))
    print("下期奖池沉淀计算: {}".format(follow_money))

    # 累计到下期的红包金额
    follow_redpacket_money = this_redpacket_money - received_redpacket_money
    print("累计到下期的红包金额: {}".format(follow_redpacket_money))

    # 总金额核对  本期投票金额+上期总结余金额 = 本期已领取分佣金额 + 本期已红包领取金额 + 本期回购金额 + 本期已领取奖励金额 + 累计到下期奖池(奖励+红包)
    result = push_money + received_redpacket_money + repurchase_money + received_money + this_follow_money
    if result == all_money:
        print("本期共进金额:{}=本期共出金额:{}".format(all_money, result))
    else:
        print("本期共进金额:{}!=本期共出金额:{}".format(all_money, result))
    print("注:由于部分扣除计算比例的时候按总奖池累计后计算,部分按当期投注总金额计算,因此总进账与总出账之间数据不相等。")
Ejemplo n.º 11
0
    def test_otc_advertise_generaluser_sells(self):
        """普通用户卖出广告并核对用户账户数据:1.创建广告,2.上架广告,3.交易广告,4.商家放币,5.交易广告,6.用户申述,7.用户胜出,
        8.用户申述,9.广告方胜出,10.广告方申述,11.用户胜出,12.广告方申述,13.广告方胜出,14.下架广告,15.删除广告"""

        # 查询申述风险配置,如设置允许申述次数小于4次,会导致测试账号被锁,则需先修改后台风控配置再执行
        safe_mark = 0
        user_risk_config = connect_mysql().connect2mysql(
            """SELECT trigger_times FROM monitor_rule_config WHERE trigger_event = 11;"""
        )
        for user_config in user_risk_config:
            for user_risk in user_config:
                if user_risk <= 10:
                    safe_mark = 1
        if safe_mark == 1:
            # 执行数据库更新操作,安全设置
            connect_mysql().connect2mysql(
                """UPDATE monitor_rule_config SET trigger_times = 30 WHERE trigger_event = 11;"""
            )
        else:
            print("申述失败次数设置大于10次,无需修改设置")

        # 查询普通用户广告手续费配置,如未配置上架优惠则不计算上币优惠
        coin_config = DKApiBase().mysqlResultFormat(
            connect_mysql().connect2mysql(
                """SELECT general_buy_min_balance, general_discount_coin_scale, 
        general_discount_coin_unit, general_discount_rate, general_fee, general_fee_coin_unit FROM otc_coin WHERE `name` = '{}';"""
                .format(self.advertcoin_CNYT)), [
                    "general_buy_min_balance", "general_discount_coin_scale",
                    "general_discount_coin_unit", "general_discount_rate",
                    "general_fee", "general_fee_coin_unit"
                ])
        # 判断设置广告上架费用是否为广告币种,否则将广告上架币种设置为广告币种
        if coin_config["general_fee_coin_unit"] == self.advertcoin_CNYT:
            logger.info("广告上架费用基础币种为:{},与广告币种{}相同".format(
                coin_config["general_fee_coin_unit"], self.advertcoin_CNYT))
        else:
            connect_mysql().connect2mysql(
                """UPDATE otc_coin SET general_fee_coin_unit = '{}' WHERE `name` = '{}';"""
                .format(self.advertcoin_CNYT, self.advertcoin_CNYT))
            logger.error("原广告上架费用基础币种为:{},修改为广告币种{}".format(
                coin_config["general_fee_coin_unit"], self.advertcoin_CNYT))
            print("原广告上架费用基础币种为:{},修改为广告币种{}".format(
                coin_config["general_fee_coin_unit"], self.advertcoin_CNYT))
        # 判断广告费优惠币种为SLU,否则修改为SLU
        if coin_config["general_discount_coin_unit"] == "SLU":
            logger.info("广告优惠币种:{}".format(
                coin_config["general_discount_coin_unit"]))
        else:
            connect_mysql().connect2mysql(
                """UPDATE otc_coin SET general_discount_coin_unit = 'SLU' WHERE `name` = '{}';"""
                .format(self.advertcoin_CNYT))
            logger.error("原上架手续费优惠币种为{},修改为:SLU".format(
                coin_config["general_discount_coin_unit"]))
            print("原上架手续费优惠币种为{},修改为:SLU".format(
                coin_config["general_discount_coin_unit"]))
        # 判断广告上架SLU优惠比例设为0则为不开启优惠,如未0则开启设置为0.8
        if coin_config["general_discount_rate"] == 0:
            connect_mysql().connect2mysql(
                """UPDATE otc_coin SET general_discount_rate = 0.8 WHERE `name` = '{}';"""
                .format(self.advertcoin_CNYT))
            logger.info("原上架手续费SLU优惠比例为:{},默认设置为:0.8".format(
                coin_config["general_discount_rate"]))
        # 判断商家手续费金额,如为0则默认设置为10
        if coin_config["general_fee"] == 0:
            connect_mysql().connect2mysql(
                """UPDATE otc_coin SET general_fee = 10 WHERE `name` = '{}';"""
                .format(self.advertcoin_CNYT))
            logger.info("原上架手续费金额为:{},默认设置为:10".format(
                coin_config["general_fee"]))
        # 完成设置后重新查询广告上架费用配置
        coin_config = DKApiBase().mysqlResultFormat(
            connect_mysql().connect2mysql(
                """SELECT general_buy_min_balance, general_discount_coin_scale, 
        general_discount_coin_unit, general_discount_rate, general_fee, general_fee_coin_unit FROM otc_coin WHERE `name` = '{}';"""
                .format(self.advertcoin_CNYT)), [
                    "general_buy_min_balance", "general_discount_coin_scale",
                    "general_discount_coin_unit", "general_discount_rate",
                    "general_fee", "general_fee_coin_unit"
                ])

        # 查询普通用户发布广告前账户数据
        wallet_sale_CNYT = DKApiBase().mysqlResultFormat(
            connect_mysql().connect2mysql(
                """SELECT balance, frozen_balance, lock_balance FROM member_wallet WHERE member_id = 
        (SELECT id FROM member WHERE token = '{}') AND coin_id = '{}';""".
                format(COMMON_TOKEN_GENERAL_USER, self.advertcoin_CNYT)),
            ["balance", "frozen_balance", "lock_balance"])
        wallet_sale_SLU = DKApiBase().mysqlResultFormat(
            connect_mysql().connect2mysql(
                """SELECT balance, frozen_balance, lock_balance FROM member_wallet WHERE member_id = 
        (SELECT id FROM member WHERE token = '{}') AND coin_id = '{}';""".
                format(COMMON_TOKEN_GENERAL_USER, self.walletcion_SLU)),
            ["balance", "frozen_balance", "lock_balance"])

        # 创建卖出广告,选择使用SLU优惠
        server = "otc/advertise/create"
        data = {
            "price": self.advertPrice_CNYT,
            "advertiseType": "1",  # 0买,1卖
            "coin.id": self.otc_coin_id_CNYT,
            "minLimit": "100",
            "maxLimit": "1000",
            "timeLimit": "30",
            "country": "中国",
            "priceType": "0",
            "premiseRate": "",
            "remark": "非认证商家卖出广告,自动化脚本添加",
            "number": self.otc_number,
            "pay[]": "银联",
            "auto": "1",  # 是否开启自动回复0否1是,默认否
            "autoword": "先付款,后放币",
            "needBindPhone": "0",  # 是否需要交易方已绑定手机号,0:不需要,1:需要
            "needRealname": "0",  # 是否需要交易方已做实名认证,0:不需要,1:需要
            "needTradeTimes": "0",  # 需要交易方至少完成过N笔交易(默认为0)
            "needPutonDiscount": "1",  # 是否使用优惠币种支付,0:不使用,1:使用
            "bindingResult": "",  # 绑定结果,非必传项
            "jyPassword": self.jyPassword
        }
        r_sale = request2DKApi(server, data, self.header_general).send()
        print(r_sale)

        # 查询个人所有广告获得最新创建广告
        server = "otc/advertise/all"
        r_Inquire_sale = request2DKApi(server, self.header_general).send()
        print(r_Inquire_sale)
        advertid_sale = DKApiBase().str2json(
            r_Inquire_sale[2])["data"][0]["id"]  # 从查询接口获取最新发布的这条广告ID

        # 上架广告
        server = "otc/advertise/on/shelves"
        data = {"id": advertid_sale}
        r_on_sale = request2DKApi(server, data, self.header_general).send()
        print(r_on_sale)

        # 查询广告方发布广告后账户数据
        wallet_sale_addadv_CNYT = DKApiBase().mysqlResultFormat(
            connect_mysql().connect2mysql(
                """SELECT balance, frozen_balance, lock_balance FROM member_wallet WHERE member_id = 
        (SELECT id FROM member WHERE token = '{}') AND coin_id = '{}';""".
                format(COMMON_TOKEN_GENERAL_USER, self.advertcoin_CNYT)),
            ["balance", "frozen_balance", "lock_balance"])
        wallet_sale_addadv_SLU = DKApiBase().mysqlResultFormat(
            connect_mysql().connect2mysql(
                """SELECT balance, frozen_balance, lock_balance FROM member_wallet WHERE member_id = 
        (SELECT id FROM member WHERE token = '{}') AND coin_id = '{}';""".
                format(COMMON_TOKEN_GENERAL_USER, self.walletcion_SLU)),
            ["balance", "frozen_balance", "lock_balance"])

        sale_change_balance_CNYT = wallet_sale_CNYT[
            "balance"] - wallet_sale_addadv_CNYT["balance"]
        sale_change_frozen_balance_CNYT = wallet_sale_CNYT[
            "frozen_balance"] - wallet_sale_addadv_CNYT["frozen_balance"]
        sale_change_balance_SLU = wallet_sale_SLU[
            "balance"] - wallet_sale_addadv_SLU["balance"]
        logger.info("广告用户{}可用余额变化金额:{};广告用户{}冻结变化金额{};广告用户{}可用余额变化金额{}".format(
            self.advertcoin_CNYT, sale_change_balance_CNYT,
            self.advertcoin_CNYT, sale_change_frozen_balance_CNYT,
            self.walletcion_SLU, sale_change_balance_SLU))

        # 上架手续费计算
        try:
            # 获取CNYT对USDT价格
            price_CNYT_USDT = float(DKApiBase().str2json(
                request2DKApi("market/exchange-rate/usd/cnyt").send()[2])
                                    ["data"])
            logger.info("获取CNYT对USDT价格:{}".format(price_CNYT_USDT))
            # 获取SLU对USDT价格
            price_SLU_USDT = float(DKApiBase().str2json(
                request2DKApi("market/exchange-rate/usd/slu").send()[2])
                                   ["data"])
            logger.info("获取SLU对USDT价格:{}".format(price_SLU_USDT))
        except Exception as e:
            logger.error("获取CNYT/SLU对USDT价格失败:", e)

        # 手续费全部换算成SLU金额
        fee_2_SLU = float(coin_config["general_fee"]
                          ) * price_CNYT_USDT / price_SLU_USDT * 0.8
        if wallet_sale_SLU["balance"] == 0:
            if sale_change_balance_CNYT == self.otc_number + coin_config[
                    "general_fee"] and sale_change_frozen_balance_CNYT == self.otc_number:
                logger.info("用户SLU账户为:{},全额扣除{}账户金额{}".format(
                    wallet_sale_SLU["balance"], self.advertcoin_CNYT,
                    coin_config["general_fee"]))
                print("用户SLU账户为:{},全额扣除{}账户金额{}".format(
                    wallet_sale_SLU["balance"], self.advertcoin_CNYT,
                    coin_config["general_fee"]))
            else:
                logger.error("SLU账户为0时广告上架手续费扣除数据异常")
                print("SLU账户为0时广告上架手续费扣除数据异常")
        elif wallet_sale_SLU["balance"] >= fee_2_SLU:
            logger.info("广告上架全额扣除SLU优惠手续费:{}".format(fee_2_SLU))
            print("广告上架全额扣除SLU优惠手续费:{}".format(fee_2_SLU))
            if sale_change_balance_SLU == fee_2_SLU:
                logger.info("广告上架费用由SLU全额扣除正确:{}".format(fee_2_SLU))
                print("广告上架费用由SLU全额扣除正确:{}".format(fee_2_SLU))
            else:
                logger.error("SLU账户金额大于应付广告手续费时扣除数据异常")
                print("SLU账户金额大于应付广告手续费时扣除数据异常")
        else:
            logger.info("广告上架实际扣除SLU优惠部分手续费:{}".format(
                wallet_sale_SLU["balance"]))
            print("广告上架实际扣除SLU优惠部分手续费:{}".format(wallet_sale_SLU["balance"]))
            # 部分扣除时CNYT应扣除广告费部分
            fee_CNYT = (fee_2_SLU - wallet_sale_SLU["balance"]
                        ) / 0.8 * price_SLU_USDT / price_CNYT_USDT
            if sale_change_balance_CNYT == self.otc_number + fee_CNYT and sale_change_frozen_balance_CNYT == self.otc_number:
                logger.info("部分使用SLU支付时,扣除原费用币种{}金额{}正确".format(
                    self.advertcoin_CNYT, fee_CNYT))
                print("部分使用SLU支付时,扣除原费用币种{}金额{}正确".format(
                    self.advertcoin_CNYT, fee_CNYT))
            else:
                logger.error("部分使用SLU支付时扣除广告费用金额异常")
                print("部分使用SLU支付时扣除广告费用金额异常")
Ejemplo n.º 12
0
    def test_otc_advertise_merchant_buy(self):
        """认证商家买入广告并核对用户账户数据变更:1.创建买入广告2.查询该条广告3.上架4.买币交易5.确认付款6.放币7.下架广告8.删除广告"""

        # 查询商家认证状态:0为普通用户;1为实名认证用户;2为认证商家
        logger.info("------执行test_otc_advertise_merchant_buy------")
        try:
            user_member_lever = connect_mysql().connect2mysql(
                self.member_level_sql)[0][0]
        except Exception as e:
            print(e)
            logger.error(e)
            user_member_lever = 0

        if user_member_lever == 2:

            # 查询商家用户钱包账户数据
            inquire_Merchant_member_wallet = connect_mysql().connect2mysql(
                self.inquire_Merchant_wallet_CNYT_sql)
            inquire_Merchant_member_wallet_list = DKApiBase(
            ).mysqlResultFormat(
                inquire_Merchant_member_wallet,
                ["coin_id", "balance", "frozen_balance", "lock_balance"])

            # 创建买入广告
            server = "otc/advertise/create"
            data = {
                "price": self.advertPrice_CNYT,
                "advertiseType": "0",  # 0买,1卖
                "coin.id": self.otc_coin_id_CNYT,
                "minLimit": "100",
                "maxLimit": "1000",
                "timeLimit": "30",
                "country": "中国",
                "priceType": "0",
                "premiseRate": "",
                "remark": "认证商家买入广告,自动化脚本添加",
                "number": self.otc_number,
                "pay[]": "银联",
                "auto": "1",  # 是否开启自动回复0否1是,默认否
                "autoword": "先付款,后放币",
                "needBindPhone": "1",  # 是否需要交易方已绑定手机号,0:不需要,1:需要
                "needRealname": "1",  # 是否需要交易方已做实名认证,0:不需要,1:需要
                "needTradeTimes": "10",  # 需要交易方至少完成过N笔交易(默认为0)
                "needPutonDiscount": "1",  # 是否使用优惠币种支付,0:不使用,1:使用
                "bindingResult": "",  # 绑定结果,非必传项
                "jyPassword": self.jyPassword
            }
            r_sale = request2DKApi(server, data).send()
            print(r_sale)

            # 查询商家账户数据,提交广告时不扣除账户币种数据
            inquire_Merchant_member_wallet = connect_mysql().connect2mysql(
                self.inquire_Merchant_wallet_CNYT_sql)
            inquire_Merchant_member_wallet_list_add = DKApiBase(
            ).mysqlResultFormat(
                inquire_Merchant_member_wallet,
                ["coin_id", "balance", "frozen_balance", "lock_balance"])

            # 判断添加广告后商家账户余额是否发生变动,如变动证明数据有问题则不执行后续操作
            if inquire_Merchant_member_wallet_list["balance"] == inquire_Merchant_member_wallet_list_add["balance"] \
                    and inquire_Merchant_member_wallet_list["frozen_balance"] == inquire_Merchant_member_wallet_list_add["frozen_balance"]:
                # 查询个人所有广告获得最新创建广告
                server = "otc/advertise/all"
                r_Inquire_sale = request2DKApi(server).send()
                print(r_Inquire_sale)
                advertid_sale = DKApiBase().str2json(
                    r_Inquire_sale[2])["data"][0]["id"]  # 从查询接口获取最新发布的这条广告ID

                # 上架
                server = "otc/advertise/on/shelves"
                data = {"id": advertid_sale}
                r_on_sale = request2DKApi(server, data).send()
                print(r_on_sale)

                # 查询商家上架后账户数据,上架广告认证商家不扣除广告费用
                inquire_Merchant_member_wallet = connect_mysql().connect2mysql(
                    self.inquire_Merchant_wallet_CNYT_sql)
                inquire_Merchant_member_wallet_list_shelf = DKApiBase(
                ).mysqlResultFormat(
                    inquire_Merchant_member_wallet,
                    ["coin_id", "balance", "frozen_balance", "lock_balance"])

                # 判断认证商家上架买入广告后可用余额及冻结余额不变
                if inquire_Merchant_member_wallet_list["balance"] == inquire_Merchant_member_wallet_list_shelf["balance"] \
                        and inquire_Merchant_member_wallet_list["frozen_balance"] == inquire_Merchant_member_wallet_list_shelf["frozen_balance"]:

                    # 查询交易方用户交易前账户数据
                    inquire_user_member_wallet = connect_mysql().connect2mysql(
                        self.inquire_member_wallet_CNYT_sql)
                    inquire_user_member_wallet_list = DKApiBase(
                    ).mysqlResultFormat(inquire_user_member_wallet, [
                        "coin_id", "balance", "frozen_balance", "lock_balance"
                    ])

                    # 卖币交易,不能是广告创建用户自己
                    server = "otc/order/sell"
                    data = {
                        "id": advertid_sale,  # 广告id
                        "coinId": self.otc_coin_id_CNYT,  # 币种id,otc_coin表ID
                        "price": self.advertPrice_CNYT,  # 当前价格
                        "money": self.advertPrice_CNYT * self.amount,  # 金额
                        "amount": self.amount,  # 数量
                        "remark": "自动脚本测试卖币",  # 要求、备注,非必传
                        "mode": ""  # 计算方式,金额/价格=数量为0,数量*价格=金额为1,非必传,默认为0
                    }
                    r_sale = request2DKApi(server, data, self.header).send()
                    print(r_sale)
                    orderSn_sale = DKApiBase().str2json(
                        r_sale[2])["data"]  # 下单结果获取交易订单号
                    if orderSn_sale is None:
                        self.assertRegexpMatches(r_sale[2],
                                                 '"message" : "创建订单成功"',
                                                 "创建订单失败")

                    # 查询交易方提交买币订单后的账户数据
                    inquire_user_member_wallet = connect_mysql().connect2mysql(
                        self.inquire_member_wallet_CNYT_sql)
                    inquire_user_member_wallet_list_addorder = DKApiBase(
                    ).mysqlResultFormat(inquire_user_member_wallet, [
                        "coin_id", "balance", "frozen_balance", "lock_balance"
                    ])

                    # 交易方用户可用余额计算:原可用余额-交易数量
                    user_coin_balance = inquire_user_member_wallet_list[
                        "balance"] - self.amount
                    # 交易方用户冻结余额计算:原冻结余额+交易数量
                    user_coin_frozen_balance = inquire_user_member_wallet_list[
                        "frozen_balance"] + self.amount

                    # 判断交易用户提交卖出订单后账户冻结金额
                    if inquire_user_member_wallet_list_addorder[
                            "balance"] == user_coin_balance and inquire_user_member_wallet_list_addorder[
                                "frozen_balance"] == user_coin_frozen_balance:

                        # 广告商家确认付款
                        server = "otc/order/pay"
                        data = {"orderSn": orderSn_sale}
                        r_pay_sale = request2DKApi(server, data).send()
                        print(r_pay_sale)

                        # 交易用户放币
                        time.sleep(2)  # 等待2s避免订单状态更改不及时
                        server = "otc/order/release"
                        data = {
                            "orderSn": orderSn_sale,
                            "jyPassword": self.jyPassword
                        }
                        r_rel_sale = request2DKApi(server, data,
                                                   self.header).send()
                        print(r_rel_sale)

                        # 查询放币后广告商家账户数据
                        inquire_Merchant_member_wallet = connect_mysql(
                        ).connect2mysql(self.inquire_Merchant_wallet_CNYT_sql)
                        inquire_Merchant_member_wallet_list_transaction = DKApiBase(
                        ).mysqlResultFormat(inquire_Merchant_member_wallet, [
                            "coin_id", "balance", "frozen_balance",
                            "lock_balance"
                        ])
                        # 查询放币后交易方账户数据
                        inquire_user_member_wallet = connect_mysql(
                        ).connect2mysql(self.inquire_member_wallet_CNYT_sql)
                        inquire_user_member_wallet_list_transaction = DKApiBase(
                        ).mysqlResultFormat(inquire_user_member_wallet, [
                            "coin_id", "balance", "frozen_balance",
                            "lock_balance"
                        ])
                        # 查询交易订单数据
                        otc_order_datas = connect_mysql().connect2mysql(
                            '''SELECT id, advertise_id, commission, number, member_id, customer_id, `status`  FROM otc_order WHERE order_sn = '{}';'''
                            .format(orderSn_sale))
                        otc_order_datas_list = DKApiBase().mysqlResultFormat(
                            otc_order_datas, [
                                "id", "advertise_id", "commission", "number",
                                "member_id", "customer_id", "status"
                            ])

                        # 商家可用余额计算:原有可用余额+订单金额-交易手续费
                        merchant_coin_balance = inquire_Merchant_member_wallet_list[
                            "balance"] + otc_order_datas_list[
                                "number"] - otc_order_datas_list["commission"]
                        # 用户可用冻结余额计算:原有冻结余额-订单金额
                        user_coin_frozen_balance_after = inquire_user_member_wallet_list_addorder[
                            "frozen_balance"] - otc_order_datas_list["number"]

                        if inquire_Merchant_member_wallet_list_transaction["balance"] == merchant_coin_balance \
                                and inquire_user_member_wallet_list_transaction["frozen_balance"] == user_coin_frozen_balance_after:

                            # 下架广告
                            server = "otc/advertise/off/shelves"
                            data = {"id": advertid_sale}
                            r_off_sale = request2DKApi(server, data).send()
                            print(r_off_sale)

                            # 查询下架广告后商家账户数据,同下架广告前进行对比
                            merchant_coin_end_wallet = connect_mysql(
                            ).connect2mysql(
                                self.inquire_Merchant_wallet_CNYT_sql)
                            merchant_coin_end_wallet_list = DKApiBase(
                            ).mysqlResultFormat(merchant_coin_end_wallet, [
                                "coin_id", "balance", "frozen_balance",
                                "lock_balance"
                            ])

                            # 下架卖出广告不影响商家账户可用余额和冻结金额
                            if inquire_Merchant_member_wallet_list_transaction["balance"] == merchant_coin_end_wallet_list["balance"] \
                                    and inquire_Merchant_member_wallet_list_transaction["frozen_balance"] == merchant_coin_end_wallet_list["frozen_balance"]:
                                print("下架买入广告后商家用户账户数据不变,可以继续后续操作")
                            else:
                                logger.error("下架买入广告后商家用户账户数据发生变化,错误")
                                print("下架买入广告后商家用户账户数据发生变化,错误")
                        else:
                            logger.error("放币后用户账户金额不正确")
                            print("放币后用户账户金额不正确")
                    else:
                        logger.error("交易用户冻结账户金额不正确")
                        print("交易用户冻结账户金额不正确")
                else:
                    logger.error("上架广告后商家账户余额不正确")
                    print("上架广告后商家账户余额不正确")
            else:
                logger.error("添加广告后该商家账户余额已经发生变动,请检测")
                print("添加广告后该商家账户余额已经发生变动,请检测")
        else:
            logger.info("该用户不是认证商家")
            print("该用户不是认证商家")

        # 最后走删除广告的业务,如果前面业务失败,则删除广告业务断言抛出异常
        server = "otc/advertise/delete"
        data = {"id": advertid_sale}  # 广告ID
        r_del_sale = request2DKApi(server, data).send()
        print(r_del_sale)
        self.assertRegexpMatches(r_del_sale[2], '"message" : "删除成功"', "结果断言失败")
Ejemplo n.º 13
0
    def test_otc_advertise_merchant_sells(self):
        """认证商家卖出广告并核对用户账户数据变更:1.创建卖出广告2.查询该条广告3.上架4.买币交易5.确认付款6.放币7.下架广告8.删除广告"""

        # 查询商家认证状态:0为普通用户;1为实名认证用户;2为认证商家
        logger.info("------执行test_otc_advertise_merchant_sells------")
        try:
            user_member_lever = connect_mysql().connect2mysql(
                self.member_level_sql)[0][0]
        except Exception as e:
            print(e)
            logger.error(e)
            user_member_lever = 0

        if user_member_lever == 2:

            # 查询商家用户钱包账户数据
            inquire_Merchant_member_wallet = connect_mysql().connect2mysql(
                self.inquire_Merchant_wallet_CNYT_sql)
            inquire_Merchant_member_wallet_list = DKApiBase(
            ).mysqlResultFormat(
                inquire_Merchant_member_wallet,
                ["coin_id", "balance", "frozen_balance", "lock_balance"])

            # 创建卖出广告
            server = "otc/advertise/create"
            data = {
                "price": self.advertPrice_CNYT,
                "advertiseType": "1",  # 0买,1卖
                "coin.id": self.otc_coin_id_CNYT,
                "minLimit": "100",
                "maxLimit": "1000",
                "timeLimit": "30",
                "country": "中国",
                "priceType": "0",
                "premiseRate": "",
                "remark": "认证商家卖出广告,自动化脚本添加",
                "number": self.otc_number,
                "pay[]": "银联",
                "auto": "1",  # 是否开启自动回复0否1是,默认否
                "autoword": "先付款,后放币",
                "needBindPhone": "1",  # 是否需要交易方已绑定手机号,0:不需要,1:需要
                "needRealname": "1",  # 是否需要交易方已做实名认证,0:不需要,1:需要
                "needTradeTimes": "10",  # 需要交易方至少完成过N笔交易(默认为0)
                "needPutonDiscount": "1",  # 是否使用优惠币种支付,0:不使用,1:使用
                "bindingResult": "",  # 绑定结果,非必传项
                "jyPassword": self.jyPassword
            }
            r_sale = request2DKApi(server, data).send()
            print(r_sale)

            # 查询商家账户数据,提交广告时不扣除账户币种数据
            inquire_Merchant_member_wallet = connect_mysql().connect2mysql(
                self.inquire_Merchant_wallet_CNYT_sql)
            inquire_Merchant_member_wallet_list_add = DKApiBase(
            ).mysqlResultFormat(
                inquire_Merchant_member_wallet,
                ["coin_id", "balance", "frozen_balance", "lock_balance"])

            # 判断添加广告后商家账户余额是否发生变动,如变动证明数据有问题则不执行后续操作
            if inquire_Merchant_member_wallet_list["balance"] == inquire_Merchant_member_wallet_list_add["balance"] \
                    and inquire_Merchant_member_wallet_list["frozen_balance"] == inquire_Merchant_member_wallet_list_add["frozen_balance"]:

                # 查询个人所有广告获得最新创建广告
                server = "otc/advertise/all"
                r_Inquire_sale = request2DKApi(server).send()
                print(r_Inquire_sale)
                advertid_sale = DKApiBase().str2json(
                    r_Inquire_sale[2])["data"][0]["id"]  # 从查询接口获取最新发布的这条广告ID

                # 上架
                server = "otc/advertise/on/shelves"
                data = {"id": advertid_sale}
                r_on_sale = request2DKApi(server, data).send()
                print(r_on_sale)

                # 查询商家上架后账户数据,上架广告认证商家不扣除广告费用
                inquire_Merchant_member_wallet = connect_mysql().connect2mysql(
                    self.inquire_Merchant_wallet_CNYT_sql)
                inquire_Merchant_member_wallet_list_shelf = DKApiBase(
                ).mysqlResultFormat(
                    inquire_Merchant_member_wallet,
                    ["coin_id", "balance", "frozen_balance", "lock_balance"])

                # 商家上架广告后可用余额计算:原可用余额-广告金额
                merchant_coin_shelf_balance = inquire_Merchant_member_wallet_list_add[
                    "balance"] - self.otc_number
                # 商家上架广告后冻结余额计算:原冻结余额+广告金额
                merchant_coin_shelf_forzen_balance = inquire_Merchant_member_wallet_list_add[
                    "frozen_balance"] + self.otc_number

                # 判断商家账户冻结等于广告冻结数量
                logger.info("上架前商家账户可用余额:{}".format(
                    inquire_Merchant_member_wallet_list["balance"]))
                logger.info("上架后商家账户可用余额:{}".format(
                    inquire_Merchant_member_wallet_list_shelf["balance"]))
                logger.info("上架前商家账户冻结余额:{}".format(
                    inquire_Merchant_member_wallet_list["frozen_balance"]))
                logger.info("上架后商家账户冻结余额:{}".format(
                    inquire_Merchant_member_wallet_list_shelf["frozen_balance"]
                ))

                if inquire_Merchant_member_wallet_list_shelf["balance"] == merchant_coin_shelf_balance \
                        and inquire_Merchant_member_wallet_list_shelf["frozen_balance"] == merchant_coin_shelf_forzen_balance:

                    # 查询交易方用户交易前账户数据
                    inquire_user_member_wallet = connect_mysql().connect2mysql(
                        self.inquire_member_wallet_CNYT_sql)
                    inquire_user_member_wallet_list = DKApiBase(
                    ).mysqlResultFormat(inquire_user_member_wallet, [
                        "coin_id", "balance", "frozen_balance", "lock_balance"
                    ])

                    # 买币交易,不能是广告创建用户自己
                    server = "otc/order/buy"
                    data = {
                        "id": advertid_sale,  # 广告id
                        "coinId": self.otc_coin_id_CNYT,  # 币种id,otc_coin表ID
                        "price": self.advertPrice_CNYT,  # 当前价格
                        "money": self.advertPrice_CNYT * self.amount,  # 金额
                        "amount": self.amount,  # 数量
                        "remark": "自动脚本测试买币",  # 要求、备注,非必传
                        "mode": ""  # 计算方式,金额/价格=数量为0,数量*价格=金额为1,非必传,默认为0
                    }
                    r_buy_sale = request2DKApi(server, data,
                                               self.header).send()
                    print(r_buy_sale)
                    orderSn_sale = DKApiBase().str2json(
                        r_buy_sale[2])["data"]  # 下单结果获取交易订单号
                    if orderSn_sale is None:
                        self.assertRegexpMatches(r_buy_sale[2],
                                                 '"message" : "创建订单成功"',
                                                 "创建订单失败")

                    # 买家确认付款
                    server = "otc/order/pay"
                    data = {"orderSn": orderSn_sale}
                    r_pay_sale = request2DKApi(server, data,
                                               self.header).send()
                    print(r_pay_sale)

                    # 卖家放币
                    time.sleep(2)  # 等待2s避免订单状态更改不及时
                    server = "otc/order/release"
                    data = {
                        "orderSn": orderSn_sale,
                        "jyPassword": self.jyPassword
                    }
                    r_rel_sale = request2DKApi(server, data).send()
                    print(r_rel_sale)

                    # 查询交易方用户交易后账户
                    inquire_user_member_wallet = connect_mysql().connect2mysql(
                        self.inquire_member_wallet_CNYT_sql)
                    inquire_user_member_wallet_list_shelf = DKApiBase(
                    ).mysqlResultFormat(inquire_user_member_wallet, [
                        "coin_id", "balance", "frozen_balance", "lock_balance"
                    ])
                    # 查询广告方交易后账户
                    inquire_Merchant_member_wallet = connect_mysql(
                    ).connect2mysql(self.inquire_Merchant_wallet_CNYT_sql)
                    inquire_Merchant_member_wallet_list_transaction = DKApiBase(
                    ).mysqlResultFormat(inquire_Merchant_member_wallet, [
                        "coin_id", "balance", "frozen_balance", "lock_balance"
                    ])
                    # 根据订单号查询订单交易信息
                    otc_order_datas = connect_mysql().connect2mysql(
                        '''SELECT id, advertise_id, commission, number, member_id, customer_id, `status`  FROM otc_order WHERE order_sn = '120480325817208832';'''
                    )
                    otc_order_datas_list = DKApiBase().mysqlResultFormat(
                        otc_order_datas, [
                            "id", "advertise_id", "commission", "number",
                            "member_id", "customer_id", "status"
                        ])

                    # 卖出广告广告方资金流向:账户冻结金额-订单金额-订单手续费
                    merchant_coin_after = inquire_Merchant_member_wallet_list_shelf[
                        "frozen_balance"] - otc_order_datas_list[
                            "commission"] - otc_order_datas_list["number"]
                    # 卖出广告交易方资金流向:账户余额+订单金额
                    user_coin_after = inquire_user_member_wallet_list[
                        "balance"] + otc_order_datas_list["number"]
                    # 判断放币后交易方及广告方账户数据
                    if inquire_Merchant_member_wallet_list_transaction[
                            "frozen_balance"] == merchant_coin_after and inquire_user_member_wallet_list_shelf[
                                "balance"] == user_coin_after:
                        logger.info("交易前商家冻结金额:{};交易后商家冻结金额:{}".format(
                            inquire_Merchant_member_wallet_list_shelf[
                                "frozen_balance"],
                            inquire_Merchant_member_wallet_list_transaction[
                                "frozen_balance"]))
                        logger.info("交易前用户冻结金额:{};交易后用户冻结金额:{}".format(
                            inquire_user_member_wallet_list["balance"],
                            inquire_user_member_wallet_list_shelf["balance"]))

                        # 查询广告剩余数量  advertid_sale
                        advert_datas = connect_mysql().connect2mysql(
                            '''SELECT remain_amount, `status` FROM advertise WHERE id = {};'''
                            .format(advertid_sale))
                        advert_datas_list_num = DKApiBase().mysqlResultFormat(
                            advert_datas, ["remain_amount", "status"])

                        # 下架广告
                        server = "otc/advertise/off/shelves"
                        data = {"id": advertid_sale}
                        r_off_sale = request2DKApi(server, data).send()
                        print(r_off_sale)

                        # 查询下架广告后商家账户数据,同下架广告前进行对比
                        merchant_coin_end_wallet = connect_mysql(
                        ).connect2mysql(self.inquire_Merchant_wallet_CNYT_sql)
                        merchant_coin_end_wallet_list = DKApiBase(
                        ).mysqlResultFormat(merchant_coin_end_wallet, [
                            "coin_id", "balance", "frozen_balance",
                            "lock_balance"
                        ])

                        # 商家可用余额计算:原可用余额+广告剩余数量
                        merchant_coin_end_balance = inquire_Merchant_member_wallet_list_transaction[
                            "balance"] + advert_datas_list_num["remain_amount"]
                        # 商家冻结余额计算:原冻结余额-广告剩余数量
                        merchant_coin_end_forzen_balance = inquire_Merchant_member_wallet_list_transaction[
                            "frozen_balance"] - advert_datas_list_num[
                                "remain_amount"]

                        # 查询下架后广告状态
                        advert_datas = connect_mysql().connect2mysql(
                            '''SELECT remain_amount, `status` FROM advertise WHERE id = {};'''
                            .format(advertid_sale))
                        advert_datas_list_stauts = DKApiBase(
                        ).mysqlResultFormat(advert_datas,
                                            ["remain_amount", "status"])

                        # 判断下架后商家账户数据,商家下架卖出广告资金流向:冻结金额-广告剩余数量;可用币数+广告剩余数量
                        if merchant_coin_end_wallet_list[
                                "balance"] == merchant_coin_end_balance and merchant_coin_end_wallet_list[
                                    "frozen_balance"] == merchant_coin_end_forzen_balance:
                            if advert_datas_list_stauts["status"] == 1:
                                print("广告{}为下架状态,可执行最后一步删除操作".format(
                                    advertid_sale))
                            else:
                                logger.error(
                                    "广告{}状态{}不正确,不能删除;0=上架/1=下架/2=已关闭(删除)".
                                    format(advertid_sale,
                                           advert_datas_list_stauts["status"]))
                                print("广告{}状态{}不正确,不能删除;0=上架/1=下架/2=已关闭(删除)".
                                      format(
                                          advertid_sale,
                                          advert_datas_list_stauts["status"]))
                        else:
                            logger.error(
                                "下架广告{}后发布者账户数据核对不正确".format(advertid_sale))
                            print("下架广告{}后发布者账户数据核对不正确".format(advertid_sale))
                    else:
                        logger.error("交易后账户数据不一致")
                        print("交易后账户数据不一致")
                else:
                    logger.error("上架广告后商家账户余额不正确")
                    print("上架广告后商家账户余额不正确")
            else:
                logger.error("添加广告后该商家账户余额已经发生变动,请检测")
                print("添加广告后该商家账户余额已经发生变动,请检测")
        else:
            logger.info("该用户不是认证商家")
            print("该用户不是认证商家")

        # 最后执行删除广告的业务,如果前面业务失败,则删除广告业务断言抛出异常
        server = "otc/advertise/delete"
        data = {"id": advertid_sale}  # 广告ID
        r_del_sale = request2DKApi(server, data).send()
        print(r_del_sale)
        self.assertRegexpMatches(r_del_sale[2], '"message" : "删除成功"', "结果断言失败")