Example #1
0
 def post(self):
     arg = lambda k: self.get_argument(k).encode('utf-8')
     yihaodian = Yihaodian('yhd.product.update')
     response = yield yihaodian(
         outerId=arg('goods_link_id'),
         productCname=arg('productCname'),
         productSubTitle=arg('productSubTitle'),
         productNamePrefix=arg('productNamePrefix'),
         productDescription=arg('productDescription'))
     yihaodian.parse_response(response.body)
     if yihaodian.is_ok():
         self.render(
             'goods/distributor/yihaodian/result.html',
             ok=True,
             title="编辑成功",
             explain='<a href="/goods/distributor?shop=yhd">继续编辑其他一号店商品</a>'
         )
     else:
         self.render('goods/distributor/yihaodian/result.html',
                     ok=False,
                     title="编辑出错",
                     explain='<br/>'.join([
                         error.findtext('errorCode') + ':' +
                         error.findtext('errorDes')
                         for error in yihaodian.message.findall(
                             './errInfoList/errDetailInfo')
                     ]))
Example #2
0
    def post(self):
        arg = lambda k: self.get_argument(k).encode('utf-8')

        attr_items = []  # 带选项的属性
        attr_texts = []  # 需要输入的属性
        for name in self.request.arguments:
            if name.startswith('attr_item_'):
                attr_items.append('%s:%s' % (name[10:], '|'.join(
                    self.get_arguments(name)).encode('utf-8')))
            elif name.startswith('attr_text_'):
                attr_texts.append('%s:%s' % (name[10:], arg(name)))

        goods_id = self.get_argument('goods_id')
        dg = alloc_distributor_goods(self.db, goods_id,
                                     options.shop_id_yihaodian)

        yihaodian = Yihaodian('yhd.product.add')
        response = yield yihaodian(
            outerId=dg.goods_link_id,
            prodAttributeInfoList=','.join(attr_texts),
            prodAttributeItemInfoList=','.join(attr_items),
            productType=arg('productType'),
            categoryId=arg('categoryId'),
            merchantCategoryId=arg('merchantCategoryId'),
            productCname=arg('productCname'),
            productSubTitle=arg('productSubTitle'),
            virtualStockNum=arg('virtualStockNum'),
            productNamePrefix=arg('productNamePrefix'),
            brandId=arg('brandId'),
            productMarketPrice=arg('productMarketPrice'),
            weight=arg('weight'),
            productSalePrice=arg('productSalePrice'),
            canSale=arg('canSale'),
            productDescription=arg('productDescription'),
            electronicCerticate=arg('electronicCerticate'))
        yihaodian.parse_response(response.body)
        if not yihaodian.is_ok():
            self.render('goods/distributor/yihaodian/result.html',
                        ok=False,
                        title="上传出错",
                        explain='<br/>'.join([
                            error.findtext('errorCode') + ':' +
                            error.findtext('errorDes')
                            for error in yihaodian.message.findall(
                                './errInfoList/errDetailInfo')
                        ]))
        else:
            self.db.execute(
                'update goods_distributor_shop set status="PENDING", created_by=%s, created_at=NOW() '
                'where goods_id=%s and distributor_shop_id=%s and goods_link_id=%s',
                self.current_user.name, goods_id, options.shop_id_yihaodian,
                dg.goods_link_id)
            self.render('goods/distributor/yihaodian/upload_img.html',
                        error=None,
                        goods_link_id=dg.goods_link_id)
