Esempio n. 1
0
def main_loop():
    redis = common.redis_client()
    db = common.db_client()
    logging.info('----- express consumer starts -----')

    while common.running():
        #淘宝订单发货信息
        message_raw = redis.brpoplpush(options.queue_taobao_express,
                                       options.queue_taobao_express_processing)
        task = json.loads(message_raw, object_hook=json_hook)
        if task.tid:
            shop = db.get(
                'select distributor_shop_id from distributor_order where order_no = %s limit 1',
                task.tid)
            if shop and shop.distributor_shop_id == options.shop_id_taobao:
                #淘宝自动发货
                express_auto_push(db, redis, message_raw,
                                  options.shop_id_taobao)
            elif shop and shop.distributor_shop_id == options.shop_id_tmall:
                #天猫自动发货
                express_auto_push(db, redis, message_raw,
                                  options.shop_id_tmall)
            else:
                logging.info(
                    "can't find order in taobao and tmall. order_no = %s",
                    task.tid)

    logging.info('----- express consumer shut down -----')
Esempio n. 2
0
def main_loop():
    db = common.db_client()

    real_ids = db.query('select oi.id, oi.buy_number, oi.return_count, oi.sale_price from reeb.order_items oi, '
                        'reeb.goods g where oi.goods_id=g.id and '
                        'g.material_type ="REAL" and oi.status != "CANCELED" and oi.status != "UNPAID"')
    num = 0
    for t in real_ids:
        last_row_id = None
        # 插入实物 item
        for i in range(t.buy_number):
            last_row_id = db.execute("""insert into item(status, goods_name, goods_id, distr_id, distr_shop_id, sp_id, sp_shop_id, sales_id, order_item_id, order_id, order_no, face_value, payment, discount, sales_price, purchase_price, refund_value,cheat_value,
            created_at, used_at, refund_at, cheat_at)
            select case oi.status when 'PAID' then 1 when 'SENT' then 2 when 'RETURNED' then 3 when 'PREPARED' then 4 when 'UPLOADED' then 5 when 'RETURNING' then 7 end,
            oi.goods_name, oi.goods_id, case when o.user_id in (13,31,33,34,39,48,49,50,51) then 13 else o.user_id end , o.user_id, g.supplier_id, NULL, s.sales_id, oi.id, oi.order_id, o.order_no, oi.face_value, oi.sale_price, 0,
            oi.sale_price, oi.original_price, 0.00, 0.00, oi.created_at, oi.send_at, NULL, NULL
            from reeb.order_items oi, reeb.goods g, reeb.orders o, reeb.suppliers s where oi.goods_id=g.id and oi.order_id = o.id and g.supplier_id=s.id and oi.id=%s;
            """, t.id)
            num += 1
        # 根据real_goods_return_entry 更新退款
        return_entry = db.query("""select * from reeb.real_goods_return_entry where order_item_id=%s""", t.id)
        if return_entry:
            refund = return_entry[0]
            if refund.partial_refund_price:
                db.execute("""update item i set i.refund_value=%s, i.refund_at=%s where i.id=%s""", refund.partial_refund_price, refund.created_at, last_row_id)
            else:
                for j in range(refund.returned_count):
                    db.execute("""update item i set i.refund_value=%s, i.refund_at=%s where i.id=%s""", t.sale_price, refund.created_at, last_row_id)
                    last_row_id -= 1

    print '插入条数:', num
