Exemplo n.º 1
0
    def handleMerchantOrder(self,
                            user_id,
                            order_id,
                            order_status=2,
                            product_id='',
                            sku_info=''):

        from shopback.trades.service import TradeService

        TradeService.createTrade(user_id, order_id, pcfg.WX_TYPE)

        return self.genTextRespJson(u'您的订单(%s)已收到,我们会尽快将宝贝寄给您。[玫瑰]' % order_id)
Exemplo n.º 2
0
def saveUserIncrementPurchaseOrderTask(seller_id, update_from=None, update_to=None):
    seller = Seller.getSellerByVisitorId(seller_id)
    if not seller.has_fenxiao:
        return

    update_from = format_datetime(update_from)
    update_to = format_datetime(update_to)

    from shopback.trades.service import TradeService, PurchaseOrderService

    has_next = True
    cur_page = 1

    while has_next:
        response_list = apis.taobao_fenxiao_orders_get(tb_user_id=seller_id,
                                                       page_no=cur_page,
                                                       time_type='update_time_type',
                                                       page_size=settings.TAOBAO_PAGE_SIZE / 2,
                                                       start_created=update_from,
                                                       end_created=update_to)

        orders_list = response_list['fenxiao_orders_get_response']
        if orders_list['total_results'] > 0:
            for o in orders_list['purchase_orders']['purchase_order']:

                modified = datetime.datetime.strptime(o['modified'], '%Y-%m-%d %H:%M:%S')

                if TradeService.isValidPubTime(seller_id, o['id'], modified):
                    purchase_order = PurchaseOrderService.savePurchaseOrderByDict(seller_id, o)
                    PurchaseOrderService.createMergeTrade(purchase_order)

        total_nums = orders_list['total_results']
        cur_nums = cur_page * settings.TAOBAO_PAGE_SIZE
        has_next = cur_nums < total_nums
        cur_page += 1
Exemplo n.º 3
0
def saveUserIncrementOrdersTask(user_id, update_from=None, update_to=None):
    s_dt_f = format_datetime(update_from)
    s_dt_t = format_datetime(update_to)

    has_next = True
    cur_page = 1

    from shopback.trades.service import TradeService, OrderService
    while has_next:
        response_list = apis.taobao_trades_sold_increment_get(tb_user_id=user_id,
                                                              page_no=cur_page,
                                                              fields='tid,modified',
                                                              page_size=settings.TAOBAO_PAGE_SIZE,
                                                              use_has_next='true',
                                                              start_modified=s_dt_f,
                                                              end_modified=s_dt_t)
        trade_list = response_list['trades_sold_increment_get_response']

        if trade_list.has_key('trades'):
            for trade in trade_list['trades']['trade']:
                modified = parse_datetime(trade['modified']) if trade.get('modified', None) else None
                if TradeService.isValidPubTime(user_id, trade['tid'], modified):
                    try:
                        trade_dict = OrderService.getTradeFullInfo(user_id, trade['tid'])
                        order_trade = OrderService.saveTradeByDict(user_id, trade_dict)
                        OrderService.createMergeTrade(order_trade)
                    except Exception, exc:
                        logger.error(u'淘宝订单下载失败:%s' % exc.message, exc_info=True)

        has_next = trade_list['has_next']
        cur_page += 1
Exemplo n.º 4
0
def saveUserPurchaseOrderTask(seller_id, update_from=None, update_to=None, status=None):
    seller = Seller.getSellerByVisitorId(seller_id)
    if not seller.has_fenxiao:
        return

    from shopback.trades.service import TradeService, PurchaseOrderService

    try:
        if not (update_from and update_to):
            update_from = datetime.datetime.now() - datetime.timedelta(28, 0, 0)
            update_to = datetime.datetime.now()

        exec_times = (update_to - update_from).days / 7 + 1
        for i in range(0, exec_times):
            dt_f = update_from + datetime.timedelta(i * 7, 0, 0)
            dt_t = update_from + datetime.timedelta((i + 1) * 7, 0, 0)

            has_next = True
            cur_page = 1

            while has_next:

                response_list = apis.taobao_fenxiao_orders_get(tb_user_id=seller_id,
                                                               page_no=cur_page,
                                                               time_type='trade_time_type',
                                                               page_size=settings.TAOBAO_PAGE_SIZE / 2,
                                                               start_created=dt_f,
                                                               end_created=dt_t,
                                                               status=status)

                orders_list = response_list['fenxiao_orders_get_response']
                if orders_list['total_results'] > 0:
                    for o in orders_list['purchase_orders']['purchase_order']:

                        modified = datetime.datetime.strptime(o['modified'], '%Y-%m-%d %H:%M:%S')

                        if TradeService.isValidPubTime(seller_id, o['id'], modified):
                            purchase_order = PurchaseOrderService.savePurchaseOrderByDict(seller_id, o)
                            PurchaseOrderService.createMergeTrade(purchase_order)

                total_nums = orders_list['total_results']
                cur_nums = cur_page * settings.TAOBAO_PAGE_SIZE
                has_next = cur_nums < total_nums
                cur_page += 1

    except Exception, exc:
        logger.error(u'分销订单下载失败:%s' % exc.message, exc_info=True)

        raise saveUserPurchaseOrderTask.retry(exc=exc, countdown=60)