Example #3
0
 def post(self):
     arg = lambda k: self.get_argument(k).encode('utf-8')
     yihaodian = Yihaodian('yhd.product.update')
     response = yield yihaodian(outerId=arg('goods_link_id'),
                                productCname=arg('productCname'),
                                productSubTitle=arg('productSubTitle'),
                                productNamePrefix=arg('productNamePrefix'),
                                productDescription=arg('productDescription'))
     yihaodian.parse_response(response.body)
     if yihaodian.is_ok():
         self.render('goods/distributor/yihaodian/result.html', ok=True, title="编辑成功",
                     explain='<a href="/goods/distributor?shop=yhd">继续编辑其他一号店商品</a>')
     else:
         self.render('goods/distributor/yihaodian/result.html', ok=False, title="编辑出错",
                     explain='<br/>'.join([error.findtext('errorCode')+':'+error.findtext('errorDes')
                                           for error in yihaodian.message.findall('./errInfoList/errDetailInfo')]))
Example #4
0
 def post(self):
     goods_link_id = self.get_argument('goods_link_id').encode('utf-8')
     if (not self.request.files) or (not 'img_file' in self.request.files):
         self.render('goods/distributor/yihaodian/upload_img.html',
                     error='请选择文件',
                     goods_link_id=goods_link_id)
     else:
         img_file = self.request.files['img_file'][0]
         yihaodian = Yihaodian('yhd.product.img.upload')
         yihaodian.add_file('img_file', img_file['filename'],
                            img_file['body'])
         response = yield yihaodian(outerId=goods_link_id)
         yihaodian.parse_response(response.body)
         if yihaodian.is_ok():
             self.render(
                 'goods/distributor/yihaodian/result.html',
                 ok=True,
                 title="上传成功",
                 explain=
                 '<a href="/goods/distributor?shop=yhd">继续推送其他一号店商品</a>')
         else:
             self.render('goods/distributor/yihaodian/upload_img.html',
                         goods_link_id=goods_link_id,
                         error='<br/>'.join([
                             error.findtext('errorCode') + ':' +
                             error.findtext('errorDes')
                             for error in yihaodian.message.findall(
                                 './errInfoList/errDetailInfo')
                         ]))
Example #5
0
    def get(self):
        goods_id = self.get_argument('goods_id')
        category_id = self.get_argument('category_id')

        # 首先查询品牌和该分类下的所有额外属性
        brands_request = Yihaodian('yhd.category.brands.get')
        attribute_request = Yihaodian('yhd.category.attribute.get')
        brands_response, attribute_response = yield [brands_request(), attribute_request(categoryId=category_id)]
        brands_request.parse_response(brands_response.body)
        attribute_request.parse_response(attribute_response.body)

        brands = [PropDict({'brandId': brand.findtext('./brandId'), 'brandName': brand.findtext('./brandName')})
                  for brand in brands_request.message.findall('./brandInfoList/brandInfo')]

        if attribute_request.is_ok():
            attributes = attribute_request.message.findall('./categoryAttributeInfoList/categoryAttributeInfo')
        else:
            attributes = []

        goods = self.db.get('select * from goods where id=%s', goods_id)

        goods_shops = self.db.query(
            'select ss.* from supplier_shop ss,goods g where ss.supplier_id=g.supplier_id and g.id=%s and ss.deleted=0 '
            'and (g.all_shop=1 or ss.id in (select supplier_shop_id from goods_supplier_shop where goods_id=%s))',
            goods_id, goods_id)

        self.render('goods/distributor/yihaodian/push.html',
                    category_id=category_id,
                    category_name=self.get_argument('category_name'),
                    brands=brands,
                    attributes=attributes,
                    goods=goods,
                    goods_shops=goods_shops)
Example #6
0
    def post(self):
        yihaodian = Yihaodian('yhd.category.merchant.products.get')
        parent_id = self.get_argument('id', '0')
        response = yield yihaodian(categoryParentId=parent_id)
        self.set_header('Content-Type', 'application/json; charset=UTF-8')
        yihaodian.parse_response(response.body)

        if yihaodian.is_ok():
            result = []
            for node in yihaodian.message.findall('./merchantCategoryInfoList/merchantCategoryInfo'):
                result.append({
                    'id': node.findtext('merchantCategoryId'),
                    'name': node.findtext('categoryName'),
                    'isParent': node.findtext('categoryIsLeaf') == '0'
                })
            self.write(json_dumps(result))
        else:
            self.write('[]')