Esempio n. 3
0
def main_loop():
    db = common.db_client()

    real_ids = db.query(
        'select oi.id, oi.buy_number, oi.return_count, oi.sale_price from reeb.order_items oi, '
        'reeb.goods g where oi.goods_id=g.id and '
        'g.material_type ="REAL" and oi.status != "CANCELED" and oi.status != "UNPAID"'
    )
    num = 0
    for t in real_ids:
        last_row_id = None
        # 插入实物 item
        for i in range(t.buy_number):
            last_row_id = db.execute(
                """insert into item(status, goods_name, goods_id, distr_id, distr_shop_id, sp_id, sp_shop_id, sales_id, order_item_id, order_id, order_no, face_value, payment, discount, sales_price, purchase_price, refund_value,cheat_value,
            created_at, used_at, refund_at, cheat_at)
            select case oi.status when 'PAID' then 1 when 'SENT' then 2 when 'RETURNED' then 3 when 'PREPARED' then 4 when 'UPLOADED' then 5 when 'RETURNING' then 7 end,
            oi.goods_name, oi.goods_id, case when o.user_id in (13,31,33,34,39,48,49,50,51) then 13 else o.user_id end , o.user_id, g.supplier_id, NULL, s.sales_id, oi.id, oi.order_id, o.order_no, oi.face_value, oi.sale_price, 0,
            oi.sale_price, oi.original_price, 0.00, 0.00, oi.created_at, oi.send_at, NULL, NULL
            from reeb.order_items oi, reeb.goods g, reeb.orders o, reeb.suppliers s where oi.goods_id=g.id and oi.order_id = o.id and g.supplier_id=s.id and oi.id=%s;
            """, t.id)
            num += 1
        # 根据real_goods_return_entry 更新退款
        return_entry = db.query(
            """select * from reeb.real_goods_return_entry where order_item_id=%s""",
            t.id)
        if return_entry:
            refund = return_entry[0]
            if refund.partial_refund_price:
                db.execute(
                    """update item i set i.refund_value=%s, i.refund_at=%s where i.id=%s""",
                    refund.partial_refund_price, refund.created_at,
                    last_row_id)
            else:
                for j in range(refund.returned_count):
                    db.execute(
                        """update item i set i.refund_value=%s, i.refund_at=%s where i.id=%s""",
                        t.sale_price, refund.created_at, last_row_id)
                    last_row_id -= 1

    print '插入条数:', num
Esempio n. 4
0
def main_loop():
    redis = common.redis_client()
    db = common.db_client()
    logging.info('----- distributor order consumer starts -----')

    while common.running():

        # 移动一个订单到处理队列
        message_raw = redis.brpoplpush(options.queue_distributor_order, options.queue_distributor_order_processing)
        task = json.loads(message_raw, object_hook=json_hook)
        logging.info('distributor order consumer pop %s distributor order, id=%s '
                     % (task.distributor, task.distributor_order_id))

        # 淘宝订单
        if task.distributor == 'TB':
            taobao_order(db, redis, task.distributor_order_id, message_raw)
        # 一号店订单
        elif task.distributor == 'YHD':
            yihaodian_order(db, redis, task.distributor_order_id, message_raw)

    logging.info('----- distributor order consumer shut down -----')
Esempio n. 5
0
def main_loop():
    redis = common.redis_client()
    db = common.db_client()
    logging.info('----- distributor order consumer starts -----')

    while common.running():

        # 移动一个订单到处理队列
        message_raw = redis.brpoplpush(
            options.queue_distributor_order,
            options.queue_distributor_order_processing)
        task = json.loads(message_raw, object_hook=json_hook)
        logging.info(
            'distributor order consumer pop %s distributor order, id=%s ' %
            (task.distributor, task.distributor_order_id))

        # 淘宝订单
        if task.distributor == 'TB':
            taobao_order(db, redis, task.distributor_order_id, message_raw)
        # 一号店订单
        elif task.distributor == 'YHD':
            yihaodian_order(db, redis, task.distributor_order_id, message_raw)

    logging.info('----- distributor order consumer shut down -----')
Esempio n. 6
0
# -*- coding: utf-8 -*-

import common
import logging
import json
from datetime import datetime, timedelta
from autumn.utils import json_hook
from tornado.options import options
from autumn.coupon import local_verify
"""美团、点评、糯米的券在一百券上验证处理"""

common.set_up()

db = common.db_client()
redis = common.redis_client()

