Пример #1
0
def syncdb():
    from lib.util import find_subclasses
    from model import db, User, Distribution, Category, Page

    models = find_subclasses(db.Model)
    for model in models:
        if model.table_exists():
            model.drop_table()
        model.create_table()
        logging.info('created table:%s' % model._meta.db_table)

    User.create(mobile='root',
                password=User.create_password('111111'),
                group=9)
    Distribution.create(name='免费配送', price=0)
    Distribution.create(name='上门自提', price=0)
    Category.create(name='积分商品', slug='credit', order=1)
    Category.create(name='搭配购买', slug='acc', order=2)
    Category.create(name='鸡', slug='ji', order=3)
    Category.create(name='鸭', slug='ya', order=4)
    Category.create(name='鹅', slug='e', order=5)
    Category.delete().where(Category.id == 1).execute()
    Category.delete().where(Category.id == 2).execute()
    #Category.create(name = '乳脂奶油蛋糕', slug = 'creambutter', order = 6)
    #Category.create(name = '冰淇淋蛋糕', slug = 'icecream', order = 7)
    Page.create(name='菜市优品', slug='aboutus', content='')
    Page.create(name='包装展示', slug='bzzs', content='')
    Page.create(name='订购说明', slug='dgsm', content='')
    Page.create(name='如何收货', slug='rhsh', content='')
    Page.create(name='付款方式', slug='fkfs', content='')
    Page.create(name='配送范围', slug='psfw', content='')

    logging.info('superuser - username:root password:111111')
Пример #2
0
def syncdb():
    from lib.util import find_subclasses
    from model import db, User, Distribution, Category, Page
    
    models = find_subclasses(db.Model)
    for model in models:
        if model.table_exists():
            model.drop_table()
        model.create_table()
        logging.info('created table:%s' % model._meta.db_table)
    
    Distribution.create(name = '免费配送', price = 0)
    Distribution.create(name = '上门自提', price = 0)
    Category.create(name = '积分商品', slug = 'credit', order = 1)
    Category.create(name = '搭配购买', slug = 'acc', order = 2)
    Category.create(name = '慕斯蛋糕', slug = 'mousse', order = 3)
    Category.create(name = '巧克力蛋糕', slug = 'chocolate', order = 4)
    Category.create(name = '乳酪蛋糕', slug = 'cheese', order = 5)
    Category.create(name = '乳脂奶油蛋糕', slug = 'creambutter', order = 6)
    Category.create(name = '冰淇淋蛋糕', slug = 'icecream', order = 7)
    Page.create(name = '吉米的厨房', slug = 'aboutus', content = '')
    Page.create(name = '包装展示', slug = 'bzzs', content = '')
    Page.create(name = '订购说明', slug = 'dgsm', content = '')
    Page.create(name = '如何收货', slug = 'rhsh', content = '')
    Page.create(name = '付款方式', slug = 'fkfs', content = '')
    Page.create(name = '配送范围', slug = 'psfw', content = '')
    User.create(mobile = 'root', password = User.create_password('111111'), group = 9)
    
    logging.info('superuser - username:root password:111111')
Пример #3
0
    def post(self, did):
        try:
            distribution = Distribution.get(id=did)
        except:
            self.flash("此配送方式不存在")
            self.redirect("/admin/distributions")
            return

        pdid = int(self.get_argument('pdid', 0))
        name = self.get_argument('name', None)
        price = float(str(self.get_argument("price", 0.0)))
        content = self.get_argument('content', '')

        distribution.pdid = pdid
        distribution.name = name
        distribution.price = price
        distribution.content = content

        try:
            distribution.validate()
            distribution.save()
            self.flash(u"配送方式%s修改成功" % name)
            self.redirect("/admin/distributions")
            return
        except Exception, ex:
            self.flash(str(ex))
Пример #4
0
 def post(self, did):
     try:
         distribution = Distribution.get(id = did)
     except:
         self.flash("此配送方式不存在")
         self.redirect("/admin/distributions")
         return
     
     pdid = int(self.get_argument('pdid', 0))
     name = self.get_argument('name', None)
     price = float(str(self.get_argument("price", 0.0)))
     content = self.get_argument('content', '')
     
     distribution.pdid = pdid
     distribution.name = name
     distribution.price = price
     distribution.content = content
     
     try:
         distribution.validate()
         distribution.save()
         self.flash(u"配送方式%s修改成功" % name)
         self.redirect("/admin/distributions")
         return
     except Exception, ex:
         self.flash(str(ex))
Пример #5
0
    def get(self):
        status = self.get_argument("status", None)
        ft = (Order.status >= 0)
        if status:
            ft = ft & (Order.status == status)

        page = int(self.get_argument("page", 1))
        pagesize = self.settings['admin_pagesize']

        oq = Order.select().where(ft)
        total = oq.count()

        orders = []
        for order in oq.paginate(page, pagesize).order_by(
                Order.ordered.desc()).dicts():
            order['orderitems'] = []
            try:
                order['ua'] = UserAddr.get(id=order['uaid'])
            except:
                order['ua'] = UserAddr()

            try:
                order['distr'] = Distribution.get(id=order['distrid'])
            except:
                order['distr'] = Distribution()

            for orderitem in OrderItem.select().where(
                    OrderItem.oid == order['id']).dicts():

                try:
                    orderitem['shop'] = Shop.get(id=orderitem['sid'])
                    if orderitem['said'] > 0:
                        orderitem['shopattr'] = ShopAttr.get(
                            id=orderitem['said'])

                    order['orderitems'].append(orderitem)
                except:
                    orderitem['shop'] = Shop()

            if order['orderitems']:
                orders.append(order)

        self.render('admin/order.html',
                    orders=orders,
                    total=total,
                    page=page,
                    pagesize=pagesize)
Пример #6
0
 def get(self, did):
     try:
         distribution = Distribution.get(id = did)
     except:
         self.flash("此配送方式不存在")
         self.redirect("/admin/distributions")
         return
     
     distributions = self.get_distributions()
     self.render('admin/editdistribution.html', distribution = distribution, distributions = distributions.values())
Пример #7
0
    def get_distributions(self):
        distributions = self.session.get('distributions')

        if not distributions:
            distributions = {}

            for distribution in Distribution.select().dicts():
                if distribution['pdid'] == 0:
                    distribution['list'] = []
                    distributions[distribution['id']] = distribution
                else:
                    distributions[distribution['pdid']]['list'].append(distribution)

            self.session.replace('distributions', distributions, 86400)
        return distributions
Пример #8
0
    def get_distributions(self):
        distributions = self.memcachedb.get('distributions')

        if not distributions:
            distributions = {}

            for distribution in Distribution.select().dicts():
                if distribution['pdid'] == 0:
                    distribution['list'] = []
                    distributions[distribution['id']] = distribution
                else:
                    distributions[distribution['pdid']]['list'].append(
                        distribution)

            self.memcachedb.replace('distributions', distributions, 86400)
        return distributions
Пример #9
0
 def post(self):
     pdid = int(self.get_argument('pdid', 0))
     name = self.get_argument('name', None)
     price = float(str(self.get_argument("price", 0.0)))
     content = self.get_argument('content', '')
     
     distribution = Distribution()
     distribution.pdid = pdid
     distribution.name = name
     distribution.price = price
     distribution.content = content
     
     try:
         distribution.validate()
         distribution.save()
         self.flash("配送方式%s添加成功" % name)
         self.redirect("/admin/distributions")
         return
     except Exception as ex:
         self.flash(str(ex))
         
     distributions = self.get_distributions()
     
     self.render('admin/adddistribution.html', distributions = list(distributions.values()))
Пример #10
0
 def get(self):
     status = self.get_argument("status", None)
     ft = (Order.status >= 0)
     if status:
         ft = ft & (Order.status == status)
     
     page = int(self.get_argument("page", 1))
     pagesize = self.settings['admin_pagesize']
     
     oq = Order.select().where(ft)
     total = oq.count()
             
     orders = []
     for order in oq.paginate(page, pagesize).order_by(Order.ordered.desc()).dicts():
         order['orderitems'] = []
         try:
             order['ua'] = UserAddr.get(id = order['uaid'])
         except:
             order['ua'] = UserAddr()
         
         try:
             order['distr'] = Distribution.get(id = order['distrid'])
         except:
             order['distr'] = Distribution()
             
         for orderitem in OrderItem.select().where(OrderItem.oid == order['id']).dicts():
             
             try:
                 orderitem['shop'] = Shop.get(id = orderitem['sid'])
                 if orderitem['said'] > 0:
                     orderitem['shopattr'] = ShopAttr.get(id = orderitem['said'])
                 
                 order['orderitems'].append(orderitem)
             except:
                 orderitem['shop'] = Shop()
         
         if order['orderitems']:
             orders.append(order)
     
     self.render('admin/order.html', orders = orders, total = total, page = page, pagesize = pagesize)
Пример #11
0
 def get(self, did):
     Distribution.delete().where(Distribution.id == did).execute()
     self.memcachedb.remove('distributions')
     self.flash(u"栏目配送方式成功")
     self.redirect(self.request.headers["Referer"])
Пример #12
0
 def post(self):
     order = None
     user = self.get_current_user()
     
     try:
         order = Order.get(uid = user.id, status = 0)
         
         mobile = self.get_argument("mobile", user.mobile)
         uaid = self.get_argument("uaid", None)
         distrid = self.get_argument("distrid", None)
         day = self.get_argument("day", datetime.date.today() + datetime.timedelta(days=1))
         hour = int(self.get_argument("hour", 10))
         payment = self.get_argument("payment", 0)
         message = self.get_argument("message", "")
         isinvoice = self.get_argument("isinvoice", 0)
         invoicesub = self.get_argument("invoicesub", 0)
         invoicename = self.get_argument("invoicename", "")
         invoicecontent = self.get_argument("payment", 1)
         shippingprice = self.get_argument("shippingprice", 0.0)
         
         if uaid and distrid:
             try:
                 distrib = Distribution.get(id = distrid)
                 shippingprice = distrib.price
             except:
                 pass
             
             order.mobile = mobile
             order.uaid = uaid
             order.distrid = distrid
             order.distribbed = "%s %d:00:00" % (str(day), hour)
             order.payment = payment
             order.message = message
             
             order.isinvoice = isinvoice
             
             if isinvoice:
                 order.invoicesub = invoicesub
                 order.invoicename = invoicename
                 order.invoicecontent = invoicecontent
             
             order.shippingprice = shippingprice
             
             order.save()
             
             
                 
             body = ""
             for orderitem in OrderItem.select().where(OrderItem.oid == order.id).dicts():
                     
                 try:
                     shop = Shop.get(id = orderitem['sid'])
                         
                     sname = ""
                     if orderitem['said'] > 0:
                         shopattr = ShopAttr.get(id = orderitem['said'])
                         
                         if shop.cid == 1:
                             credits = shopattr.price * orderitem['num']
                             
                             if credits > user.credit:
                                 OrderItem.delete().where(OrderItem.id == orderitem['id']).execute()
                             else:
                                 user = User.get(id = user.id)
                                 user.credit = user.credit - credits
                                 user.save()
                                 
                                 clog = CreditLog()
                                 clog.uid = user.id
                                 clog.mobile = user.mobile
                                 clog.ctype = 1
                                 clog.affect = int(credits)
                                 clog.log = u"购买" + shop.name
                                 clog.save()
                                 
                                 self.session['user'] = user
                                 self.session.save()
                                 
                         sname = shopattr.name
                         
                     #body = body + shop.name + " " + sname + " " + str(orderitem['num']) + "个\n"
                     body = body + shop.name + " " + sname + " " + str(orderitem['num'])
                 except Exception, ex:
                     logging.error(ex)
             
             tn = "U%d-S%d" % (user.id, order.id)
             
             if int(payment) == 1:
                 self.redirect("/alipay/topay?tn=%s&body=%s&price=%f" % (tn, body, order.price))
             else:
                 self.flash(u"请选择地址和收货方式")
                 self.redirect("/user/orders")
         else:
Пример #13
0
 def load_dist(jd):
     return Distribution(jd["from"], jd["probs"])
Пример #14
0
    def post(self):
        order = None
        user = self.get_current_user()

        try:
            order = Order.get(uid=user.id, status=0)

            mobile = self.get_argument("mobile", user.mobile)
            uaid = self.get_argument("uaid", None)
            distrid = self.get_argument("distrid", None)
            day = self.get_argument(
                "day",
                datetime.date.today() + datetime.timedelta(days=1))
            hour = int(self.get_argument("hour", 10))
            payment = self.get_argument("payment", 0)
            message = self.get_argument("message", "")
            isinvoice = self.get_argument("isinvoice", 0)
            invoicesub = self.get_argument("invoicesub", 0)
            invoicename = self.get_argument("invoicename", "")
            invoicecontent = self.get_argument("payment", 1)
            shippingprice = self.get_argument("shippingprice", 0.0)

            if uaid and distrid:
                try:
                    distrib = Distribution.get(id=distrid)
                    shippingprice = distrib.price
                except:
                    pass

                order.mobile = mobile
                order.uaid = uaid
                order.distrid = distrid
                order.distribbed = "%s %d:00:00" % (str(day), hour)
                order.payment = payment
                order.message = message

                order.isinvoice = isinvoice

                if isinvoice:
                    order.invoicesub = invoicesub
                    order.invoicename = invoicename
                    order.invoicecontent = invoicecontent

                order.shippingprice = shippingprice

                order.save()

                body = ""
                for orderitem in OrderItem.select().where(
                        OrderItem.oid == order.id).dicts():

                    try:
                        shop = Shop.get(id=orderitem['sid'])

                        sname = ""
                        if orderitem['said'] > 0:
                            shopattr = ShopAttr.get(id=orderitem['said'])

                            if shop.cid == 1:
                                credits = shopattr.price * orderitem['num']

                                if credits > user.credit:
                                    OrderItem.delete().where(
                                        OrderItem.id ==
                                        orderitem['id']).execute()
                                else:
                                    user = User.get(id=user.id)
                                    user.credit = user.credit - credits
                                    user.save()

                                    clog = CreditLog()
                                    clog.uid = user.id
                                    clog.mobile = user.mobile
                                    clog.ctype = 1
                                    clog.affect = int(credits)
                                    clog.log = u"购买" + shop.name
                                    clog.save()

                                    self.session['user'] = user
                                    self.session.save()

                            sname = shopattr.name

                        body = body + shop.name + " " + sname + " " + str(
                            orderitem['num']) + "个\n"
                    except Exception, ex:
                        logging.error(ex)

                tn = "U%d-S%d" % (user.id, order.id)

                if int(payment) == 1:
                    self.redirect("/alipay/topay?tn=%s&body=%s&price=%f" %
                                  (tn, body, order.price))
                else:
                    self.flash(u"请选择地址和收货方式")
                    self.redirect("/user/orders")
            else:
Пример #15
0
 def get(self, did):
     Distribution.delete().where(Distribution.id == did).execute()
     self.memcachedb.remove('distributions')
     self.flash(u"栏目配送方式成功")
     self.redirect(self.request.headers["Referer"])