Example #7
0
    def post(self):
        yihaodian = Yihaodian('yhd.category.merchant.products.get')
        parent_id = self.get_argument('id', '0')
        response = yield yihaodian(categoryParentId=parent_id)
        self.set_header('Content-Type', 'application/json; charset=UTF-8')
        yihaodian.parse_response(response.body)

        if yihaodian.is_ok():
            result = []
            for node in yihaodian.message.findall(
                    './merchantCategoryInfoList/merchantCategoryInfo'):
                result.append({
                    'id':
                    node.findtext('merchantCategoryId'),
                    'name':
                    node.findtext('categoryName'),
                    'isParent':
                    node.findtext('categoryIsLeaf') == '0'
                })
            self.write(json_dumps(result))
        else:
            self.write('[]')
Example #8
0
def fetch_yihaodian_order(start_time, end_time):
    """
    发送一号店订单获取请求,返回订单列表
    :return: list: 一号店order_code列表
    """

    yihaodian = Yihaodian('yhd.orders.get')
    orders_list = []
    page = 0

    while True:
        page += 1
        # 发送请求
        response = yihaodian.sync_fetch(
            orderStatusList='ORDER_WAIT_SEND',
            dataType='1',
            startTime=start_time,
            endTime=end_time,
            pageRows='100',
            cutPage=page,
        )
        logging.info('yihaodian fetch order response: %s' % response)
        # 解析应答
        yihaodian.parse_response(response)
        if not yihaodian.is_ok():
            # 没有数据,返回
            return orders_list
        else:
            total = int(yihaodian.message.findtext('totalCount'))
            if total == 0:
                # 订单总数为零,返回
                return orders_list
            orders = yihaodian.message.find('orderList').findall('order')
            for order in orders:
                orders_list.append(order.findtext('orderCode'))
            if len(orders_list) >= total:
                # 获得所有订单,返回,可以少执行一次
                return orders_list
Example #9
0
    def get(self):
        goods_id = self.get_argument('goods_id')
        category_id = self.get_argument('category_id')

        # 首先查询品牌和该分类下的所有额外属性
        brands_request = Yihaodian('yhd.category.brands.get')
        attribute_request = Yihaodian('yhd.category.attribute.get')
        brands_response, attribute_response = yield [
            brands_request(),
            attribute_request(categoryId=category_id)
        ]
        brands_request.parse_response(brands_response.body)
        attribute_request.parse_response(attribute_response.body)

        brands = [
            PropDict({
                'brandId': brand.findtext('./brandId'),
                'brandName': brand.findtext('./brandName')
            }) for brand in brands_request.message.findall(
                './brandInfoList/brandInfo')
        ]

        if attribute_request.is_ok():
            attributes = attribute_request.message.findall(
                './categoryAttributeInfoList/categoryAttributeInfo')
        else:
            attributes = []

        goods = self.db.get('select * from goods where id=%s', goods_id)

        goods_shops = self.db.query(
            'select ss.* from supplier_shop ss,goods g where ss.supplier_id=g.supplier_id and g.id=%s and ss.deleted=0 '
            'and (g.all_shop=1 or ss.id in (select supplier_shop_id from goods_supplier_shop where goods_id=%s))',
            goods_id, goods_id)

        self.render('goods/distributor/yihaodian/push.html',
                    category_id=category_id,
                    category_name=self.get_argument('category_name'),
                    brands=brands,
                    attributes=attributes,
                    goods=goods,
                    goods_shops=goods_shops)
