コード例 #1
0
def split_merge_trade(merger_order_id, modify_user):
    """
        批量拆单功能实现
        参数为order_id 以逗号拼接的字串
    """
    from shopback.trades.handlers import trade_handler
    order_list = merger_order_id.split(",")
    len_of_chai = len(order_list)
    if len(order_list) == 0:
        return u"error"

    m = MergeOrder.objects.filter(Q(id=order_list[0], sys_status=IN_EFFECT))
    if m.count() == 0:
        return u"有无效的订单"
    m_trade = MergeOrder.objects.filter(merge_trade=m[0].merge_trade,
                                        sys_status=IN_EFFECT)
    if m_trade.count() == len_of_chai:
        return u"至少留一个有效的订单"
    parent_trade = m[0].merge_trade
    if parent_trade.has_merge and parent_trade.sys_status != pcfg.WAIT_CHECK_BARCODE_STATUS:
        return u"有合单"
    parent_trade_tid = parent_trade.tid.split("-")[0]
    first_p = Product.objects.filter(outer_id=m[0].outer_id)
    if first_p.count() == 0:
        return u"未发现商品"
    payment = 0
    for order_id in order_list:
        m = MergeOrder.objects.filter(Q(id=order_id, sys_status=IN_EFFECT))
        if m.count() == 0:
            return u"没有有效的订单"
        if parent_trade.id != m[0].merge_trade.id:
            return u"不在一个父订单"

        p = Product.objects.filter(outer_id=m[0].outer_id)
        if p.count() == 0:
            return u"未发现商品"
        if first_p[0].ware_by != p[0].ware_by:
            return u"不在一个仓库"
        payment += m[0].payment

    count = 1
    while True:
        temp_merge = MergeTrade.objects.filter(
            Q(tid=parent_trade_tid + "-" + str(count)))
        if temp_merge.count() == 0:
            break
        count += 1

    parent_trade_dict = parent_trade.__dict__
    new_trade = MergeTrade(tid=parent_trade_tid + "-" + str(count),
                           user=parent_trade.user)
    # 复制原来的订单的信息
    for k, v in parent_trade_dict.items():
        if not (k == u"tid" or k == u"id"):
            if k == u"payment":
                new_trade.payment = payment
            elif k == u"ware_by":
                new_trade.ware_by = p[0].ware_by
            else:
                hasattr(new_trade, k) and setattr(new_trade, k, v)
    new_trade.is_part_consign = True
    new_trade.is_part_consign = True
    new_trade.buyer_message = parent_trade.buyer_message
    new_trade.seller_memo = parent_trade.seller_memo
    new_trade.sys_memo = parent_trade.sys_memo
    new_trade.save()

    log_action(modify_user.id, new_trade, ADDITION,
               u'从订单{0}拆过来'.format(parent_trade.id))
    # 将新的order合入新的订单
    for order_id in order_list:
        mergeorder = MergeOrder.objects.get(id=order_id, sys_status=IN_EFFECT)
        mergeorder_dict = mergeorder.__dict__

        new_order = MergeOrder()
        for k1, v1 in mergeorder_dict.items():
            if not k1 == u"id":
                if k1 == u'merge_trade_id':
                    new_order.merge_trade_id = new_trade.id
                else:
                    hasattr(new_order, k1) and setattr(new_order, k1, v1)
        new_order.save()

        mergeorder.sys_status = INVALID_STATUS
        mergeorder.save()
        log_action(modify_user.id, mergeorder, CHANGE, u'被拆单')
    parent_trade.sys_memo += u"拆单到{0}".format(new_trade.id)
    parent_trade.is_part_consign = True
    parent_trade.save()

    trade_handler.proccess(parent_trade, **{"update_logistic": True})
    trade_handler.proccess(new_trade, **{"update_logistic": True})
    log_action(modify_user.id, parent_trade, CHANGE,
               u'拆到订单{0}'.format(new_trade.id))
    return "OK"
コード例 #2
0
    def createMergeTrade(cls, trade, *args, **kwargs):

        tid = trade.id
        merge_trade, state = MergeTrade.objects.get_or_create(
            user=trade.user, tid=tid, type=pcfg.FENXIAO_TYPE)

        update_fields = [
            'buyer_nick', 'payment', 'shipping_type', 'total_fee', 'post_fee',
            'created', 'trade_from', 'pay_time', 'modified', 'consign_time',
            'seller_flag', 'priority', 'status'
        ]

        if not merge_trade.receiver_name and \
                        trade.status not in ('',
                                             pcfg.TRADE_NO_CREATE_PAY,
                                             pcfg.WAIT_BUYER_PAY,
                                             pcfg.TRADE_CLOSED,
                                             pcfg.TRADE_CLOSED_BY_TAOBAO):
            logistics = Logistics.get_or_create(trade.user.visitor_id, tid)
            location = json.loads(logistics.location or 'null')

            merge_trade.receiver_name = logistics.receiver_name
            merge_trade.receiver_zip = location.get('zip',
                                                    '') if location else ''
            merge_trade.receiver_mobile = logistics.receiver_mobile
            merge_trade.receiver_phone = logistics.receiver_phone

            merge_trade.receiver_state = location.get('state',
                                                      '') if location else ''
            merge_trade.receiver_city = location.get('city',
                                                     '') if location else ''
            merge_trade.receiver_district = location.get(
                'district', '') if location else ''
            merge_trade.receiver_address = location.get('address',
                                                        '') if location else ''

            address_fields = [
                'receiver_name', 'receiver_state', 'receiver_city',
                'receiver_district', 'receiver_address', 'receiver_zip',
                'receiver_mobile', 'receiver_phone'
            ]

            update_fields.extend(address_fields)

        merge_trade.payment = merge_trade.payment or trade.distributor_payment
        merge_trade.total_fee = merge_trade.total_fee or trade.total_fee
        merge_trade.post_fee = merge_trade.post_fee or trade.post_fee

        merge_trade.buyer_nick = trade.distributor_username
        merge_trade.shipping_type = merge_trade.shipping_type or \
                                    pcfg.SHIPPING_TYPE_MAP.get(trade.shipping, pcfg.EXPRESS_SHIPPING_TYPE)
        merge_trade.created = trade.created
        merge_trade.pay_time = trade.created
        merge_trade.modified = trade.modified
        merge_trade.consign_time = trade.consign_time
        merge_trade.seller_flag = trade.supplier_flag
        merge_trade.priority = 0
        merge_trade.status = trade.status
        merge_trade.trade_from = MergeTrade.objects.mapTradeFromToCode(
            pcfg.TF_TAOBAO)

        update_model_fields(merge_trade, update_fields=update_fields)

        # 保存分销订单到抽象全局抽象订单表
        for order in trade.sub_purchase_orders.all():
            cls.createMergeOrder(merge_trade, order)

        trade_handler.proccess(
            merge_trade, **{
                'origin_trade':
                trade,
                'first_pay_load':
                (merge_trade.sys_status == pcfg.EMPTY_STATUS
                 and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS)
            })

        return merge_trade
コード例 #3
0
ファイル: services.py プロジェクト: xiaolusys/xiaolusys
    def createMergeTrade(cls, trade, *args, **kwargs):
        return
        from shopback.trades.handlers import trade_handler
        from shopback.trades.models import MergeTrade

        seller = cls.getOrCreateSeller(trade)
        merge_trade, state = MergeTrade.objects.get_or_create(tid=trade.tid,
                                                              user=seller)

        update_fields = [
            'buyer_nick', 'created', 'pay_time', 'modified', 'status',
            'buyer_message'
        ]

        merge_trade.buyer_nick = trade.buyer_nick.strip(
        ) or trade.receiver_mobile

        merge_trade.buyer_message = trade.buyer_message

        merge_trade.created = trade.created
        merge_trade.modified = trade.modified
        merge_trade.pay_time = trade.pay_time
        merge_trade.status = SaleTrade.mapTradeStatus(trade.status)

        update_address = False
        if not merge_trade.receiver_name and trade.receiver_name:
            update_address = True
            address_fields = [
                'receiver_name', 'receiver_state', 'receiver_city',
                'receiver_address', 'receiver_district', 'receiver_mobile',
                'receiver_phone'
            ]

            for k in address_fields:
                setattr(merge_trade, k, getattr(trade, k))

            update_fields.extend(address_fields)

        merge_trade.payment = merge_trade.payment or float(trade.payment)
        merge_trade.total_fee = merge_trade.total_fee or float(trade.total_fee)
        merge_trade.post_fee = merge_trade.post_fee or float(trade.post_fee)

        merge_trade.trade_from = 0
        merge_trade.shipping_type = pcfg.EXPRESS_SHIPPING_TYPE
        merge_trade.type = pcfg.SALE_TYPE

        update_model_fields(merge_trade,
                            update_fields=update_fields + [
                                'shipping_type', 'type', 'payment',
                                'total_fee', 'post_fee', 'trade_from'
                            ])

        for order in trade.sale_orders.all():
            cls.createMergeOrder(merge_trade, order)

        trade_handler.proccess(
            merge_trade, **{
                'origin_trade':
                trade,
                'update_address':
                (update_address
                 and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS),
                'first_pay_load':
                (merge_trade.sys_status == pcfg.EMPTY_STATUS
                 and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS)
            })

        return merge_trade
