123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- # -*- coding: utf-8 -*-
- """
- demeter service
- name:product.py 商品业务
- author:rabin
- """
- from demeter.core import *
- import random
- class Product(object):
- def getSite(self, site_id):
- model = Demeter.model('site')
- model.id = site_id
- site = model.select(type='fetchone')
- return site
- def get(self):
- model = Demeter.model('product')
- model.status = 1
- product = model.select()
- if product:
- return product
- return False
- model = Demeter.model('site')
- model.id = site_id
- site = model.select(type='fetchone')
- if site:
- model = Demeter.model('product')
- model.site_id = site_id
- model.status = 1
- product = model.select()
- if product:
- site['product'] = product
- return site
- return False
- def status(self, id, value):
- model = Demeter.model('product')
- model.id = id
- return model.update(status=value)
- def order(self, order, pic, site_id, product_id):
- model = Demeter.model('order')
- model.orderID = order
- model.pic = pic
- model.site_id = site_id
- model.product_id = product_id
- return model.insert()
- def createOrderId(self, order, site_id, product_id):
- if not order:
- order = self.code(product_id)
- return order
- def code(self, product_id):
- cdate = Demeter.date(Demeter.time(), '%Y%m%d%H%M%S')
- min = 1000
- max = 9999
- order = 'CN' + str(product_id + 10000) + '-' + str(cdate) + str(random.randint(min, max))
- model = Demeter.model('order')
- model.orderID = order
- info = model.select(type='fetchone')
- if info:
- return self.get(self, product_id)
- return order
|