Example #1
0
    def changeInfo(self, msg, info, order_id, userInfo):

        cm = ConnectMysql()
        # try:

        # 查询用户是否有上线
        check_user_sql = "SELECT * FROM taojin_user_info WHERE wx_number='" + str(
            userInfo['NickName']) + "';"
        check_user_res = cm.ExecQuery(check_user_sql)

        # 判断是否已经有个人账户,没有返回信息
        if len(check_user_res) < 1:
            cm.Close()
            return {"info": "not_info"}
        else:
            get_query_sql = "SELECT * FROM taojin_query_record WHERE good_title='" + info[
                'skuList'][0]['skuName'] + "'AND username='******' ORDER BY create_time LIMIT 1;"

            get_query_info = cm.ExecQuery(get_query_sql)

            # 定义SQL语句 查询用户是否已经存在邀请人
            # 判断是否已经有邀请人了
            if check_user_res and check_user_res[0][16] != 0:

                get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str(
                    check_user_res[0][16]) + "';"

                get_parent_info = cm.ExecQuery(get_parent_sql)
                print(get_parent_info)

                add_balance = round(
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                withdrawals_amount = round(
                    float(check_user_res[0][8]) +
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                jd = round(
                    float(check_user_res[0][6]) +
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                total_rebate_amount = round(
                    float(check_user_res[0][5]) +
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                save_money = round(
                    check_user_res[0][9] +
                    (float(get_query_info[0][2]) -
                     float(info['skuList'][0]['payPrice'])), 2)

                add_parent_balance = round(
                    float(info['skuList'][0]['actualFee']) * 0.1, 2)
                withdrawals_amount2 = round(
                    float(get_parent_info[0][8]) + float(add_balance) * 0.1, 2)

                cm.ExecNonQuery(
                    "UPDATE taojin_user_info SET withdrawals_amount='" +
                    str(withdrawals_amount) + "', save_money='" +
                    str(save_money) + "', jd_rebate_amount='" + str(jd) +
                    "', total_rebate_amount='" + str(total_rebate_amount) +
                    "', update_time='" + str(time.time()) +
                    "' WHERE wx_number='" + str(userInfo['NickName']) + "';")
                cm.ExecNonQuery(
                    "UPDATE taojin_user_info SET withdrawals_amount='" +
                    str(withdrawals_amount2) + "', update_time='" +
                    str(time.time()) + "' WHERE lnivt_code='" +
                    str(check_user_res[0][16]) + "';")

                cm.ExecNonQuery(
                    "INSERT INTO taojin_order(username, order_id, order_source) VALUES('"
                    + str(userInfo['NickName']) + "', '" + str(order_id) +
                    "', '1')")

                args = {
                    'username': check_user_res[0][1],
                    'rebate_amount': add_balance,
                    'type': 3,
                    'create_time': time.time()
                }

                # 写入返利日志
                cm.InsertRebateLog(args)

                args2 = {
                    'username': get_parent_info[0][1],
                    'rebate_amount': add_parent_balance,
                    'type': 4,
                    'create_time': time.time()
                }

                # 写入返利日志
                cm.InsertRebateLog(args2)

                parent_user_text = '''
一一一一  推广信息 一一一一

您的好友【%s】又完成了一笔订单,返利提成%s元已发放到您的账户
回复【个人信息】查询账户信息及提成
                        ''' % (check_user_res[0][3], add_parent_balance)

                user_text = '''
一一一一系统消息一一一一

订单【%s】已完成!
返利金%s元已发放到您的个人账户!

回复【提现】可申请账户余额提现
回复【个人信息】可看个当前账户信息

分享【京东商品链接】或者【淘口令】精准查询商品优惠券和返利信息!
分享【VIP视频链接】免费查看高清VIP视频!

优惠券使用教程:
http://t.cn/RnAKqWW
京东优惠券网站:
http://jdyhq.ptjob.net
淘宝优惠券网站:
http://tbyhq.ptjob.net
邀请好友得返利:
http://t.cn/RnAKafe
                        ''' % (order_id, add_balance)
                cm.Close()
                return {
                    'parent_user_text': parent_user_text,
                    'user_text': user_text,
                    'info': 'success',
                    'parent': get_parent_info[0][1]
                }
            else:
                add_balance = round(
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                withdrawals_amount = round(
                    float(check_user_res[0][8]) +
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                jd = round(
                    float(check_user_res[0][6]) +
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                total_rebate_amount = round(
                    float(check_user_res[0][5]) +
                    float(info['skuList'][0]['actualFee']) * 0.3, 2)
                save_money = round(
                    check_user_res[0][9] +
                    (float(get_query_info[0][2]) -
                     float(info['skuList'][0]['payPrice'])), 2)

                up_sql = "UPDATE taojin_user_info SET jd_rebate_amount='" + str(
                    jd) + "', withdrawals_amount='" + str(
                        withdrawals_amount) + "', save_money='" + str(
                            save_money) + "', total_rebate_amount='" + str(
                                total_rebate_amount
                            ) + "', update_time='" + str(
                                time.time()) + "' WHERE wx_number='" + str(
                                    userInfo['NickName']) + "';"
                cm.ExecNonQuery(up_sql)
                # cm.ExecNonQuery("UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "' WHERE wx_number='" + str(msg['FromUserName']) + "';")
                cm.ExecNonQuery(
                    "INSERT INTO taojin_order(username, order_id, order_source) VALUES('"
                    + str(userInfo['NickName']) + "', '" + str(order_id) +
                    "', '2')")

                args = {
                    'username': check_user_res[0][1],
                    'rebate_amount': add_balance,
                    'type': 3,
                    'create_time': time.time()
                }

                # 写入返利日志
                cm.InsertRebateLog(args)

                user_text = '''
一一一一 订单消息 一一一一

订单【%s】标记成功,返利金%s已发放到您的账户
回复【个人信息】 查看订单及返利信息
                            ''' % (order_id, add_balance)
                cm.Close()
                return {
                    'user_text': user_text,
                    'info': 'not_parent_and_success'
                }
Example #2
0
    def changeInfo(self, msg, info, order_id, userInfo):
        try:
            cm = ConnectMysql()

            # 查询用户是否有上线
            check_user_sql = "SELECT * FROM taojin_user_info WHERE wx_number='" + str(
                userInfo['NickName']) + "';"
            check_user_res = cm.ExecQuery(check_user_sql)

            # 判断是否已经有个人账户,没有返回信息
            if len(check_user_res) < 1:
                cm.Close()
                return {"info": "not_info"}
            else:

                get_query_sql = "SELECT * FROM taojin_query_record WHERE good_title='" + info[
                    'auctionTitle'] + "'AND username='******' ORDER BY create_time LIMIT 1;"

                get_query_info = cm.ExecQuery(get_query_sql)

                # 定义SQL语句 查询用户是否已经存在邀请人
                # 判断是否已经有邀请人了
                if check_user_res and check_user_res[0][16] != 0:

                    get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str(
                        check_user_res[0][16]) + "';"

                    get_parent_info = cm.ExecQuery(get_parent_sql)

                    add_balance = round(float(info['feeString']) * 0.3, 2)
                    withdrawals_amount = round(
                        float(check_user_res[0][8]) +
                        float(info['feeString']) * 0.3, 2)
                    taobao_rebate_amount = round(
                        float(check_user_res[0][7]) +
                        float(info['feeString']) * 0.3, 2)
                    total_rebate_amount = round(
                        float(check_user_res[0][5]) +
                        float(info['feeString']) * 0.3, 2)
                    save_money = round(
                        check_user_res[0][9] +
                        (float(get_query_info[0][2]) -
                         float(info['realPayFeeString'])) + add_balance, 2)
                    total_order_num = int(check_user_res[0][10]) + 1
                    taobao_order_num = int(check_user_res[0][12]) + 1

                    add_parent_balance = round(
                        float(info['feeString']) * 0.1, 2)
                    friends_rebatr = float(
                        get_parent_info[0][18]) + float(add_balance)
                    withdrawals_amount2 = round(
                        float(get_parent_info[0][8]) +
                        float(add_balance) * 0.1, 2)

                    cm.ExecNonQuery(
                        "UPDATE taojin_user_info SET withdrawals_amount='" +
                        str(withdrawals_amount) + "', save_money='" +
                        str(save_money) + "', taobao_rebate_amount='" +
                        str(taobao_rebate_amount) +
                        "', total_rebate_amount='" + str(total_rebate_amount) +
                        "', order_quantity='" + str(total_order_num) +
                        "', taobao_order_quantity='" + str(taobao_order_num) +
                        "', update_time='" + str(time.time()) +
                        "' WHERE wx_number='" + str(userInfo['NickName']) +
                        "';")
                    cm.ExecNonQuery(
                        "UPDATE taojin_user_info SET withdrawals_amount='" +
                        str(withdrawals_amount2) + "', friends_rebate='" +
                        str(friends_rebatr) + "', update_time='" +
                        str(time.time()) + "' WHERE lnivt_code='" +
                        str(check_user_res[0][16]) + "';")

                    cm.ExecNonQuery(
                        "INSERT INTO taojin_order(username, order_id, order_source) VALUES('"
                        + str(userInfo['NickName']) + "', '" + str(order_id) +
                        "', '2')")

                    args = {
                        'username': check_user_res[0][1],
                        'rebate_amount': add_balance,
                        'type': 3,
                        'create_time': time.time()
                    }

                    # 写入返利日志
                    cm.InsertRebateLog(args)

                    args2 = {
                        'username': get_parent_info[0][1],
                        'rebate_amount': add_parent_balance,
                        'type': 4,
                        'create_time': time.time()
                    }

                    # 写入返利日志
                    cm.InsertRebateLog(args2)

                    parent_user_text = '''
    一一一一  推广信息 一一一一

    您的好友【%s】又完成了一笔订单,返利提成%s元已发放到您的账户
    回复【个人信息】查询账户信息及提成
                    ''' % (check_user_res[0][3], add_parent_balance)

                    user_text = '''
    一一一一系统消息一一一一

    订单【%s】已完成!
    返利金%s元已发放到您的个人账户!

    回复【提现】可申请账户余额提现
    回复【个人信息】可看个当前账户信息

    分享【京东商品链接】或者【淘口令】精准查询商品优惠券和返利信息!
    分享【VIP视频链接】免费查看高清VIP视频!

    优惠券使用教程:
    http://t.cn/RnAKqWW
    京东优惠券网站:
    http://jdyhq.ptjob.net
    淘宝优惠券网站:
    http://tbyhq.ptjob.net
    邀请好友得返利:
    http://t.cn/RnAKafe
                    ''' % (order_id, add_balance)

                    return {
                        'parent_user_text': parent_user_text,
                        'user_text': user_text,
                        'info': 'success',
                        'parent': get_parent_info[0][1]
                    }
                else:
                    add_balance = round(float(info['feeString']) * 0.3, 2)
                    withdrawals_amount = round(
                        float(check_user_res[0][8]) +
                        float(info['feeString']) * 0.3, 2)
                    taobao_rebate_amount = round(
                        float(check_user_res[0][7]) +
                        float(info['feeString']) * 0.3, 2)
                    total_rebate_amount = round(
                        float(check_user_res[0][5]) +
                        float(info['feeString']) * 0.3, 2)
                    save_money = round(
                        check_user_res[0][9] +
                        (float(get_query_info[0][2]) -
                         float(info['realPayFeeString'])) + add_balance, 2)
                    total_order_num = int(check_user_res[0][10]) + 1
                    taobao_order_num = int(check_user_res[0][12]) + 1

                    cm.ExecNonQuery(
                        "UPDATE taojin_user_info SET withdrawals_amount='" +
                        str(withdrawals_amount) + "', save_money='" +
                        str(save_money) + "', taobao_rebate_amount='" +
                        str(taobao_rebate_amount) +
                        "', total_rebate_amount='" + str(total_rebate_amount) +
                        "', order_quantity='" + str(total_order_num) +
                        "', taobao_order_quantity='" + str(taobao_order_num) +
                        "', update_time='" + str(time.time()) +
                        "' WHERE wx_number='" + str(userInfo['NickName']) +
                        "';")

                    cm.ExecNonQuery(
                        "INSERT INTO taojin_order(username, order_id, order_source) VALUES('"
                        + str(userInfo['NickName']) + "', '" + str(order_id) +
                        "', '2')")

                    args = {
                        'username': check_user_res[0][1],
                        'rebate_amount': add_balance,
                        'type': 3,
                        'create_time': time.time()
                    }

                    # 写入返利日志
                    cm.InsertRebateLog(args)

                    user_text = '''
    一一一一系统消息一一一一

    订单【%s】已完成!
    返利金%s元已发放到您的个人账户!

    回复【提现】可申请账户余额提现
    回复【个人信息】可看个当前账户信息

    分享【京东商品链接】或者【淘口令】精准查询商品优惠券和返利信息!
    分享【VIP视频链接】免费查看高清VIP视频!

    优惠券使用教程:
    http://t.cn/RnAKqWW
    京东优惠券网站:
    http://jdyhq.ptjob.net
    淘宝优惠券网站:
    http://tbyhq.ptjob.net
    邀请好友得返利:
    http://t.cn/RnAKafe
                                ''' % (order_id, add_balance)

                    return {
                        'user_text': user_text,
                        'info': 'not_parent_and_success'
                    }
        except Exception as e:
            self.logger.debug(e)
            return {'info': 'feild'}
Example #3
0
    def order(self, orderId, msg):
        """
        用户发送过来订单号,查询订单是否完成,完成并返利
        :param orderId:
        :return:
        """
        # 获取十分钟之前的订单
        m10 = (datetime.datetime.now() -
               datetime.timedelta(minutes=10)).strftime("%Y-%m-%d %H:%M:%S")

        get_order_url = 'http://api.hitui.net/tbk_order?appkey=JoB3RIns&start_time={m}&span=600&session={session}&tk_status=12'\
        .format(m=m10, session=config.get('SYS', 'session'))

        print('get_order_url', get_order_url)

        response = self.se.get(get_order_url)
        print(response.text)
        adminuser = self.bot2.friends().search(
            config.get('ADMIN', 'ADMIN_USER'))[0]
        if 'error_response' in response.text:
            text_to_user = '''
一一一一返利信息一一一一

返利失败,可能原因:

1,订单错误请检查重新发送
2,当前订单已经失效或取消
3,当前订单并非本渠道购买
            '''

            text_to_admin = '''
一一一一返利信息一一一一

订单返利失败,订单号为{id}
用户为{user}
            '''.format(id=orderId, user=msg.sender.nick_name)

            adminuser.send(text_to_admin)
            return text_to_user

        if str(orderId) not in response.text:
            to_user = '''
一一一一返利信息一一一一

返利失败,可能原因:

1,订单错误请检查重新发送
2,当前订单已经失效或取消
3,当前订单并非本渠道购买
            '''
            return to_user

        data = json.loads(
            response.text
        )['tbk_sc_order_get_response']['results']['n_tbk_order']

        for item in data:
            if int(item['trade_id']) == int(orderId):
                # 计算返利金额
                fx = round(
                    float(item['pub_share_pre_fee']) *
                    float(config.get('BN', 'bn3t')), 2)
                print(fx)
                fx_pp = round(float(fx) * float(config.get('BN', 'bn4')), 2)
                try:
                    cm = ConnectMysql()
                    # 查询用户是否有上线
                    check_user_sql = "SELECT * FROM taojin_user_info WHERE puid='" + msg.sender.puid + "' AND bot_puid='" + self.bot2.self.puid + "';"
                    check_user_res = cm.ExecQuery(check_user_sql)
                    # 定义SQL语句 查询用户是否已经存在邀请人
                    # 判断是否已经有邀请人了
                    if check_user_res and check_user_res[0][17] != '0':

                        # 获取邀请人信息
                        get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str(
                            check_user_res[0][17]
                        ) + "' AND bot_puid='" + self.bot2.self.puid + "';"

                        get_parent_info = cm.ExecQuery(get_parent_sql)

                        # 计算返佣
                        add_balance = fx
                        # 累加余额
                        withdrawals_amount = round(
                            float(check_user_res[0][9]) + add_balance, 2)
                        # 累加淘宝总返利
                        taobao_rebate_amount = round(
                            float(check_user_res[0][8]) + add_balance, 2)
                        # 累加总返利
                        total_rebate_amount = round(
                            float(check_user_res[0][6]) + add_balance, 2)

                        jishen = fx

                        # 计算共节省金额,商品原价减去实际支付价格,加上原有节省金额加上返佣
                        save_money = round(
                            check_user_res[0][10] + jishen + add_balance, 2)
                        # 总订单数加一
                        total_order_num = int(check_user_res[0][11]) + 1
                        # 淘宝订单数加一
                        taobao_order_num = int(check_user_res[0][13]) + 1

                        # 邀请人返利金额
                        add_parent_balance = fx_pp

                        # 给邀请人好友返利加上金额
                        friends_rebatr = round(
                            float(get_parent_info[0][19]) +
                            float(add_parent_balance))
                        # 邀请人总钱数加上返利金额
                        withdrawals_amount2 = round(
                            float(get_parent_info[0][9]) +
                            float(add_parent_balance), 2)

                        cm.InsertM(
                            "UPDATE taojin_user_info SET withdrawals_amount='"
                            + str(withdrawals_amount) + "', save_money='" +
                            str(save_money) + "', taobao_rebate_amount='" +
                            str(taobao_rebate_amount) +
                            "', total_rebate_amount='" +
                            str(total_rebate_amount) + "', order_quantity='" +
                            str(total_order_num) +
                            "', taobao_order_quantity='" +
                            str(taobao_order_num) + "', update_time='" +
                            str(time.time()) + "' WHERE puid='" +
                            msg.sender.puid + "' AND bot_puid='" +
                            self.bot2.self.puid + "';")
                        cm.InsertM(
                            "UPDATE taojin_user_info SET withdrawals_amount='"
                            + str(withdrawals_amount2) +
                            "', friends_rebate='" + str(friends_rebatr) +
                            "', update_time='" + str(time.time()) +
                            "' WHERE lnivt_code='" +
                            str(check_user_res[0][17]) + "' AND bot_puid='" +
                            self.bot2.self.puid + "';")

                        insert_to_sql = "INSERT INTO taojin_order(wx_bot, username, order_id, status, completion_time, order_source, puid, bot_puid, order_price, total_commission_rate, total_commission_fee) \
                                                VALUES ('"                                                           + self.bot2.self.nick_name + "', '" + msg.sender.nick_name + "', '" + str(
                            orderId) + "', '2','" \
                                        + item[
                                            'create_time'] + "', '2', '" + msg.sender.puid + "', '" + self.bot2.self.puid + "', '" + str(
                            item['alipay_total_price']) + "', '" + str(
                            item['total_commission_rate']) + "' , '" + str(fx) + "')"

                        # 把订单插入数据库
                        cm.InsertM(insert_to_sql)

                        # select_order_num = "SELECT * FROM taojin_order WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "'"
                        # 订单已完成,修改备注
                        '''order_num = cm.ExecQuery(select_order_num)
    
                            if order_num == ():
                                split_arr = this_user.remark_name.split('_')
                                new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'C', '_', split_arr[3])
                                bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name)
    
                                cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")
    
                            cm.ExecNonQuery("UPDATE taojin_order SET status=2 WHERE order_id='"+str(orderInfo[1])+"'")
    
                            # 累计订单数量
                            order_nums = cm.ExecQuery(select_order_num)
    
                            split_arr2 = this_user.remark_name.split('_')
    
                            new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', split_arr2[2], '_', len(order_nums))
    
                            bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name2)
    
                            cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")
                            '''
                        args = {
                            'wx_bot': self.bot2.self.nick_name,
                            'bot_puid': self.bot2.self.puid,
                            'username': check_user_res[0][4],
                            'puid': msg.sender.puid,
                            'rebate_amount': add_balance,
                            'type': 3,
                            'create_time': time.time()
                        }

                        # 写入返利日志
                        cm.InsertRebateLog(args)
                        parent_puid = get_parent_info[0][2]
                        args2 = {
                            'wx_bot': self.bot2.self.nick_name,
                            'bot_puid': self.bot2.self.puid,
                            'username': get_parent_info[0][4],
                            'puid': parent_puid,
                            'rebate_amount': add_parent_balance,
                            'type': 4,
                            'create_time': time.time()
                        }
                        # 写入返利日志
                        cm.InsertRebateLog(args2)
                        parent_user_text = '''
一一一一  推广信息 一一一一

好友【%s】又完成一笔订单
返利提成%s元已发放到个人账户
回复【个人信息】可查询账户详情
                                    ''' % (check_user_res[0][4],
                                           add_parent_balance)

                        user_text = '''
一一一一系统消息一一一一

订单【%s】返利成功
返利金%s元已发放到个人账户
回复【个人信息】可查询账户详情
回复【提现】可申请账户余额提现
                                    ''' % (orderId, add_balance)

                        # 提交事务,并关闭数据库连接
                        cm.CommitMysql()
                        cm.Close()

                        parent_user = self.bot2.friends().search(
                            nick_name=get_parent_info[0][4])[0]

                        parent_user.send(parent_user_text)
                        return user_text
                    else:
                        add_balance = fx
                        withdrawals_amount = round(
                            float(check_user_res[0][9]) + add_balance, 2)
                        taobao_rebate_amount = round(
                            float(check_user_res[0][8]) + add_balance, 2)
                        total_rebate_amount = round(
                            float(check_user_res[0][6]) + add_balance, 2)

                        jishen = add_balance

                        if jishen < 0:
                            jishen = 0

                        save_money = round(
                            check_user_res[0][10] + jishen + add_balance, 2)
                        total_order_num = int(check_user_res[0][11]) + 1
                        taobao_order_num = int(check_user_res[0][13]) + 1

                        cm.InsertM(
                            "UPDATE taojin_user_info SET withdrawals_amount='"
                            + str(withdrawals_amount) + "', save_money='" +
                            str(save_money) + "', taobao_rebate_amount='" +
                            str(taobao_rebate_amount) +
                            "', total_rebate_amount='" +
                            str(total_rebate_amount) + "', order_quantity='" +
                            str(total_order_num) +
                            "', taobao_order_quantity='" +
                            str(taobao_order_num) + "', update_time='" +
                            str(time.time()) + "' WHERE puid='" +
                            msg.sender.puid + "' AND bot_puid='" +
                            self.bot2.self.puid + "';")

                        insert_to_sql = "INSERT INTO taojin_order(wx_bot, username, order_id, status, completion_time, order_source, puid, bot_puid, order_price, total_commission_rate, total_commission_fee) \
                        VALUES ('"                                   + self.bot2.self.nick_name + "', '" + msg.sender.nick_name + "', '" + str(orderId) + "', '2','" \
                        + item['create_time'] + "', '2', '" + msg.sender.puid + "', '" + self.bot2.self.puid + "', '" + str(item['alipay_total_price']) + "', '" + str(item['total_commission_rate']) + "' , '" + str(fx) + "')"

                        # 把订单插入数据库
                        cm.InsertM(insert_to_sql)

                        # select_order_num = "SELECT * FROM taojin_order WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "'"
                        # 订单已完成,修改备注
                        '''order_num = cm.ExecQuery(select_order_num)
    
                            if order_num == ():
                                split_arr = this_user.remark_name.split('_')
                                new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'C', '_', split_arr[3])
                                self.logger.debug(new_remark_name)
                                bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name)
    
                                cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")
    
                            cm.ExecNonQuery("UPDATE taojin_order SET status=2 WHERE order_id='"+str(orderInfo[1])+"'")
    
                            # 累计订单数量
                            order_nums = cm.ExecQuery(select_order_num)
    
                            split_arr2 = this_user.remark_name.split('_')
    
                            new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', split_arr2[2], '_', len(order_nums))
    
                            bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name2)
    
                            cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")'''

                        args = {
                            'wx_bot': self.bot2.self.nick_name,
                            'bot_puid': self.bot2.self.puid,
                            'username': check_user_res[0][4],
                            'puid': msg.sender.puid,
                            'rebate_amount': add_balance,
                            'type': 3,
                            'create_time': time.time()
                        }
                        # 写入返利日志
                        cm.InsertRebateLog(args)

                        user_text = '''
一一一一系统消息一一一一

订单【%s】返利成功
返利金%s元已发放到个人账户
回复【个人信息】可查询账户详情
回复【提现】可申请账户余额提现
                                                ''' % (orderId, add_balance)
                        cm.CommitMysql()
                        cm.Close()

                        return user_text
                except Exception as e:
                    cm.Rollback()
                    trace = traceback.format_exc()
                    self.logger.warning("error:{},trace:{}".format(
                        str(e), trace))
                    text_to_admin = '''
一一一一返利信息一一一一

订单返利失败,订单号为{id}
用户为{user}
                                '''.format(id=orderId,
                                           user=msg.sender.nick_name)

                    adminuser.send(text_to_admin)
                    t = '''
一一一一一 订单信息 一一一一一
订单返利失败,以联系管理员
请等待处理!
                    '''
                    return t
Example #4
0
    def changeInfoAlimama(self, puid, orderInfo):
        try:
            cm = ConnectMysql()
            # 查询用户是否有上线
            check_user_sql = "SELECT * FROM taojin_user_info WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "';"
            check_user_res = cm.ExecQuery(check_user_sql)
            this_user = self.bot.friends().search(
                nick_name=check_user_res[0][4])[0]
            # 定义SQL语句 查询用户是否已经存在邀请人
            # 判断是否已经有邀请人了
            if check_user_res and check_user_res[0][17] != '0':

                # 获取邀请人信息
                get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str(
                    check_user_res[0]
                    [17]) + "' AND bot_puid='" + self.bot.self.puid + "';"

                get_parent_info = cm.ExecQuery(get_parent_sql)

                # 计算返佣
                add_balance = round(
                    float(orderInfo[9]) * float(self.config.get('BN', 'bn3t')),
                    2)
                # 累加余额
                withdrawals_amount = round(
                    float(check_user_res[0][9]) + add_balance, 2)
                # 累加淘宝总返利
                taobao_rebate_amount = round(
                    float(check_user_res[0][8]) + add_balance, 2)
                # 累加总返利
                total_rebate_amount = round(
                    float(check_user_res[0][6]) + add_balance, 2)

                jishen = round(
                    float(orderInfo[4]) * float(orderInfo[5]) -
                    float(orderInfo[6]))

                if jishen < 0:
                    jishen = 0

                # 计算共节省金额,商品原价减去实际支付价格,加上原有节省金额加上返佣
                save_money = round(
                    check_user_res[0][10] + jishen + add_balance, 2)
                # 总订单数加一
                total_order_num = int(check_user_res[0][11]) + 1
                # 淘宝订单数加一
                taobao_order_num = int(check_user_res[0][13]) + 1

                # 邀请人返利金额
                add_parent_balance = round(
                    float(orderInfo[9]) * float(self.config.get('BN', 'bn4')),
                    2)

                # 给邀请人好友返利加上金额
                friends_rebatr = round(
                    float(get_parent_info[0][19]) + float(add_parent_balance))
                # 邀请人总钱数加上返利金额
                withdrawals_amount2 = round(
                    float(get_parent_info[0][9]) + float(add_parent_balance),
                    2)

                cm.ExecNonQuery(
                    "UPDATE taojin_user_info SET withdrawals_amount='" +
                    str(withdrawals_amount) + "', save_money='" +
                    str(save_money) + "', taobao_rebate_amount='" +
                    str(taobao_rebate_amount) + "', total_rebate_amount='" +
                    str(total_rebate_amount) + "', order_quantity='" +
                    str(total_order_num) + "', taobao_order_quantity='" +
                    str(taobao_order_num) + "', update_time='" +
                    str(time.time()) + "' WHERE puid='" + puid +
                    "' AND bot_puid='" + self.bot.self.puid + "';")
                cm.ExecNonQuery(
                    "UPDATE taojin_user_info SET withdrawals_amount='" +
                    str(withdrawals_amount2) + "', friends_rebate='" +
                    str(friends_rebatr) + "', update_time='" +
                    str(time.time()) + "' WHERE lnivt_code='" +
                    str(check_user_res[0][17]) + "' AND bot_puid='" +
                    self.bot.self.puid + "';")

                #select_order_num = "SELECT * FROM taojin_order WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "'"
                # 订单已完成,修改备注
                '''order_num = cm.ExecQuery(select_order_num)

                if order_num == ():
                    split_arr = this_user.remark_name.split('_')
                    new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'C', '_', split_arr[3])
                    bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name)

                    cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")

                cm.ExecNonQuery("UPDATE taojin_order SET status=2 WHERE order_id='"+str(orderInfo[1])+"'")

                # 累计订单数量
                order_nums = cm.ExecQuery(select_order_num)

                split_arr2 = this_user.remark_name.split('_')

                new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', split_arr2[2], '_', len(order_nums))

                bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name2)

                cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")
                '''
                args = {
                    'wx_bot': self.bot.self.nick_name,
                    'bot_puid': self.bot.self.puid,
                    'username': check_user_res[0][4],
                    'puid': puid,
                    'rebate_amount': add_balance,
                    'type': 3,
                    'create_time': time.time()
                }

                # 写入返利日志
                cm.InsertRebateLog(args)
                parent_puid = get_parent_info[0][2]
                args2 = {
                    'wx_bot': self.bot.self.nick_name,
                    'bot_puid': self.bot.self.puid,
                    'username': get_parent_info[0][4],
                    'puid': parent_puid,
                    'rebate_amount': add_parent_balance,
                    'type': 4,
                    'create_time': time.time()
                }
                # 写入返利日志
                cm.InsertRebateLog(args2)
                parent_user_text = '''
一一一一  推广信息 一一一一

好友【%s】又完成一笔订单
返利提成%s元已发放到个人账户
回复【个人信息】可查询账户详情
                ''' % (check_user_res[0][4], add_parent_balance)

                user_text = '''
一一一一系统消息一一一一

订单【%s】返利成功
返利金%s元已发放到个人账户
回复【个人信息】可查询账户详情
回复【提现】可申请账户余额提现
                ''' % (orderInfo[1], add_balance)

                cm.Close()

                parent_user = self.bot.friends().search(
                    nick_name=get_parent_info[0][4])[0]

                parent_user.send(parent_user_text)
                this_user.send(user_text)
            else:
                add_balance = round(
                    float(orderInfo[9]) * float(self.config.get('BN', 'bn3t')),
                    2)
                withdrawals_amount = round(
                    float(check_user_res[0][9]) + add_balance, 2)
                taobao_rebate_amount = round(
                    float(check_user_res[0][8]) + add_balance, 2)
                total_rebate_amount = round(
                    float(check_user_res[0][6]) + add_balance, 2)

                jishen = add_balance

                if jishen < 0:
                    jishen = 0

                save_money = round(
                    check_user_res[0][10] + jishen + add_balance, 2)
                total_order_num = int(check_user_res[0][11]) + 1
                taobao_order_num = int(check_user_res[0][13]) + 1

                cm.ExecNonQuery(
                    "UPDATE taojin_user_info SET withdrawals_amount='" +
                    str(withdrawals_amount) + "', save_money='" +
                    str(save_money) + "', taobao_rebate_amount='" +
                    str(taobao_rebate_amount) + "', total_rebate_amount='" +
                    str(total_rebate_amount) + "', order_quantity='" +
                    str(total_order_num) + "', taobao_order_quantity='" +
                    str(taobao_order_num) + "', update_time='" +
                    str(time.time()) + "' WHERE puid='" + puid +
                    "' AND bot_puid='" + self.bot.self.puid + "';")

                #select_order_num = "SELECT * FROM taojin_order WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "'"
                # 订单已完成,修改备注
                '''order_num = cm.ExecQuery(select_order_num)

                if order_num == ():
                    split_arr = this_user.remark_name.split('_')
                    new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'C', '_', split_arr[3])
                    self.logger.debug(new_remark_name)
                    bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name)

                    cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")

                cm.ExecNonQuery("UPDATE taojin_order SET status=2 WHERE order_id='"+str(orderInfo[1])+"'")

                # 累计订单数量
                order_nums = cm.ExecQuery(select_order_num)

                split_arr2 = this_user.remark_name.split('_')

                new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', split_arr2[2], '_', len(order_nums))

                bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name2)

                cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")'''

                args = {
                    'wx_bot': self.bot.self.nick_name,
                    'bot_puid': self.bot.self.puid,
                    'username': check_user_res[0][4],
                    'puid': puid,
                    'rebate_amount': add_balance,
                    'type': 3,
                    'create_time': time.time()
                }
                # 写入返利日志
                cm.InsertRebateLog(args)

                user_text = '''
一一一一系统消息一一一一

订单【%s】返利成功
返利金%s元已发放到个人账户
回复【个人信息】可查询账户详情
回复【提现】可申请账户余额提现
                            ''' % (orderInfo[1], add_balance)
                cm.Close()

                this_user.send(user_text)

        except Exception as e:
            trace = traceback.format_exc()
            self.logger.warning("error:{},trace:{}".format(str(e), trace))
            return {'info': 'feild'}