Example #10
0
    def post(self):
        arg = lambda k: self.get_argument(k).encode('utf-8')

        attr_items = []  # 带选项的属性
        attr_texts = []  # 需要输入的属性
        for name in self.request.arguments:
            if name.startswith('attr_item_'):
                attr_items.append('%s:%s' % (name[10:], '|'.join(self.get_arguments(name)).encode('utf-8')))
            elif name.startswith('attr_text_'):
                attr_texts.append('%s:%s' % (name[10:], arg(name)))

        goods_id = self.get_argument('goods_id')
        dg = alloc_distributor_goods(self.db, goods_id, options.shop_id_yihaodian)

        yihaodian = Yihaodian('yhd.product.add')
        response = yield yihaodian(
            outerId=dg.goods_link_id,
            prodAttributeInfoList=','.join(attr_texts), prodAttributeItemInfoList=','.join(attr_items),
            productType=arg('productType'), categoryId=arg('categoryId'),
            merchantCategoryId=arg('merchantCategoryId'), productCname=arg('productCname'),
            productSubTitle=arg('productSubTitle'), virtualStockNum=arg('virtualStockNum'),
            productNamePrefix=arg('productNamePrefix'), brandId=arg('brandId'),
            productMarketPrice=arg('productMarketPrice'), weight=arg('weight'),
            productSalePrice=arg('productSalePrice'), canSale=arg('canSale'),
            productDescription=arg('productDescription'), electronicCerticate=arg('electronicCerticate')
        )
        yihaodian.parse_response(response.body)
        if not yihaodian.is_ok():
            self.render('goods/distributor/yihaodian/result.html', ok=False, title="上传出错",
                        explain='<br/>'.join([error.findtext('errorCode')+':'+error.findtext('errorDes')
                                              for error in yihaodian.message.findall('./errInfoList/errDetailInfo')]))
        else:
            self.db.execute('update goods_distributor_shop set status="PENDING", created_by=%s, created_at=NOW() '
                            'where goods_id=%s and distributor_shop_id=%s and goods_link_id=%s',
                            self.current_user.name, goods_id, options.shop_id_yihaodian, dg.goods_link_id)
            self.render('goods/distributor/yihaodian/upload_img.html', error=None, goods_link_id=dg.goods_link_id)
Example #11
0
 def post(self):
     goods_link_id = self.get_argument('goods_link_id').encode('utf-8')
     if (not self.request.files) or (not 'img_file' in self.request.files):
         self.render('goods/distributor/yihaodian/upload_img.html',
                     error='请选择文件', goods_link_id=goods_link_id)
     else:
         img_file = self.request.files['img_file'][0]
         yihaodian = Yihaodian('yhd.product.img.upload')
         yihaodian.add_file('img_file', img_file['filename'], img_file['body'])
         response = yield yihaodian(outerId=goods_link_id)
         yihaodian.parse_response(response.body)
         if yihaodian.is_ok():
             self.render('goods/distributor/yihaodian/result.html', ok=True, title="上传成功",
                         explain='<a href="/goods/distributor?shop=yhd">继续推送其他一号店商品</a>')
         else:
             self.render('goods/distributor/yihaodian/upload_img.html',
                         goods_link_id=goods_link_id,
                         error='<br/>'.join([error.findtext('errorCode')+':'+error.findtext('errorDes')
                                             for error in yihaodian.message.findall('./errInfoList/errDetailInfo')]))
Example #12
0
def fetch_yihaodian_order(start_time, end_time):
    """
    发送一号店订单获取请求,返回订单列表
    :return: list: 一号店order_code列表
    """

    yihaodian = Yihaodian('yhd.orders.get')
    orders_list = []
    page = 0

    while True:
        page += 1
        # 发送请求
        response = yihaodian.sync_fetch(
            orderStatusList='ORDER_WAIT_SEND',
            dataType='1',
            startTime=start_time,
            endTime=end_time,
            pageRows='100',
            cutPage=page,
        )
        logging.info('yihaodian fetch order response: %s' % response)
        # 解析应答
        yihaodian.parse_response(response)
        if not yihaodian.is_ok():
            # 没有数据,返回
            return orders_list
        else:
            total = int(yihaodian.message.findtext('totalCount'))
            if total == 0:
                # 订单总数为零,返回
                return orders_list
            orders = yihaodian.message.find('orderList').findall('order')
            for order in orders:
                orders_list.append(order.findtext('orderCode'))
            if len(orders_list) >= total:
                # 获得所有订单,返回,可以少执行一次
                return orders_list
