product.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter service
  4. name:product.py 商品业务
  5. author:rabin
  6. """
  7. from demeter.core import *
  8. import random
  9. class Product(object):
  10. def getSite(self, site_id):
  11. model = Demeter.model('site')
  12. model.id = site_id
  13. site = model.select(type='fetchone')
  14. return site
  15. def get(self):
  16. model = Demeter.model('product')
  17. model.status = 1
  18. product = model.select()
  19. if product:
  20. return product
  21. return False
  22. model = Demeter.model('site')
  23. model.id = site_id
  24. site = model.select(type='fetchone')
  25. if site:
  26. model = Demeter.model('product')
  27. model.site_id = site_id
  28. model.status = 1
  29. product = model.select()
  30. if product:
  31. site['product'] = product
  32. return site
  33. return False
  34. def status(self, id, value):
  35. model = Demeter.model('product')
  36. model.id = id
  37. return model.update(status=value)
  38. def order(self, order, pic, site_id, product_id):
  39. model = Demeter.model('order')
  40. model.orderID = order
  41. model.pic = pic
  42. model.site_id = site_id
  43. model.product_id = product_id
  44. return model.insert()
  45. def createOrderId(self, order, site_id, product_id):
  46. if not order:
  47. order = self.code(product_id)
  48. return order
  49. def code(self, product_id):
  50. cdate = Demeter.date(Demeter.time(), '%Y%m%d%H%M%S')
  51. min = 1000
  52. max = 9999
  53. order = 'CN' + str(product_id + 10000) + '-' + str(cdate) + str(random.randint(min, max))
  54. model = Demeter.model('order')
  55. model.orderID = order
  56. info = model.select(type='fetchone')
  57. if info:
  58. return self.get(self, product_id)
  59. return order