Exemplo n.º 5
0
def saveUserDuringOrdersTaskBak(user_id, update_from=None, update_to=None, status=None):
    """ 下载用户商城订单 """
    update_tids = []
    try:
        update_from = format_datetime(update_from) if update_from else None
        update_to = format_datetime(update_to) if update_to else None

        has_next = True
        cur_page = 1

        from shopback.trades.service import TradeService, OrderService
        while has_next:
            response_list = apis.taobao_trades_sold_get(tb_user_id=user_id,
                                                        page_no=cur_page,
                                                        use_has_next='true',
                                                        fields='tid,modified',
                                                        page_size=settings.TAOBAO_PAGE_SIZE,
                                                        start_created=update_from,
                                                        end_created=update_to,
                                                        status=status)

            order_list = response_list['trades_sold_get_response']
            if order_list.has_key('trades'):
                for trade in order_list['trades']['trade']:

                    modified = parse_datetime(trade['modified']) if trade.get('modified', None) else None
                    if TradeService.isValidPubTime(user_id, trade['tid'], modified):
                        try:
                            trade_dict = OrderService.getTradeFullInfo(user_id, trade['tid'])
                            order_trade = OrderService.saveTradeByDict(user_id, trade_dict)
                            OrderService.createMergeTrade(order_trade)
                        except Exception, exc:
                            logger.error(u'淘宝订单下载失败:%s' % exc.message, exc_info=True)

                    update_tids.append(trade['tid'])

            has_next = order_list['has_next']
            cur_page += 1
    except Exception, exc:
        logger.error(u'淘宝订单批量下载错误:%s' % exc.message, exc_info=True)
        raise saveUserDuringOrdersTask.retry(exc=exc, countdown=60)
Exemplo n.º 6
0
    except Exception, exc:
        logger.error(u'淘宝订单批量下载错误:%s' % exc.message, exc_info=True)
        raise saveUserDuringOrdersTask.retry(exc=exc, countdown=60)

    else:
        from shopback.trades.models import MergeTrade
        wait_update_trades = MergeTrade.objects.filter(user__visitor_id=user_id,
                                                       type=pcfg.TAOBAO_TYPE,
                                                       status=pcfg.WAIT_SELLER_SEND_GOODS) \
            .exclude(tid__in=update_tids)
        for trade in wait_update_trades:
            tid = trade.tid
            if tid.find('-') == len(tid) - 2:
                continue
            try:
                TradeService(user_id, trade.tid).payTrade()
            except Exception, exc:
                logger.error(u'更新订单信息异常:%s' % exc, exc_info=True)


@app.task()
def saveUserIncrementOrdersTask(user_id, update_from=None, update_to=None):
    s_dt_f = format_datetime(update_from)
    s_dt_t = format_datetime(update_to)

    has_next = True
    cur_page = 1

    from shopback.trades.service import TradeService, OrderService
    while has_next:
        response_list = apis.taobao_trades_sold_increment_get(tb_user_id=user_id,
Exemplo n.º 7
0
    def handleRefundMessage(self, userId, msgCode, content, msgTime):

        tradeType = content.get('type')
        tradeId = content.get('tid')
        oid = content.get('oid', None)

        if tradeType not in (pcfg.TAOBAO_TYPE, pcfg.FENXIAO_TYPE,
                             pcfg.GUARANTEE_TYPE, pcfg.COD_TYPE,
                             pcfg.TB_STEP_TYPE):
            raise Exception(u'系统不支持该淘宝订单类型:%s' % tradeType)

        if (not TradeService.isTradeExist(userId, tradeId)
                or msgCode == 'TradeAlipayCreate'):

            TradeService.createTrade(userId, tradeId, tradeType)

            if tradeType == pcfg.FENXIAO_TYPE:
                return

            TradeService.updatePublicTime(userId, tradeId, msgTime)
            return

        if not TradeService.isValidPubTime(userId, tradeId, msgTime):
            return

        t_service = TradeService(userId, tradeId)
        if msgCode in ('TradeClose' 'TradeCloseAndModifyDetailOrder'):
            t_service.closeTrade(oid)

        elif msgCode == 'TradeBuyerPay':
            t_service.payTrade()

        elif msgCode == 'TradeSellerShip':
            t_service.shipTrade(oid)

        elif msgCode == 'TradePartlyRefund':
            pass

        elif msgCode == 'TradeSuccess':
            t_service.finishTrade(oid)

        elif msgCode == 'TradeTimeoutRemind':
            t_service.remindTrade()

        elif msgCode == 'TradeMemoModified':
            t_service.memoTrade()

        elif msgCode == 'TradeChanged':
            t_service.changeTrade()

        TradeService.updatePublicTime(userId, tradeId, msgTime)