Example #13
0
def yihaodian_order(db, redis, distributor_order_id, message_raw):
    """
    一号店分销订单处理
    :param db:
    :param redis:
    :param distributor_order_id:
    :param message_raw:
    :type db:torndb.Connection
    :type redis:redis.client.StrictRedis
    :type distributor_order_id: int
    """
    distributor_order = db.get('select * from distributor_order where id=%s', distributor_order_id)
    distributor_order_no = distributor_order.order_no

    # 分销订单号不存在,结束
    if not distributor_order:
        logging.error('yihaodian job consume cannot find distributor order: order_no=%s', distributor_order_no)
        return

    # 重新刷新订单信息
    yihaodian = Yihaodian('yhd.order.detail.get')
    response = yihaodian.sync_fetch(orderCode=distributor_order_no)
    logging.info('yihaodian response for distributor_order_no %s : %s' % (distributor_order_no, response))
    yihaodian.parse_response(response)

    # 一号店请求失败,结束
    if not yihaodian.is_ok():
        logging.error('yihaodian job consume fetch order failed, distributor order_no=%s', distributor_order_no)
        return

    order_status = yihaodian.message.findtext('./orderInfo/orderDetail/orderStatus').strip()

    # 一号店订单已取消,从队列移除,结束
    if order_status == 'ORDER_CANCEL':
        # 队列移除
        redis.lrem(options.queue_distributor_order_processing, 0, message_raw)
        logging.info(' yihaodian order_no %s cancelled ', distributor_order_no)
        return
    # 一号店订单状态为‘可以发货’, 则处理该订单
    elif order_status == 'ORDER_TRUNED_TO_DO':
        # 更新分销订单message, 如果distributor_order表中message为空,则该分销订单已在分销商处取消
        db.execute('update distributor_order set message=%s where order_no=%s', response, distributor_order_no)

        # 筛选电子券订单
        order_items = yihaodian.message.findall('./orderInfo/orderItemList/orderItem')
        coupon_items = []
        for item in order_items:
            goods_link_id = item.findtext('./outerId')
            if goods_link_id:
                goods = db.get('select g.* from goods as g, goods_distributor_shop as gds '
                               'where g.id = gds.goods_id and gds.distributor_shop_id=%s and gds.goods_link_id=%s',
                               options.shop_id_yihaodian, goods_link_id)
                if not goods and int(goods_link_id) < 20000:
                    goods = db.get('select g.* from goods g where g.type="E" and g.id=%s', goods_link_id)
                # 当商品类型为电子券时,才处理
                if goods and goods.type == options.goods_type_electronic:
                    coupon_items.append((item, goods))
                else:
                    logging.warning('yihaodian job consume warning: goods_link_id=%s not found or goods type is real'
                                    % goods_link_id)

        if len(coupon_items) == 0:
            # 分销订单没有电子券,从处理队列移除
            redis.lrem(options.queue_distributor_order_processing, 0, message_raw)
            logging.info('yihaodian job consume exits for no real goods, distributor order_no: %s' % distributor_order_no)
            return

        # 生成一百券订单
        if distributor_order.order_id == 0 and check_stock(coupon_items):
            mobile = yihaodian.message.findtext('./orderInfo/orderDetail/goodReceiverMoblie')
            order_amount = yihaodian.message.findtext('./orderInfo/orderDetail/orderAmount')
            payment = Decimal(yihaodian.message.findtext('./orderInfo/orderDetail/realAmount'))
            order_id, order_no = new_distributor_order(db, options.shop_id_yihaodian, order_amount, payment, mobile)

            # 生成订单项
            for item in coupon_items:
                order_item = item[0]
                goods_info = item[1]
                sales_price = Decimal(order_item.findtext('./orderItemPrice'))
                count = int(order_item.findtext('./orderItemNum'))
                distributor_goods_id = order_item.findtext('./productId')
                result = new_distributor_item(db, order_id, order_no, sales_price, count, goods_info, mobile,
                                              options.shop_id_yihaodian, distributor_goods_id, [], False)
                if not result.ok:
                    logging.error('failed to generate order items for distributor_order_id=%s of goods_id=%s'
                                  % (distributor_order_id, goods_info.id))
                    return
                logging.info('create new yibaiquan order id=%s for yihaodian distributor order id=%s'
                             % (order_id, distributor_order_id))

            # 相互更新分销订单和订单
            db.execute('update orders set distributor_order_id=%s where id = %s',
                       distributor_order_id, order_id)
            db.execute('update distributor_order set order_id=%s where id=%s',
                       order_id, distributor_order_id)

            # 按order_item发送券短信
            all_order_items = db.query('select * from order_item where order_id=%s', order_id)
            for item in all_order_items:
                CouponSMSMessage(db, redis, order_item=item).remark('一号店订单发送券号短信').send()

            # 通知一号店,已发货
            yihaodian = Yihaodian('yhd.logistics.order.shipments.update')
            response = yihaodian.sync_fetch(orderCode=distributor_order_no,
                                            deliverySupplierId=options.yhd_delivery,
                                            expressNbr=distributor_order_no
                                            )
            yihaodian.parse_response(response)

            if yihaodian.is_ok():
                # 分销订单处理完成,从处理队列移除
                redis.lrem(options.queue_distributor_order_processing, 0, message_raw)
                logging.info('yihaodian distributor order (id=%s) finish' % distributor_order_id)
            else:
                logging.error('update yihaodian distributor order (id=%s) shipments failed' % distributor_order_id)
Example #14
0
def yihaodian_order(db, redis, distributor_order_id, message_raw):
    """
    一号店分销订单处理
    :param db:
    :param redis:
    :param distributor_order_id:
    :param message_raw:
    :type db:torndb.Connection
    :type redis:redis.client.StrictRedis
    :type distributor_order_id: int
    """
    distributor_order = db.get('select * from distributor_order where id=%s',
                               distributor_order_id)
    distributor_order_no = distributor_order.order_no

    # 分销订单号不存在,结束
    if not distributor_order:
        logging.error(
            'yihaodian job consume cannot find distributor order: order_no=%s',
            distributor_order_no)
        return

    # 重新刷新订单信息
    yihaodian = Yihaodian('yhd.order.detail.get')
    response = yihaodian.sync_fetch(orderCode=distributor_order_no)
    logging.info('yihaodian response for distributor_order_no %s : %s' %
                 (distributor_order_no, response))
    yihaodian.parse_response(response)

    # 一号店请求失败,结束
    if not yihaodian.is_ok():
        logging.error(
            'yihaodian job consume fetch order failed, distributor order_no=%s',
            distributor_order_no)
        return

    order_status = yihaodian.message.findtext(
        './orderInfo/orderDetail/orderStatus').strip()

    # 一号店订单已取消,从队列移除,结束
    if order_status == 'ORDER_CANCEL':
        # 队列移除
        redis.lrem(options.queue_distributor_order_processing, 0, message_raw)
        logging.info(' yihaodian order_no %s cancelled ', distributor_order_no)
        return
    # 一号店订单状态为‘可以发货’, 则处理该订单
    elif order_status == 'ORDER_TRUNED_TO_DO':
        # 更新分销订单message, 如果distributor_order表中message为空,则该分销订单已在分销商处取消
        db.execute('update distributor_order set message=%s where order_no=%s',
                   response, distributor_order_no)

        # 筛选电子券订单
        order_items = yihaodian.message.findall(
            './orderInfo/orderItemList/orderItem')
        coupon_items = []
        for item in order_items:
            goods_link_id = item.findtext('./outerId')
            if goods_link_id:
                goods = db.get(
                    'select g.* from goods as g, goods_distributor_shop as gds '
                    'where g.id = gds.goods_id and gds.distributor_shop_id=%s and gds.goods_link_id=%s',
                    options.shop_id_yihaodian, goods_link_id)
                if not goods and int(goods_link_id) < 20000:
                    goods = db.get(
                        'select g.* from goods g where g.type="E" and g.id=%s',
                        goods_link_id)
                # 当商品类型为电子券时,才处理
                if goods and goods.type == options.goods_type_electronic:
                    coupon_items.append((item, goods))
                else:
                    logging.warning(
                        'yihaodian job consume warning: goods_link_id=%s not found or goods type is real'
                        % goods_link_id)

        if len(coupon_items) == 0:
            # 分销订单没有电子券,从处理队列移除
            redis.lrem(options.queue_distributor_order_processing, 0,
                       message_raw)
            logging.info(
                'yihaodian job consume exits for no real goods, distributor order_no: %s'
                % distributor_order_no)
            return

        # 生成一百券订单
        if distributor_order.order_id == 0 and check_stock(coupon_items):
            mobile = yihaodian.message.findtext(
                './orderInfo/orderDetail/goodReceiverMoblie')
            order_amount = yihaodian.message.findtext(
                './orderInfo/orderDetail/orderAmount')
            payment = Decimal(
                yihaodian.message.findtext(
                    './orderInfo/orderDetail/realAmount'))
            order_id, order_no = new_distributor_order(
                db, options.shop_id_yihaodian, order_amount, payment, mobile)

            # 生成订单项
            for item in coupon_items:
                order_item = item[0]
                goods_info = item[1]
                sales_price = Decimal(order_item.findtext('./orderItemPrice'))
                count = int(order_item.findtext('./orderItemNum'))
                distributor_goods_id = order_item.findtext('./productId')
                result = new_distributor_item(db, order_id, order_no,
                                              sales_price, count, goods_info,
                                              mobile,
                                              options.shop_id_yihaodian,
                                              distributor_goods_id, [], False)
                if not result.ok:
                    logging.error(
                        'failed to generate order items for distributor_order_id=%s of goods_id=%s'
                        % (distributor_order_id, goods_info.id))
                    return
                logging.info(
                    'create new yibaiquan order id=%s for yihaodian distributor order id=%s'
                    % (order_id, distributor_order_id))

            # 相互更新分销订单和订单
            db.execute(
                'update orders set distributor_order_id=%s where id = %s',
                distributor_order_id, order_id)
            db.execute('update distributor_order set order_id=%s where id=%s',
                       order_id, distributor_order_id)

            # 按order_item发送券短信
            all_order_items = db.query(
                'select * from order_item where order_id=%s', order_id)
            for item in all_order_items:
                CouponSMSMessage(db, redis,
                                 order_item=item).remark('一号店订单发送券号短信').send()

            # 通知一号店,已发货
            yihaodian = Yihaodian('yhd.logistics.order.shipments.update')
            response = yihaodian.sync_fetch(
                orderCode=distributor_order_no,
                deliverySupplierId=options.yhd_delivery,
                expressNbr=distributor_order_no)
            yihaodian.parse_response(response)

            if yihaodian.is_ok():
                # 分销订单处理完成,从处理队列移除
                redis.lrem(options.queue_distributor_order_processing, 0,
                           message_raw)
                logging.info('yihaodian distributor order (id=%s) finish' %
                             distributor_order_id)
            else:
                logging.error(
                    'update yihaodian distributor order (id=%s) shipments failed'
                    % distributor_order_id)