Пример #1
0
 def create(self, user_id, data, user_name):
     order_id = IdGenerationService.generate_order_id()
     order = Order(
         consignee_name=data['consignee_name'],
         zip_code=data['zip_code'],
         consignee_phone=data['consignee_phone'],
         consignee_province=data['consignee_province'],
         consignee_city=data['consignee_city'],
         consignee_area=data['consignee_area'],
         consignee_detail=data['consignee_detail'],
         express=data['express'],
         store_id=data['store_id'],
         user_note=data.get('user_note', None),
         user_id=user_id,
         id=order_id,
         user_name=user_name,
         order_code=order_id  # 手工创建的订单号为ID
     )
     order.save()
     create_order_details = []
     # TODO 优化,获取sku信息,在order_detail加冗余
     for sku_info in data['skues']:
         order_detail = OrderDetail(quantity=sku_info['quantity'],
                                    sku_id=sku_info['sku_id'],
                                    order_id=order.id)
         create_order_details.append(order_detail)
     OrderDetail.objects.bulk_create(create_order_details)
     return self.get(user_id=user_id, order_id=order.id)
Пример #2
0
 def create(self, user_id, token, data, user_name=None):
     s = ';'
     user_info = get_user_info(user_id)
     express_number = s.join(data.get('express_number', []))
     stock_in = StockIn(stock_in_type=int(data.get('stock_in_type', 1)),
                        warehouse_id=data['warehouse_id'],
                        express=data.get('express'),
                        express_number=express_number,
                        warehouse_code=data.get('warehouse_code'),
                        warehouse_name=data.get('warehouse_name'),
                        wms_app_key=data.get('wms_app_key'),
                        user_note=data.get('user_note'),
                        estimated_to_arrival=datetime.fromtimestamp(
                            int(data.get('estimated_to_arrival'))),
                        user_id=user_id,
                        user_name=user_name,
                        user_mobile=user_info['phone'],
                        id=IdGenerationService.generate_stock_in_id())
     # 获取仓库信息,修改入库单的发货和收货信息
     # 可能存在不能获取到信息的情况
     warehouse = get_warehouse_by_id(data['warehouse_id'], token)
     stock_in.sender_phone = data.get('sender_phone', '')
     stock_in.send_name = data.get('sender_name', '')
     stock_in.recipient_phone = warehouse['warehouse_recipient_contact']
     stock_in.recipient_name = warehouse['warehouse_recipient_name']
     # 如果是退货入库,必须关联退货订单
     if int(data['stock_in_type']) == 2:
         try:
             order = Order.objects.get(id=data['order_id'])
             stock_in.order_code = order.order_code
         except AttributeError:
             raise CustomException('10003', 'order_id not exist')
         except ObjectDoesNotExist:
             raise CustomException('10009')
     if not data.get('skues'):
         raise CustomException('10020', '请填写商品信息')
     create_stock_in_details = []
     for sku_info in data['skues']:
         sku = Sku.objects.get(id=sku_info['sku_id'])
         stock_in_detail = StockInDetail(quantity=sku_info['quantity'],
                                         sku_id=sku_info['sku_id'],
                                         stock_in_id=stock_in.id,
                                         sku_name=sku.sku_name,
                                         sku_spec=sku.specification,
                                         bar_code=sku.bar_code,
                                         item_code=sku.item_code,
                                         user_id=user_id)
         create_stock_in_details.append(stock_in_detail)
     stock_in.save()
     StockInDetail.objects.bulk_create(create_stock_in_details)
     stock_in.stock_in_details = create_stock_in_details
     # data['warehouse_id']
     # EntryOrder(custom_id='xiaobanma').\
     #     sync_to_cop(user_id, stock_in)
     EntryOrder(custom_id=data['warehouse_id']).\
         sync_to_cop(user_id, stock_in)
     return stock_in
Пример #3
0
 def copy_order(self, order):
     _order = Order()
     for f in order._meta.fields:
         if isinstance(f, ForeignKey):
             setattr(_order, '%s_id', getattr(order, '%s_id' % f.name))
         else:
             setattr(_order, f.name, getattr(order, f.name))
     order_id = IdGenerationService.generate_order_id()
     _order.id = order_id
     _order.order_details = []
     return _order
Пример #4
0
 def create(self, user_id, param=None):
     sku = Sku(sku_name=param['sku_name'],
               specification=param['specification'],
               bar_code=param['bar_code'],
               item_code=param['item_code'],
               price=param['price'],
               unit=param['unit'],
               category_id=param['category_id'],
               user_id=user_id,
               id=IdGenerationService.generate_sku_id(user_id))
     category = SkuCategory.objects.\
         get(id=param['category_id'], is_deleted=False)
     sku.category_name = category.category_name
     sku.save()
     return sku