コード例 #4
0
    def createMergeTrade(cls, trade, *args, **kwargs):

        tid = trade.id
        update_address = False
        merge_trade, state = MergeTrade.objects.get_or_create(
            user=trade.user, tid=tid, type=pcfg.TAOBAO_TYPE)

        update_fields = [
            'buyer_nick', 'is_force_wlb', 'seller_cod_fee', 'buyer_cod_fee',
            'cod_fee', 'cod_status', 'seller_flag', 'created', 'pay_time',
            'modified', 'consign_time', 'send_time', 'status', 'is_brand_sale',
            'is_lgtype', 'lg_aging', 'lg_aging_type', 'buyer_rate',
            'seller_rate', 'seller_can_rate', 'is_part_consign',
            'step_paid_fee', 'step_trade_status'
        ]

        if not merge_trade.receiver_name and trade.receiver_name:
            update_address = True
            address_fields = [
                'receiver_name', 'receiver_state', 'receiver_city',
                'receiver_district', 'receiver_address', 'receiver_zip',
                'receiver_mobile', 'receiver_phone'
            ]

            update_fields.extend(address_fields)

        for k in update_fields:
            setattr(merge_trade, k, getattr(trade, k))

        merge_trade.is_cod = trade.type == pcfg.COD_TYPE
        merge_trade.payment = merge_trade.payment or trade.payment
        merge_trade.total_fee = merge_trade.total_fee or trade.total_fee
        merge_trade.discount_fee = merge_trade.discount_fee or trade.discount_fee
        merge_trade.adjust_fee = merge_trade.adjust_fee or trade.adjust_fee
        merge_trade.post_fee = merge_trade.post_fee or trade.post_fee

        merge_trade.trade_from = MergeTrade.objects.mapTradeFromToCode(
            trade.trade_from)
        merge_trade.shipping_type = (merge_trade.shipping_type
                                     or pcfg.SHIPPING_TYPE_MAP.get(
                                         trade.shipping_type,
                                         pcfg.EXPRESS_SHIPPING_TYPE))

        update_model_fields(
            merge_trade,
            update_fields=update_fields + [
                'is_cod', 'shipping_type', 'payment', 'total_fee',
                'discount_fee', 'adjust_fee', 'post_fee', 'trade_from'
            ])

        for order in trade.trade_orders.all():
            cls.createMergeOrder(merge_trade, order)

        trade_handler.proccess(
            merge_trade, **{
                'origin_trade':
                trade,
                'update_address':
                (update_address
                 and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS),
                'first_pay_load':
                (merge_trade.sys_status == pcfg.EMPTY_STATUS
                 and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS)
            })

        return merge_trade