while common.running():
    coupon = redis.brpoplpush(options.queue_coupon_local_verify,
                              options.queue_coupon_local_verify_processing)
    task = json.loads(coupon, object_hook=json_hook)
    logging.info('local coupon verify pop %s ,shop_id:%s ' %
                 (task.coupon, task.shop_id))

    #开始对外部券进行本地验证
    verify_result = local_verify(db,
                                 task.coupon,
                                 task.shop_id,
                                 '系统',
                                 verified_at=task.used_at)

    ok, msg = (verify_result.ok, verify_result.msg)
Esempio n. 7
0
def main_loop():
    redis = common.redis_client()
    db = common.db_client()
    args = {'db': db, 'body': ''}

    while common.running():
        sp_id = redis.brpop('q:wx:mem:update')[1]

        args['sp_id'] = sp_id
        app_id = db.get(
            'select * from supplier_property where name="app_id" and sp_id = %s',
            sp_id)['value']
        app_secret = db.get(
            'select * from supplier_property where name="app_secret" and sp_id = %s',
            sp_id)['value']

        wx = Weixin(method='user/get', **args)
        wx.set_app_info(app_id, app_secret)

        info = Weixin(method='user/info', **args)
        info.set_app_info(app_id, app_secret)

        next_openid = ''
        while True:
            result = yield wx(next_openid=next_openid)
            wx.parse_response(result.body)

            if wx.is_ok() and 'data' in wx.message.keys():
                count = wx.message.count
                total = wx.message.total
                customs = wx.message.data.openid
                for custom in customs:
                    response = yield info(openid=custom, lang='zh_CN')
                    info.parse_response(response.body)
                    if info.is_ok():
                        nickname = info.message.nickname

                        # 暂时数据库未升级至可以存储emoji字符,故使用以下代码,升级数据库后可删除
                        import re
                        try:
                            # UCS-4
                            highpoints = re.compile(u'[\U00010000-\U0010ffff]')
                        except re.error:
                            # UCS-2
                            highpoints = re.compile(
                                u'[\uD800-\uDBFF][\uDC00-\uDFFF]')
                        nickname = highpoints.sub(u'', nickname)
                        # todo =========================未升级前的替代方案===================

                        sex = {0: '未知', 1: '男', 2: '女'}.get(info.message.sex)
                        follow_at = datetime.fromtimestamp(
                            info.message.subscribe_time)
                        openid = info.message.openid
                        head_img = info.message.headimgurl

                        mid = db.query(
                            'select * from member where wx_id = %s and sp_id = %s',
                            custom, sp_id)

                        if mid:
                            db.execute(
                                'update member set wx_name = %s, gender = %s,'
                                'head_img = %s, wx_follow_at = %s, country = %s, province = %s, city = %s '
                                'where wx_id = %s and sp_id = %s', nickname,
                                sex, head_img, follow_at, info.message.country,
                                info.message.province, info.message.city,
                                custom, sp_id)
                        else:
                            cid = db.query(
                                'select * from member_category where sp_id = %s and name = "未分组" ',
                                sp_id)[0].id
                            db.execute(
                                'insert into member set sp_id = %s, wx_id = %s, wx_name = %s, gender = %s,'
                                'head_img = %s, wx_follow_at = %s, created_at = NOW(),'
                                'category_id = %s, country = %s, province = %s, city = %s, '
                                'source = "微信导入"', sp_id, openid, nickname,
                                sex, head_img, follow_at, cid,
                                info.message.country, info.message.province,
                                info.message.city)
                        logging.info('会员 %s 更新信息成功', custom.encode('utf-8'))
                    else:
                        logging.error('获取 %s 信息失败。失败原因 %s',
                                      custom.encode('utf-8'),
                                      error_list.get(info.error_code, ''))

                if count < 10000 or count == total:
                    break
                else:
                    next_openid = wx.message.next_openid
            else:
                logging.error('获取关注者失败.商户 %s, 错误原因 %s', sp_id,
                              error_list.get(wx.error_code, ''))
                break
