Beispiel #1
0
    def get_goods(self, equipment_in, product_name, buy_num, buy_price, shop, terminal_code):
        goods = None
        product_model = None
        if equipment_in is not None:
            product_model_qs = ProductModel.query().filter(name = equipment_in.product_model)
            if product_model_qs.count() > 0:
                product_model = product_model_qs[0]

        if product_name:
            goods_qs = Goods.query().filter(name = product_name)
            if goods_qs.count() > 0:
                goods = goods_qs[0]
            else:
                try:
                    price = int(buy_price / buy_num * 100)
                except Exception as e:
                    price = 0
                goods = Goods.create(name = product_name, alias = product_name, price = price, \
                                     shop = shop, product_model = product_model, \
                                     update_time = self._modify_date, create_time = self._create_date)
        else:
            goods = Goods.query().filter(name = "系统商品")[0]
            RecordError.create(remark = "缺少商品:{c}".format(c = terminal_code))

        return goods, product_model
Beispiel #2
0
 def create(self, goods_info, result_mapping):
     goods_qs = Goods.query().filter(shop = goods_info.shop, \
                                    name = goods_info.name)
     if goods_qs.count():
         goods = goods_qs[0]
     else:
         goods = Goods.create(**goods_info)
     return goods
Beispiel #3
0
    def convet_goods(self, name, buy_number, buy_money):
        goods = None
        goods_qs = Goods.query().filter(name=name)
        if goods_qs.count() > 0:
            goods = goods_qs[0]
        else:
            try:
                price = int(buy_money / buy_number)
            except Exception as e:
                price = 0

            goods = Goods.create(name=name,
                                 alias=name,
                                 price=price,
                                 shop=self._shop,
                                 product_model=self._product_model)

        return goods
Beispiel #4
0
    def calc(self, shop=None, has_none=False):
        if not hasattr(self, '_enume'):
            from model.store.model_shop import Goods
            self._enume = [None] if has_none else []
            goods_qs = Goods.query()
            for goods in goods_qs:
                self._enume.append(goods)

        select_enum = self._enume.copy()
        if shop:
            select_enum = filter(lambda obj: obj.shop == shop, select_enum)
        return random.choice(select_enum)
Beispiel #5
0
    def get(cls, goods_id):
        """获取商品详情"""
        goods = Goods.get_byid(goods_id)

        return goods
Beispiel #6
0
    def match(cls, keyword, size=5):
        """匹配商品列表"""

        return Goods.query(name=keyword).order_by('-create_time')[:size]
Beispiel #7
0
 def search_qs(cls, **search_info):
     goods_qs = Goods.query(**search_info)
     goods_qs = goods_qs.order_by("-create_time")
     return goods_qs