コード例 #5
0
ファイル: service.py プロジェクト: xiaolusys/xiaolusys
    def createMergeTrade(cls, trade, *args, **kwargs):

        from shopback.trades.handlers import trade_handler
        from shopback.trades.models import MergeTrade
        from shopback.users.models import User

        seller = User.getOrCreateSeller(trade.shop.vender_id, seller_type=User.SHOP_TYPE_JD)
        merge_trade, state = MergeTrade.objects.get_or_create(tid=trade.order_id,
                                                              user=seller)

        update_fields = ['buyer_nick', 'created', 'pay_time', 'modified', 'status']

        merge_trade.buyer_nick = trade.pin

        merge_trade.created = trade.order_start_time
        merge_trade.modified = trade.modified
        merge_trade.pay_time = trade.payment_confirm_time
        merge_trade.status = JDOrder.mapTradeStatus(trade.order_state)

        update_address = False
        if not merge_trade.receiver_name and trade.consignee_info:
            update_address = True
            receiver_info = json.loads(trade.consignee_info)
            merge_trade.receiver_name = receiver_info['fullname']
            merge_trade.receiver_state = receiver_info['province']
            merge_trade.receiver_city = receiver_info['city']
            merge_trade.receiver_district = receiver_info['county']
            merge_trade.receiver_address = receiver_info['full_address']
            merge_trade.receiver_mobile = receiver_info['mobile']
            merge_trade.receiver_phone = receiver_info['telephone']

            address_fields = ['receiver_name', 'receiver_state',
                              'receiver_city', 'receiver_address',
                              'receiver_district', 'receiver_mobile',
                              'receiver_phone']

            update_fields.extend(address_fields)

        merge_trade.payment = merge_trade.payment or float(trade.order_payment)
        merge_trade.total_fee = merge_trade.total_fee or float(trade.order_total_price)
        merge_trade.post_fee = merge_trade.post_fee or float(trade.freight_price)

        merge_trade.trade_from = 0
        merge_trade.shipping_type = pcfg.EXPRESS_SHIPPING_TYPE
        merge_trade.type = pcfg.JD_TYPE

        update_model_fields(merge_trade, update_fields=update_fields
                                                       + ['shipping_type', 'type', 'payment',
                                                          'total_fee', 'post_fee', 'trade_from'])

        if trade.item_info_list:
            item_list = json.loads(trade.item_info_list)
            for item in item_list:
                cls.createMergeOrder(merge_trade, item)

        trade_handler.proccess(merge_trade,
                               **{'origin_trade': trade,
                                  'update_address': (update_address and
                                                     merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS),
                                  'first_pay_load': (
                                      merge_trade.sys_status == pcfg.EMPTY_STATUS and
                                      merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS)})

        return merge_trade
コード例 #6
0
ファイル: service.py プロジェクト: xiaolusys/xiaolusys
    def createMergeTrade(cls, trade, *args, **kwargs):

        user = cls.getOrCreateSeller(trade)
        merge_trade, state = MergeTrade.objects.get_or_create(
            user=user, tid=trade.order_id)

        update_fields = [
            'buyer_nick', 'created', 'pay_time', 'modified', 'status'
        ]

        merge_trade.buyer_nick = trade.buyer_nick or trade.receiver_name
        merge_trade.created = trade.order_create_time
        merge_trade.modified = trade.order_create_time
        merge_trade.pay_time = trade.order_create_time
        merge_trade.status = WXOrder.mapTradeStatus(trade.order_status)

        update_address = False
        if not merge_trade.receiver_name and trade.receiver_name:
            update_address = True
            merge_trade.receiver_name = trade.receiver_name
            merge_trade.receiver_state = trade.receiver_province
            merge_trade.receiver_city = trade.receiver_city
            merge_trade.receiver_district = trade.receiver_zone
            merge_trade.receiver_address = trade.receiver_address
            merge_trade.receiver_mobile = trade.receiver_mobile
            merge_trade.receiver_phone = trade.receiver_phone

            address_fields = [
                'receiver_name', 'receiver_state', 'receiver_district',
                'receiver_city', 'receiver_address', 'receiver_mobile',
                'receiver_phone'
            ]

            update_fields.extend(address_fields)

        merge_trade.payment = (merge_trade.payment
                               or round(trade.order_total_price / 100.0, 2))
        merge_trade.total_fee = (merge_trade.total_fee
                                 or round(trade.product_price / 100.0, 2) *
                                 trade.product_count)
        merge_trade.post_fee = (merge_trade.post_fee
                                or round(trade.order_express_price / 100.0, 2))

        merge_trade.trade_from = MergeTrade.trade_from
        merge_trade.shipping_type = pcfg.EXPRESS_SHIPPING_TYPE
        merge_trade.type = pcfg.WX_TYPE

        update_model_fields(merge_trade,
                            update_fields=update_fields + [
                                'shipping_type', 'type', 'payment',
                                'total_fee', 'post_fee', 'trade_from'
                            ])

        cls.createMergeOrder(merge_trade, trade)

        _params = {
            'origin_trade':
            trade,
            'update_address':
            (update_address
             and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS),
            'first_pay_load':
            (merge_trade.sys_status == pcfg.EMPTY_STATUS
             and merge_trade.status == pcfg.WAIT_SELLER_SEND_GOODS)
        }
        _params.update(kwargs)

        if _params.get('first_pay_load'):
            trade.confirm_payment()

        trade_handler.proccess(merge_trade, *args, **_params)

        return merge_trade