Пример #5
0
 def create(self, user_id, param=None):
     store = Store(username=param['username'],
                   store_key=param.get('store_key'),
                   store_name=param['store_name'],
                   address=param.get('address'),
                   app_key=param.get('app_key'),
                   app_secret=param.get('app_secret'),
                   access_token=param.get('access_token'),
                   contact_number=param.get('contact_number'),
                   refresh_token=param['refresh_token'],
                   abbreviation=param.get('abbreviation'),
                   platform_id=param['platform_id'],
                   auto_merge=param.get('auto_merge', False),
                   auto_check=param.get('auto_check', False),
                   is_enabled=param.get('is_enabled', True),
                   user_id=user_id,
                   id=IdGenerationService.generate_store_id(user_id))
     # is_exist = False
     # if param.get('store_key'):
     #     is_exist = Store.objects.\
     #         filter(store_key=param['store_key'],
     #                app_key=param['app_key']).\
     #         count()
     # else:
     #     is_exist = Store.objects.\
     #         filter(app_key=param['app_key']).\
     #         count()
     # if is_exist:
     #     raise Exception('重复密钥创建')
     platform = Plat.objects.get(id=param['platform_id'])
     store.platform_name = platform.name
     store.platform_id = platform.id
     if param.get('access_token_expire_time'):
         access_token_expire_time = datetime.datetime.\
             fromtimestamp(int(param.get('access_token_expire_time')))
         store.access_token_expire_time = access_token_expire_time
     if param.get('refresh_token_expire_time'):
         refresh_token_expire_time = datetime.datetime.\
             fromtimestamp(int(param.get('refresh_token_expire_time')))
         store.refresh_token_expire_time = refresh_token_expire_time
     fetch_order_lastest = datetime.datetime.now() -\
         datetime.timedelta(days=30)
     store.fetch_order_latest = fetch_order_lastest
     store.save()
     self.check_invalid(store)
     return store
Пример #6
0
def ware_detail_callback(
        user_param,
        store_detail,
        sku_item,
        wares_total,
        sku_total,
        status):
    if status["callback_status"] == "end":
        start_stamp = status["start_stamp"]
        end_stamp = status["end_stamp"]
        msg = str.format(
            "%s[%s]商品同步已完成,%s个商品%s个SKU,共耗时%s秒" %
            (store_detail["platform_name"], store_detail["store_name"],
             wares_total, sku_total, round(end_stamp - start_stamp, 1)))
        # print(msg)
        logging.info(msg)
        headers = {'token': user_param["token"]}
        data = {
            "msg_type": 3,
            "msg_title": "商品同步完成通知",
            "msg_body": msg
        }
        try:
            url = str.format(
                "%s/api/messages/put" % test.CMM_URL)
            resp = requests.post(url=url, headers=headers, data=data)
            res = json.loads(resp.text)
            if "error_code" not in res and res["error_code"] != 0:
                logging.warning("商品同步时发送消息返回失败,url:%s; return:%s" % (url, res))
        except BaseException as e:
            logging.warning("商品同步时发送消息失败,error:%s" % (str(e)))
        return True
    else:
        sku = Sku(**sku_item)
        sku_old = Sku.objects.filter(
            item_code=sku_item['item_code'],
            user_id=sku_item['user_id'])
        if sku_old:
            sku_old.update(**sku_item)
        else:
            sku.id = IdGenerationService.generate_sku_id(
                store_detail["user_id"])
            sku.save()
Пример #7
0
    def create_order(cls, order):
        logger.debug('==================================')
        logger.debug(order)
        logger.debug('==================================')
        o = Order()
        # if order.get('order_id', False):
        #     o.id = order['order_id']

        # 按照规则生成order的id
        o.id = IdGenerationService.generate_order_id()

        o.consignee_country = order['consignee_country']
        store_id = order['store_id']
        user_id = order['user_id']
        user_info = get_user_info(user_id)
        o.user_name = user_info['nickname']
        o.user_id = user_id
        try:
            store = Store.objects.get(id=store_id)
        except:
            raise CustomException('10001', '店铺不存在')
        else:
            o.store = store
        order_status_info = order.get('order_status_info', '')
        if order_status_info:
            o.order_status_info = order_status_info
        else:
            o.order_status_info = '10'
        o.order_status = order.get('order_status', '10')
        o.mark_reason = order['mark_reason']
        o.express_note = order['express_note']
        o.buyer_note = order['buyer_note']
        o.goods_price = order['goods_price']
        o.express_type = order['express_type']
        o.status_ori = order['status_ori']
        o.quantity = order['quantity']
        o.consignee_detail = order['consignee_detail']
        o.express_fee = order['express_fee']
        o.consignee_country = order['consignee_country']
        o.order_code = order['order_code']
        o.consignee_area = order['consignee_area']
        o.refund_status_ori = order['refund_status_ori']
        o.total_price = order['total_price']
        o.express_number = order['express_number']
        o.consignee_phone = order['consignee_phone']
        o.consignee_city = order['consignee_city']
        o.consignee_province = order['consignee_province']
        o.consignee_name = order['consignee_name']
        o.pay_time = order['pay_time']
        o.add_time = order['add_time']
        if order.get('warehouse_id', False):
            o.warehouse_id = order['warehouse_id']
        o.created_at = time.strftime('%Y-%m-%d %H:%M:%S',
                                     time.localtime(time.time()))
        o.save()
        for order_detail in order['order_details']:
            item_code = order_detail['item_code']
            sku = Sku.objects.get(item_code=item_code, user_id=user_id)
            od = OrderDetail()
            # od.sku_id = sku.id
            od.total_price = order_detail['total_price']
            # od.order_id = order_detail['order_id']
            od.order = o
            od.sku = sku
            od.price = order_detail['price']
            # od.order_detail_id = order_detail['order_detail_id']
            od.quantity = order_detail['quantity']
            od.save()
        return {'order_id': o.id}