예제 #1
0
def check_refund_order():
    connection = pymysql.connect(
        host='localhost',
        port=3306,
        user='******',
        password='******',
        db='native',
        charset='utf8',
    )
    cursor = connection.cursor()  # 定义一个数据库游标
    # 查找订单状态为3 ,且是15天前的发货订单,判断是否评价
    cursor.execute(
        'select id, user_id,orderType,out_trade_no,realTotal from main_order WHERE status=6 FOR UPDATE '
    )
    orders = cursor.fetchall()  # 得到元组数据, 选择订单id 和 订单的交易号
    if orders:
        for o in orders:
            try:
                # 退款
                # data = {
                #     'out_trade_no': o[3]}
                raw = WxPay().refund_query(out_trade_no=o[3])
                if raw.get("return_code") == 'SUCCESS' and raw.get(
                        'result_code') == 'SUCCESS':
                    cursor.execute(
                        'update main_order set status=7 WHERE status=1 and id=%s',
                        o[0])
                connection.commit()
            except Exception as e:
                connection.rollback()
                print('8return_msg:' + str(e))
예제 #2
0
def check_no_send_collage_order():
    connection = pymysql.connect(
        host='localhost',
        port=3306,
        user='******',
        password='******',
        db='native',
        charset='utf8',
    )
    cursor = connection.cursor()  # 定义一个数据库游标
    t = datetime.datetime.fromtimestamp(time.time() - 259200)  # 查找3天后仍然未拼成团的订单
    # 查找3天后仍然未拼成团的订单,
    cursor.execute(
        'select id, user_id,orderType,out_trade_no,realTotal,collagerId from main_order WHERE status=8 and orderType=1 and collageTime < %s FOR UPDATE ',
        t)
    orders = cursor.fetchall()  # 得到元组数据, 选择订单id 和 订单的交易号
    if orders:
        for o in orders:
            try:
                # 退款
                data = {
                    'out_trade_no': o[3],
                    'total_fee': int(float(o[4]) * 100),
                    'refund_fee': int(float(o[4]) * 100),
                }
                raw = WxPay().refund(c_api_cert_path, c_api_key_path, data)
                if raw.get("return_code") == 'SUCCESS' and raw.get(
                        'result_code') == 'SUCCESS':
                    cursor.execute(
                        'update main_order set status=6 WHERE status=1 and id=%s',
                        o[0])
                    # 回源
                    cursor.execute(
                        'select id,user_id,collageSku_id from main_collageuser WHERE id=%s',
                        o[5])
                    collager = cursor.fetchone()  # 团长
                    if collager[1] == o[1]:  # # 是团长回源
                        cursor.execute(
                            'select id,residualNum,sku_id from main_collagesku WHERE id=%s FOR UPDATE ',
                            collager[2])
                        collageSku = cursor.fetchone()
                        cursor.execute(
                            'update main_collagesku set residualNum=%s WHERE id=%s',
                            [collageSku[1] + 1, collageSku[0]])
                connection.commit()
            except Exception as e:
                connection.rollback()
                print('10return_msg:' + str(e))
예제 #3
0
def check_no_send_order():
    connection = pymysql.connect(
        host='localhost',
        port=3306,
        user='******',
        password='******',
        db='native',
        charset='utf8',
    )
    cursor = connection.cursor()  # 定义一个数据库游标
    t = datetime.datetime.fromtimestamp(time.time() - 259200)  # 查找收货超过3天未发货的订单
    # 查找订单状态为3 ,且是15天前的发货订单,判断是否评价
    cursor.execute(
        'select id, user_id,orderType,out_trade_no,realTotal from main_order WHERE status=1 and orderType=0 and payTime < %s FOR UPDATE ',
        t)
    orders = cursor.fetchall()  # 得到元组数据, 选择订单id 和 订单的交易号
    if orders:
        for o in orders:
            try:
                # 退款
                data = {
                    'out_trade_no': o[3],
                    'total_fee': int(float(o[4]) * 100),
                    'refund_fee': int(float(o[4]) * 100),
                }
                raw = WxPay().refund(c_api_cert_path, c_api_key_path, data)
                if raw.get("return_code") == 'SUCCESS' and raw.get(
                        'result_code') == 'SUCCESS':
                    cursor.execute(
                        'update main_order set status=6 WHERE status=1 and id=%s',
                        o[0])
                    # 回源
                    cursor.execute(
                        'select id,skuNum,sku_id from main_ordersku WHERE order_id=%s',
                        o[0])
                    orderSkus = cursor.fetchall()
                    for osk in orderSkus:
                        cursor.execute(
                            'select id,residualNum from main_sku WHERE id=%s FOR UPDATE ',
                            osk[2])
                        sku = cursor.fetchone()
                        cursor.execute(
                            'update main_sku set residualNum=%s WHERE id=%s',
                            [sku[1] + osk[1], sku[0]])
                connection.commit()
            except Exception as e:
                connection.rollback()
                print('7return_msg:' + str(e))