Esempio n. 8
0
def main_loop():
    redis = common.redis_client()
    db = common.db_client()
    args = {
        'db': db,
        'body': ''
    }

    while common.running():
        sp_id = redis.brpop('q:wx:mem:update')[1]

        args['sp_id'] = sp_id
        app_id = db.get('select * from supplier_property where name="app_id" and sp_id = %s', sp_id)['value']
        app_secret = db.get('select * from supplier_property where name="app_secret" and sp_id = %s', sp_id)['value']

        wx = Weixin(method='user/get', **args)
        wx.set_app_info(app_id, app_secret)

        info = Weixin(method='user/info', **args)
        info.set_app_info(app_id, app_secret)

        next_openid = ''
        while True:
            result = yield wx(next_openid=next_openid)
            wx.parse_response(result.body)

            if wx.is_ok() and 'data' in wx.message.keys():
                count = wx.message.count
                total = wx.message.total
                customs = wx.message.data.openid
                for custom in customs:
                    response = yield info(openid=custom, lang='zh_CN')
                    info.parse_response(response.body)
                    if info.is_ok():
                        nickname = info.message.nickname

                        # 暂时数据库未升级至可以存储emoji字符,故使用以下代码,升级数据库后可删除
                        import re
                        try:
                            # UCS-4
                            highpoints = re.compile(u'[\U00010000-\U0010ffff]')
                        except re.error:
                            # UCS-2
                            highpoints = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]')
                        nickname = highpoints.sub(u'', nickname)
                        # todo =========================未升级前的替代方案===================

                        sex = {0: '未知', 1: '男', 2: '女'}.get(info.message.sex)
                        follow_at = datetime.fromtimestamp(info.message.subscribe_time)
                        openid = info.message.openid
                        head_img = info.message.headimgurl

                        mid = db.query('select * from member where wx_id = %s and sp_id = %s',
                                       custom, sp_id)

                        if mid:
                            db.execute('update member set wx_name = %s, gender = %s,'
                                       'head_img = %s, wx_follow_at = %s, country = %s, province = %s, city = %s '
                                       'where wx_id = %s and sp_id = %s',
                                       nickname, sex, head_img, follow_at, info.message.country,
                                       info.message.province, info.message.city,
                                       custom, sp_id)
                        else:
                            cid = db.query('select * from member_category where sp_id = %s and name = "未分组" ',
                                           sp_id)[0].id
                            db.execute('insert into member set sp_id = %s, wx_id = %s, wx_name = %s, gender = %s,'
                                       'head_img = %s, wx_follow_at = %s, created_at = NOW(),'
                                       'category_id = %s, country = %s, province = %s, city = %s, '
                                       'source = "微信导入"',
                                       sp_id, openid, nickname, sex, head_img, follow_at, cid, info.message.country,
                                       info.message.province, info.message.city)
                        logging.info('会员 %s 更新信息成功', custom.encode('utf-8'))
                    else:
                        logging.error('获取 %s 信息失败。失败原因 %s', custom.encode('utf-8'), error_list.get(info.error_code, ''))

                if count < 10000 or count == total:
                    break
                else:
                    next_openid = wx.message.next_openid
            else:
                logging.error('获取关注者失败.商户 %s, 错误原因 %s', sp_id, error_list.get(wx.error_code, ''))
                break
# -*- coding: utf-8 -*-

import common
import logging
import json
from datetime import datetime, timedelta
from autumn.utils import json_hook
from tornado.options import options
from autumn.coupon import local_verify

"""美团、点评、糯米的券在一百券上验证处理"""

common.set_up()

db = common.db_client()
redis = common.redis_client()

while common.running():
    coupon = redis.brpoplpush(options.queue_coupon_local_verify, options.queue_coupon_local_verify_processing)
    task = json.loads(coupon, object_hook=json_hook)
    logging.info('local coupon verify pop %s ,shop_id:%s ' % (task.coupon, task.shop_id))

    #开始对外部券进行本地验证
    verify_result = local_verify(db, task.coupon, task.shop_id, '系统', verified_at=task.used_at)

    ok, msg = (verify_result.ok, verify_result.msg)
    if ok:
        # 外部券验证处理完成,从处理队列移除
        redis.lrem(options.queue_coupon_local_verify_processing, 0, coupon)
        logging.info('local coupon verify finish,coupon_sn:%s' % task.coupon)
    else: