def get(self, ename): try: shop = Shop.get(ename=ename) shop.views = shop.views + 1 shop.save() category = Category.get(id=shop.cid) except: raise HTTPError(404) return categoryattrs = CategoryAttr.select().where( CategoryAttr.cid == shop.cid) shopattrs = ShopAttr.select().where(ShopAttr.sid == shop.id) if shop.args: shop.args = simplejson.loads(shop.args) pics = ShopPic.select().where(ShopPic.sid == shop.id) recomshops = Shop.select().where((Shop.status == 1) & (Shop.id != shop.id)).paginate( 1, 5) self.render("shop/shop.html", shop=shop, category=category, categoryattrs=categoryattrs, shopattrs=shopattrs, pics=pics, recomshops=recomshops)
def get(self): orderitems = [] user = self.current_user try: order = Order.get(uid=user.id, status=0) 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']) orderitems.append(orderitem) except: pass except: order = Order() ashops = Shop.select().where((Shop.cid == 2) & (Shop.status != 9)) self.render("shop/order.html", orderitems=orderitems, order=order, ashops=ashops)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select( Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by( Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) ccategory = None keyword = self.get_argument("keyword", None) page = int(self.get_argument("page", 1)) order = self.get_argument("order", None) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price) total = sq.count() if ccategory: sq = sq.where((Shop.cid == ccategory.id) & (Shop.status != 9)) elif keyword: keyword = "%" + keyword + "%" sq = sq.where((Shop.name % keyword) & (Shop.status != 9)) else: sq = sq.where((Shop.cid != 2) & (Shop.status != 9)) if order: sq = sq.order_by(Shop.orders.desc()) else: sq = sq.order_by(Shop.views.desc()) shops = [] for shop in sq.paginate(page, pagesize): shop.price = shop.price.split("~")[0] shops.append(shop) self.render("responsive/index.html", ads=ads, newest=newest, recomm=recomm, ccategory=ccategory, categorys=categorys, shops=shops, total=total, page=page, pagesize=pagesize)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by(Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) self.render("site/index.html", ads = ads, newest = newest, recomm = recomm)
def post(self): result = {'status': False, 'msg': 0} user = self.get_current_user() if user: sid = int(self.get_argument("sid", 0)) said = int(self.get_argument("said", 0)) num = int(self.get_argument("num", 1)) #判断商品是否下架 if sid > 0 and said > 0 and num > 0: try: Shop.get(id=sid) ShopAttr.get(id=said) #判断是否有未使用的订单或生成新订单 try: try: order = Order.get(uid=user.id, status=0) except: order = Order() order.uid = user.id order.mobile = user.mobile order.ordered = int(time.time()) try: order.save() except Exception, ex: logging.error(ex) try: orderitem = OrderItem.get(oid=order.id, sid=sid, said=said) except: orderitem = OrderItem() orderitem.oid = order.id orderitem.sid = sid orderitem.said = said orderitem.num = orderitem.num + num orderitem.save() result['status'] = True result['msg'] = 200 except Exception, ex: logging.error(ex) result['msg'] = 500 except:
def post(self): result = {'status' : False, 'msg' : 0} user = self.get_current_user() if user: sid = int(self.get_argument("sid", 0)) said = int(self.get_argument("said", 0)) num = int(self.get_argument("num", 1)) #判断商品是否下架 if sid > 0 and said > 0 and num > 0: try: Shop.get(id = sid) ShopAttr.get(id = said) #判断是否有未使用的订单或生成新订单 try: try: order = Order.get(uid = user.id, status = 0) except: order = Order() order.uid = user.id order.mobile = user.mobile order.ordered = int(time.time()) try: order.save() except Exception, ex: logging.error(ex) try: orderitem = OrderItem.get(oid = order.id, sid = sid, said = said) except: orderitem = OrderItem() orderitem.oid = order.id orderitem.sid = sid orderitem.said = said orderitem.num = orderitem.num + num orderitem.save() result['status'] = True result['msg'] = 200 except Exception, ex: logging.error(ex) result['msg'] = 500 except:
def get(self, oid): orderitems = [] price = 0.0 credit = 0.0 order = None try: order = Order.get(id = oid) print order.id for orderitem in OrderItem.select().where(OrderItem.oid == order.id).dicts(): try: orderitem['shop'] = Shop.get(id = orderitem['sid']) _oiprice = orderitem['shop'].price if orderitem['said'] > 0: orderitem['shopattr'] = ShopAttr.get(id = orderitem['said']) if orderitem['shop'].cid == 1: _oicredit = orderitem['shopattr'].price credit = credit + _oicredit * orderitem['num'] _oiprice = orderitem['shopattr'].price else: _oiprice = orderitem['shopattr'].price else: _oiprice = float(_oiprice) orderitems.append(orderitem) price = price + float(_oiprice) * orderitem['num'] except: pass print price except: pass self.render("/responsive/user_confirmorder.html", order = order, credit = credit, orderitems = orderitems)
def post(self, said): try: shopattr = ShopAttr.get(id = said) shop = Shop.get(id = shopattr.sid) except: self.flash("此商品不存在") self.redirect("/admin/shops") return name = self.get_argument("name", None) price = float(str(self.get_argument("price", 0.0))) order = int(self.get_argument("order", 1)) shopattr.name = name shopattr.price = price shopattr.order = order try: shopattr.validate() shopattr.save() self.flash(u"规格%s修改成功" % name) self.redirect("/admin/shopattrs/%d" % int(shopattr.sid) ) return except Exception, ex: self.flash(str(ex))
def get(self): page = int(self.get_argument("page", 1)) cid = int(self.get_argument("cid", 0)) status = int(self.get_argument("status", 0)) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select() if cid > 0: sq = sq.where(Shop.cid == cid) if status > 0: sq = sq.where(Shop.status == status) total = sq.count() shops = sq.paginate(page, pagesize) self.render('admin/shop.html', categorys=categorys, shops=shops, total=total, page=page, pagesize=pagesize)
def get(self, sid): try: shop = Shop.get(id=sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return try: category = Category.get(id=shop.cid) except: pass categoryattrs = CategoryAttr.select().where( CategoryAttr.cid == shop.cid) pics = [ shoppic.path for shoppic in ShopPic.select().where(ShopPic.sid == sid) ] shop.args = simplejson.loads(shop.args) self.render('admin/editshop.html', shop=shop, pics=pics, category=category, categoryattrs=categoryattrs)
def post(self, said): try: shopattr = ShopAttr.get(id=said) shop = Shop.get(id=shopattr.sid) except: self.flash("此商品不存在") self.redirect("/admin/shops") return name = self.get_argument("name", None) price = float(str(self.get_argument("price", 0.0))) order = int(self.get_argument("order", 1)) shopattr.name = name shopattr.price = price shopattr.order = order try: shopattr.validate() shopattr.save() self.flash(u"规格%s修改成功" % name) self.redirect("/admin/shopattrs/%d" % int(shopattr.sid)) return except Exception, ex: self.flash(str(ex))
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)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select( Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by( Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) self.render("site/index.html", ads=ads, newest=newest, recomm=recomm)
def get(self, sid): try: shop = Shop.get(id = sid) except: self.flash("此商品不存在") self.redirect("/admin/shops") return self.render('admin/addshopattr.html', shop = shop, maxorder = ShopAttr.maxorder(sid))
def get(self): page = int(self.get_argument("page", 1)) pagesize = self.settings['admin_pagesize'] sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1) total = sq.count() shops = sq.paginate(page, pagesize) self.render("shop/recomm.html", shops = shops, total = total, page = page, pagesize = pagesize)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by(Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) ccategory= None keyword = self.get_argument("keyword", None) page = int(self.get_argument("page", 1)) order = self.get_argument("order", None) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price) total = sq.count() if ccategory: sq = sq.where((Shop.cid == ccategory.id) & (Shop.status != 9)) elif keyword: keyword = "%" + keyword + "%" sq = sq.where((Shop.name % keyword) & (Shop.status != 9)) else: sq = sq.where((Shop.cid != 2) & (Shop.status != 9)) if order: sq = sq.order_by(Shop.orders.desc()) else: sq = sq.order_by(Shop.views.desc()) shops = [] for shop in sq.paginate(page, pagesize): shop.price = shop.price.split("~")[0] shops.append(shop) self.render("responsive/index.html", ads = ads, newest = newest, recomm = recomm,ccategory = ccategory, categorys = categorys, shops = shops, total = total, page = page, pagesize = pagesize)
def get(self): orderitems = [] user = self.current_user order = None distributions = self.get_distributions() price = 0.0 credit = 0.0 try: order = Order.get(uid=user.id, status=0) try: mobile = '18014349809' sendmsg(self.settings, mobile, '新订单') except: pass for orderitem in OrderItem.select().where( OrderItem.oid == order.id).dicts(): try: orderitem['shop'] = Shop.get(id=orderitem['sid']) _oiprice = orderitem['shop'].price if orderitem['said'] > 0: orderitem['shopattr'] = ShopAttr.get( id=orderitem['said']) if orderitem['shop'].cid == 1: _oicredit = orderitem['shopattr'].price credit = credit + _oicredit * orderitem['num'] else: _oiprice = orderitem['shopattr'].price else: _oiprice = float(_oiprice) orderitems.append(orderitem) price = price + _oiprice * orderitem['num'] except: pass order.price = price order.save() except: pass if orderitems: self.render("shop/settle.html", tmday=datetime.date.today() + datetime.timedelta(days=1), order=order, orderitems=orderitems, distributions=distributions.values(), credit=credit)
def get(self, sid): try: shop = Shop.get(id = sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return shopattrs = [shopattr for shopattr in ShopAttr.select().where(ShopAttr.sid == sid)] self.render('admin/shopattr.html', shop = shop, shopattrs = shopattrs)
def get(self, said): try: shopattr = ShopAttr.get(id=said) shop = Shop.get(id=shopattr.sid) except: self.flash("此商品不存在") self.redirect("/admin/shops") return self.render('admin/editshopattr.html', shop=shop, shopattr=shopattr)
def get(self, said): try: shopattr = ShopAttr.get(id = said) shop = Shop.get(id = shopattr.sid) except: self.flash("此商品不存在") self.redirect("/admin/shops") return self.render('admin/editshopattr.html', shop = shop, shopattr = shopattr)
def get(self, ename): try: shop = Shop.get(ename = ename) shop.views = shop.views + 1 shop.save() category = Category.get(id = shop.cid) except: raise HTTPError(404) return categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid) shopattrs = ShopAttr.select().where(ShopAttr.sid == shop.id) if shop.args: shop.args = simplejson.loads(shop.args) pics = ShopPic.select().where(ShopPic.sid == shop.id) recomshops = Shop.select().where((Shop.status == 1) & (Shop.id != shop.id)).paginate(1, 5) self.render("shop/shop.html", shop = shop, category = category, categoryattrs = categoryattrs, shopattrs = shopattrs, pics = pics, recomshops = recomshops)
def get(self): user = self.get_current_user() status = self.get_argument("status", None) ft = (Order.uid == user.id) 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).dicts(): order['orderitems'] = [] 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']) except: break order['orderitems'].append(orderitem) if order['orderitems']: orders.append(order) else: Order.delete().where(Order.id == order['id']).execute() try: user = User.get(id=user.id) if user.order > 0: user.order = user.order - 1 user.save() self.session['user'] = user self.session.save() except: pass self.render('user/order.html', orders=orders, total=total, page=page, pagesize=pagesize)
def get(self): orderitems = [] user = self.current_user try: order = Order.get(uid = user.id, status = 0) 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']) orderitems.append(orderitem) except: pass except: order = Order() ashops = Shop.select().where((Shop.cid == 2) & (Shop.status != 9)) self.render("shop/order.html", orderitems = orderitems, order = order, ashops = ashops)
def get(self): page = int(self.get_argument("page", 1)) pagesize = self.settings['admin_pagesize'] sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1) total = sq.count() shops = sq.paginate(page, pagesize) self.render("shop/recomm.html", shops=shops, total=total, page=page, pagesize=pagesize)
def get(self): user = self.get_current_user() status = self.get_argument("status", None) ft = (Order.uid == user.id) 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).dicts(): order['orderitems'] = [] 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']) except: break order['orderitems'].append(orderitem) if order['orderitems']: orders.append(order) else: Order.delete().where(Order.id == order['id']).execute() try: user = User.get(id = user.id) if user.order > 0: user.order = user.order - 1 user.save() self.session['user'] = user self.session.save() except: pass self.render('user/order.html', orders = orders, total = total, page = page, pagesize = pagesize)
def get(self): orderitems = [] user = self.current_user order = None distributions = self.get_distributions() price = 0.0 credit = 0.0 try: order = Order.get(uid = user.id, status = 0) try: mobile = '18014349809' sendmsg(self.settings, mobile, '新订单') except: pass for orderitem in OrderItem.select().where(OrderItem.oid == order.id).dicts(): try: orderitem['shop'] = Shop.get(id = orderitem['sid']) _oiprice = orderitem['shop'].price if orderitem['said'] > 0: orderitem['shopattr'] = ShopAttr.get(id = orderitem['said']) if orderitem['shop'].cid == 1: _oicredit = orderitem['shopattr'].price credit = credit + _oicredit * orderitem['num'] else: _oiprice = orderitem['shopattr'].price else: _oiprice = float(_oiprice) orderitems.append(orderitem) price = price + _oiprice * orderitem['num'] except: pass order.price = price order.save() except: pass if orderitems: self.render("shop/settle.html", tmday = datetime.date.today() + datetime.timedelta(days=1), order = order, orderitems = orderitems, distributions = distributions.values(), credit = credit)
def get_shop(shop_pub_key: str = Query(None, alias='shopPubKey')): shop = Shop.get(shop_pub_key=shop_pub_key) if not shop: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail='店舖不存在') version, server_secret_key = select( (k.version, k.server_secret_key) for k in Secret if k.shop == shop).order_by(desc(1)).first() box = SecretBox(SERVER_MASTER_SECRET) server_pub_key = b64encode( PrivateKey(box.decrypt(b64decode( server_secret_key))).public_key._public_key).decode('ascii') return ShopLoginRequest(name=shop.name, shop_pub_key=shop_pub_key, server_pub_key=server_pub_key)
def get(self, sid): try: shop = Shop.get(id = sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return if shop.status == 1: shop.status = 0 else: shop.status = 1 shop.save() self.flash(u"推荐商品%s成功" % shop.name, 'ok') self.redirect("/admin/shops")
def get(self, sid): try: shop = Shop.get(id=sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return if shop.status == 1: shop.status = 0 else: shop.status = 1 shop.save() self.flash(u"推荐商品%s成功" % shop.name, 'ok') self.redirect("/admin/shops")
def get(self): page = int(self.get_argument("page", 1)) pagesize = self.settings['admin_pagesize'] cq = Consult.select() total = cq.count() consults = [] for consult in cq.order_by(Consult.posted.desc(), Consult.replyed.asc()).paginate(page, pagesize).dicts(): try: shop = Shop.get(id = consult['sid']) except: shop = Shop consult['shop'] = shop consults.append(consult) self.render('admin/consult.html', consults = consults, total = total, page = page, pagesize = pagesize)
def get(self, slug): ccategory = None if slug: try: ccategory = Category.get(slug=slug) except: self.redirect("/list/") return keyword = self.get_argument("keyword", None) page = int(self.get_argument("page", 1)) order = self.get_argument("order", None) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price) total = sq.count() if ccategory: sq = sq.where((Shop.cid == ccategory.id) & (Shop.status != 9)) elif keyword: keyword = "%" + keyword + "%" sq = sq.where((Shop.name % keyword) & (Shop.status != 9)) else: sq = sq.where((Shop.cid != 2) & (Shop.status != 9)) if order: sq = sq.order_by(Shop.orders.desc()) else: sq = sq.order_by(Shop.views.desc()) shops = [] for shop in sq.paginate(page, pagesize): shop.price = shop.price.split("~")[0] shops.append(shop) self.render("shop/list.html", ccategory=ccategory, categorys=categorys, shops=shops, total=total, page=page, pagesize=pagesize)
def get(self): user = self.get_current_user() page = int(self.get_argument("page", 1)) pagesize = self.settings["admin_pagesize"] cq = Consult.select().where(Consult.uid == user.id) total = cq.count() consults = [] for consult in cq.paginate(page, pagesize).order_by(Consult.replyed.desc(), Consult.posted.desc()).dicts(): try: shop = Shop.get(id=consult["sid"]) except: shop = Shop consult["shop"] = shop consults.append(consult) self.render("user/consult.html", consults=consults, total=total, page=page, pagesize=pagesize)
def get(self, sid): try: shop = Shop.get(id = sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return try: category = Category.get(id = shop.cid) except: pass categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid) pics = [shoppic.path for shoppic in ShopPic.select().where(ShopPic.sid == sid)] shop.args = simplejson.loads(shop.args) self.render('admin/editshop.html', shop = shop, pics = pics, category = category, categoryattrs = categoryattrs)
def create_shop(shop_id, name, lat, lng, address_num=None, address_street=None, zipcode=None): """Create a shop, add to db, return shop.""" shop = Shop(shop_id=shop_id, name=name, address_num=address_num, address_street=address_street, zipcode=zipcode, lat=lat, lng=lng) db.session.add(shop) db.session.commit() return shop
def new_shop(req: ShopCreateRequest): try: b64decode(req.shop_pub_key) except binascii.Error: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail='公鑰錯誤') shop = Shop(name=req.name, shop_pub_key=req.shop_pub_key) private_key = PrivateKey.generate() box = SecretBox(SERVER_MASTER_SECRET) try: Secret(shop=shop, server_secret_key=b64encode( box.encrypt(private_key._private_key)).decode('ascii')) commit() except TransactionIntegrityError: rollback() raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail='公鑰已被使用') return b64encode(private_key.public_key._public_key).decode('ascii')
def get(self): page = int(self.get_argument("page", 1)) cid = int(self.get_argument("cid", 0)) status = int(self.get_argument("status", 0)) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select() if cid > 0: sq = sq.where(Shop.cid == cid) if status > 0: sq = sq.where(Shop.status == status) total = sq.count() shops = sq.paginate(page, pagesize) self.render('admin/shop.html', categorys = categorys, shops = shops, total = total, page = page, pagesize = pagesize)
def get(self, sid): #Shop.delete().where(Shop.id == sid).execute() #ShopPic.delete().where(ShopPic.sid == sid).execute() #ShopAttr.delete().where(ShopAttr.sid == sid).execute() try: shop = Shop.get(id=sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return if shop.status == 9: shop.status = 0 else: shop.status = 9 shop.save() self.flash(u"商品操作成功") self.redirect(self.request.headers["Referer"])
def get(self, sid): #Shop.delete().where(Shop.id == sid).execute() #ShopPic.delete().where(ShopPic.sid == sid).execute() #ShopAttr.delete().where(ShopAttr.sid == sid).execute() try: shop = Shop.get(id = sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return if shop.status == 9: shop.status = 0 else: shop.status = 9 shop.save() self.flash(u"商品操作成功") self.redirect(self.request.headers["Referer"])
def get(self, slug): ccategory= None if slug: try: ccategory = Category.get(slug = slug) except: self.redirect("/list/") return keyword = self.get_argument("keyword", None) page = int(self.get_argument("page", 1)) order = self.get_argument("order", None) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price) total = sq.count() if ccategory: sq = sq.where((Shop.cid == ccategory.id) & (Shop.status != 9)) elif keyword: keyword = "%" + keyword + "%" sq = sq.where((Shop.name % keyword) & (Shop.status != 9)) else: sq = sq.where((Shop.cid != 2) & (Shop.status != 9)) if order: sq = sq.order_by(Shop.orders.desc()) else: sq = sq.order_by(Shop.views.desc()) shops = [] for shop in sq.paginate(page, pagesize): shop.price = shop.price.split("~")[0] shops.append(shop) self.render("shop/list.html", ccategory = ccategory, categorys = categorys, shops = shops, total = total, page = page, pagesize = pagesize)
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)
def post(self, sid): try: shop = Shop.get(id=sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return try: category = Category.get(id=shop.cid) except: pass categoryattrs = CategoryAttr.select().where( CategoryAttr.cid == shop.cid) opics = [ shoppic.path for shoppic in ShopPic.select().where(ShopPic.sid == sid) ] cover = self.get_argument("cover", None) pics = self.get_argument("pics", None) name = self.get_argument("name", None) ename = self.get_argument("ename", None) price = self.get_argument("price", 0.0) views = int(self.get_argument("views", 0)) if category.id == 2: price = str(float(price)) level = int(self.get_argument("level", 3)) resume = self.get_argument("resume", "") intro = self.get_argument("intro", "") prompt = self.get_argument("prompt", "") try: shop.name = name shop.ename = ename shop.level = level shop.resume = resume shop.intro = intro shop.prompt = prompt shop.price = price shop.views = views args = {} for categoryattr in categoryattrs: caid = str(categoryattr.id) args['attr_' + caid] = self.get_argument('attr_' + caid, '') shop.args = simplejson.dumps(args) if pics: pics = pics.split(',') pics = [pic.replace('/upload/', '') for pic in pics] if not cover: cover = pics[0] if not cover: cover = '' shop.cover = cover.replace('/upload/', '') shop.validate() shop.save() if isinstance(pics, list): for pic in pics: if pic not in opics: shoppic = ShopPic() shoppic.sid = shop.id shoppic.path = pic shoppic.save() for pic in opics: if pic not in pics: ShopPic.delete().where(ShopPic.path == pic).execute() self.flash(u"修改商品%s成功" % name, 'ok') self.redirect("/admin/shops") return except Exception, ex: shop.args = simplejson.loads(shop.args) self.flash(str(ex))
session.commit() shop_handlings = [ {'url': 'https://www.kobu-teeversand.de', 'name': "Kobu Tee ® und Futon", 'spider': KobuSpider}, {'url': 'https://www.teehandel-kolodziej-shop.de/', 'name': "Teehandel Kolodziej e.K.", 'spider': KolodziejSpider}, {'url': 'https://www.nibelungentee.de', 'name': "Nibelungentee internet-connect GmbH", 'spider': NibelungenSpider}, {'url': 'https://www.sunday.de', 'name': "Sunday Natural Products GmbH", 'spider': SundaySpider}, {'url': 'https://www.teaworld.de/', 'name': "Teaworld OHG", 'spider': TeaworldSpider} ] for shop_handling in shop_handlings: shop = session.query(Shop).filter_by(name=shop_handling['name']).first() if not shop: shop = Shop(name=shop_handling['name'], url=shop_handling['url']) session.add(shop) try: spider = shop_handling['spider'](shop_handling['url'], logging) products = spider.get_products() for product in products: save_product(session, product, shop) session.commit() except: logging.info("exception in spider {}".format(shop_handling.spider)) pass # clean max_date = session.query(func.max(Price.date)).all()[0] logging.info("delete products with date < {}".format(max_date)) print("delete products with date < {}".format(max_date))
def get(self): orderitems = [] user = self.current_user order = None distributions = self.get_distributions() price = 0.0 credit = 0.0 try: order = Order.get(uid=user.id, status=0) print order.id ''' try: mobile = '18014349809' sendmsg(self.settings, mobile, '新订单') except: pass ''' for orderitem in OrderItem.select().where( OrderItem.oid == order.id).dicts(): try: orderitem['shop'] = Shop.get(id=orderitem['sid']) _oiprice = orderitem['shop'].price if orderitem['said'] > 0: orderitem['shopattr'] = ShopAttr.get( id=orderitem['said']) if orderitem['shop'].cid == 1: _oicredit = orderitem['shopattr'].price credit = credit + _oicredit * orderitem['num'] _oiprice = orderitem['shopattr'].price else: _oiprice = orderitem['shopattr'].price else: _oiprice = float(_oiprice) orderitems.append(orderitem) price = price + float(_oiprice) * orderitem['num'] except: pass print price price_pay = str(int(price * 100)) print 'price_pay:' + price_pay openid = user.openid print 'wx_pay:' + openid jsApi = JsApi_pub() unifiedOrder = UnifiedOrder_pub() unifiedOrder.setParameter("openid", openid) #商品描述 unifiedOrder.setParameter("body", "菜市优品购物") #商品描述 timeStamp = time.time() print timeStamp out_trade_no = "{0}{1}".format(WxPayConf_pub.APPID, int(timeStamp * 100)) unifiedOrder.setParameter("out_trade_no", out_trade_no) #商户订单号 print 'out_trade_no:' + out_trade_no Order.update(wxid=out_trade_no).where( Order.id == order.id).execute() unifiedOrder.setParameter("total_fee", price_pay) #总金额 print WxPayConf_pub.NOTIFY_URL unifiedOrder.setParameter("notify_url", WxPayConf_pub.NOTIFY_URL) #通知地址 unifiedOrder.setParameter("trade_type", "JSAPI") #交易类型 prepay_id = unifiedOrder.getPrepayId() jsApi.setPrepayId(prepay_id) jsApiParameters = jsApi.getParameters() print jsApiParameters appid = json.loads(jsApiParameters).get("appId") timestamp = json.loads(jsApiParameters).get("timeStamp") noncestr = json.loads(jsApiParameters).get("nonceStr") package = json.loads(jsApiParameters).get("package") signtype = json.loads(jsApiParameters).get("signType") paysign = json.loads(jsApiParameters).get("paySign") print appid + timestamp + noncestr + package + signtype + paysign if orderitems: self.render("/responsive/wxpay.html", tmday=datetime.date.today() + datetime.timedelta(days=1), order=order, orderitems=orderitems, distributions=distributions.values(), credit=credit, appid=appid, timestamp=timestamp, noncestr=noncestr, package=package, signtype=signtype, paysign=paysign) except: pass
import sqlalchemy as sa from sqlalchemy.orm import Query, scoped_session, sessionmaker import datetime from model import Publisher, Book, Shop, Stock, Sale from engine_session import engine, Session #################### setup some data ###################### pub1 = Publisher(name='МИФ') sa.session.add(pub1) sa.session.commit() book1 = Book(title='45 татуировок менеджера', id_publisher=0) sa.session.add(book1) sa.session.commit() sh1 = Shop(name='Буквоед-1') sa.session.add(sh1) sa.session.commit() st1 = Stock(id_book=0, id_shop=0, count=100) sa.session.add(st1) sa.session.commit() sale1 = Sale(price=570, date_sale=datetime.today(), id_stock=0, count=84) sa.session.add(sale1) sa.session.commit()
def post(self, cid): try: category = Category.get(id = cid) except: self.flash("此分类不存在") self.redirect("/admin/addshop") return categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == cid) cover = self.get_argument("cover", None) pics = self.get_argument("pics", None) name = self.get_argument("name", None) ename = self.get_argument("ename", None) price = str(float(str(self.get_argument("price", 0.0)))) level = int(self.get_argument("level", 3)) resume = self.get_argument("resume", "") intro = self.get_argument("intro", "") prompt = self.get_argument("prompt", "") views = int(self.get_argument("views", 0)) try: shop = Shop() shop.name = name shop.ename = ename shop.cid = cid shop.level = level shop.resume = resume shop.intro = intro shop.prompt = prompt shop.price = price shop.views = views args = {} for categoryattr in categoryattrs: caid = str(categoryattr.id) args['attr_' + caid] = self.get_argument('attr_' + caid, '') shop.args = simplejson.dumps(args) if pics: pics = pics.split(',') pics = [pic.replace('/upload/', '') for pic in pics] if not cover: cover = pics[0] if not cover: cover = '' shop.cover = cover.replace('/upload/', '') shop.validate() shop.save() if isinstance(pics, list): for pic in pics: shoppic = ShopPic() shoppic.sid = shop.id shoppic.path = pic shoppic.save() self.flash("添加商品%s成功" % name, 'ok') if category.id == 2: self.redirect("/admin/shops") else: self.redirect("/admin/addshopattr/" + str(shop.id)) return except Exception as ex: self.flash(str(ex)) self.render('admin/addcshop.html', category = category, categoryattrs = categoryattrs)
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:
def load_data(data_path): """ (str) -> set Loads the data from the csv file. It creates and returns a set of all the Products. """ shop_dict = {} log.info('Loading data...') start_time = int(round(time() * 1000)) # Load shops try: with open(data_path + '/shops.csv') as shop_file: reader = csv.DictReader(shop_file) for row in reader: shop = Shop(row['id'], row['name'], row['lat'], row['lng']) shop_dict[shop.id] = shop except IOError as e: log.error(e) shop_time = int(round(time() * 1000)) log.debug('Loaded shops in {0} ms'.format((shop_time - start_time))) # Load tags tag_dict = {} try: with open(data_path + '/tags.csv') as tag_file: reader = csv.DictReader(tag_file) for row in reader: tag_dict[row['id']] = row['tag'] with open(data_path + '/taggings.csv') as taggings_file: reader = csv.DictReader(taggings_file) for row in reader: if row['shop_id'] in shop_dict: shop_dict[row['shop_id']].tags.add(tag_dict[row['tag_id']]) except IOError as e: log.error(e) tag_time = int(round(time() * 1000)) log.debug('Loaded tags in {0} ms'.format((tag_time - start_time))) # Load products products = set() try: with open(data_path + '/products.csv') as product_file: reader = csv.DictReader(product_file) for row in reader: product = Product(row['id'], row['title'], row['popularity'], row['quantity']) if row['shop_id'] in shop_dict: product.shop = shop_dict[row['shop_id']] products.add(product) except IOError as e: log.error(e) product_time = int(round(time() * 1000)) log.debug('Loaded products in {0} ms'.format((product_time - tag_time))) end_time = int(round(time() * 1000)) log.info('Loaded data in {0} ms'.format((end_time - start_time))) return products
def post(self, sid): try: shop = Shop.get(id = sid) except: self.flash("此商品不存在") self.redirect("/admin/addshop") return try: category = Category.get(id = shop.cid) except: pass categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid) opics = [shoppic.path for shoppic in ShopPic.select().where(ShopPic.sid == sid)] cover = self.get_argument("cover", None) pics = self.get_argument("pics", None) name = self.get_argument("name", None) ename = self.get_argument("ename", None) price = self.get_argument("price", 0.0) views = int(self.get_argument("views", 0)) if category.id == 2: price = str(float(price)) level = int(self.get_argument("level", 3)) resume = self.get_argument("resume", "") intro = self.get_argument("intro", "") prompt = self.get_argument("prompt", "") try: shop.name = name shop.ename = ename shop.level = level shop.resume = resume shop.intro = intro shop.prompt = prompt shop.price = price shop.views = views args = {} for categoryattr in categoryattrs: caid = str(categoryattr.id) args['attr_' + caid] = self.get_argument('attr_' + caid, '') shop.args = simplejson.dumps(args) if pics: pics = pics.split(',') pics = [pic.replace('/upload/', '') for pic in pics] if not cover: cover = pics[0] if not cover: cover = '' shop.cover = cover.replace('/upload/', '') shop.validate() shop.save() if isinstance(pics, list): for pic in pics: if pic not in opics: shoppic = ShopPic() shoppic.sid = shop.id shoppic.path = pic shoppic.save() for pic in opics: if pic not in pics: ShopPic.delete().where(ShopPic.path == pic).execute() self.flash(u"修改商品%s成功" % name, 'ok') self.redirect("/admin/shops") return except Exception, ex: shop.args = simplejson.loads(shop.args) self.flash(str(ex))
def get(self): orderitems = [] user = self.current_user order = None distributions = self.get_distributions() price = 0.0 credit = 0.0 try: order = Order.get(uid = user.id, status = 0) print order.id ''' try: mobile = '18014349809' sendmsg(self.settings, mobile, '新订单') except: pass ''' for orderitem in OrderItem.select().where(OrderItem.oid == order.id).dicts(): try: orderitem['shop'] = Shop.get(id = orderitem['sid']) _oiprice = orderitem['shop'].price if orderitem['said'] > 0: orderitem['shopattr'] = ShopAttr.get(id = orderitem['said']) if orderitem['shop'].cid == 1: _oicredit = orderitem['shopattr'].price credit = credit + _oicredit * orderitem['num'] _oiprice = orderitem['shopattr'].price else: _oiprice = orderitem['shopattr'].price else: _oiprice = float(_oiprice) orderitems.append(orderitem) price = price + float(_oiprice) * orderitem['num'] except: pass print price price_pay = str(int(price*100)) print 'price_pay:' + price_pay openid = user.openid print 'wx_pay:'+ openid jsApi = JsApi_pub() unifiedOrder = UnifiedOrder_pub() unifiedOrder.setParameter("openid",openid) #商品描述 unifiedOrder.setParameter("body","菜市优品购物") #商品描述 timeStamp = time.time() print timeStamp out_trade_no = "{0}{1}".format(WxPayConf_pub.APPID, int(timeStamp*100)) unifiedOrder.setParameter("out_trade_no", out_trade_no) #商户订单号 print 'out_trade_no:' + out_trade_no Order.update(wxid = out_trade_no).where(Order.id == order.id).execute() unifiedOrder.setParameter("total_fee", price_pay) #总金额 print WxPayConf_pub.NOTIFY_URL unifiedOrder.setParameter("notify_url", WxPayConf_pub.NOTIFY_URL) #通知地址 unifiedOrder.setParameter("trade_type", "JSAPI") #交易类型 prepay_id = unifiedOrder.getPrepayId() jsApi.setPrepayId(prepay_id) jsApiParameters = jsApi.getParameters() print jsApiParameters appid = json.loads(jsApiParameters).get("appId") timestamp = json.loads(jsApiParameters).get("timeStamp") noncestr = json.loads(jsApiParameters).get("nonceStr") package = json.loads(jsApiParameters).get("package") signtype = json.loads(jsApiParameters).get("signType") paysign = json.loads(jsApiParameters).get("paySign") print appid + timestamp + noncestr + package + signtype +paysign if orderitems: self.render("/responsive/wxpay.html", tmday = datetime.date.today() + datetime.timedelta(days=1), order = order, orderitems = orderitems, distributions = distributions.values(), credit = credit, appid = appid, timestamp = timestamp, noncestr = noncestr, package = package, signtype = signtype, paysign = paysign) except: pass
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: