def get(self, pid, status): page = int( self.get_argument("page", '1') if len(self.get_argument("page", '1')) > 0 else '1') cid = int(self.get_argument("cid", 0)) keyword = self.get_argument("keyword", None) ds = self.get_argument("ds", None) s = int(self.get_argument("status", 1)) p = Product.get(Product.id == pid) content = {} content['operatetype'] = '修改产品状态' content['pid'] = pid content['old_status'] = p.status content['current_status'] = status p.status = status p.updatedtime = int(time.time()) p.updatedby = self.get_store_user() p.save() AdminLog.create(user=self.get_store_user(), dotime=int(time.time()), content=content) self.redirect('/store/products?page=' + str(page) + '&pcategory=' + str(cid) + '&keyword=' + keyword + '&defaultstandard=' + str(ds) + '&status=' + str(s))
def get(self, pid): if pid == '0': p = None ps = None else: p = Product.get(Product.id == pid) ps = ProductStandard.get(ProductStandard.id == p.defaultstandard) categorys = Category_Store.select().where( Category_Store.store == self.get_store_user().store.id) self.render('store/product/product_edit.html', p=p, ps=ps, categorys=categorys, active='ps')
def get(self): key = self.request.get('key') product = Product.get(key) if not product: return if product.image_url and not product.image_data: fetcher = ImageFetcher() blob_key = fetcher.FetchAndSaveImage(product.image_url) if blob_key: product.image_data = blob_key product.image_serving_url = images.get_serving_url(blob_key) product.put() return
def check_buy_quantity(pid, uid, c, is_cart): result = {'flag': 0, 'quantity': 0} try: begin = time.mktime( time.strptime( time.strftime("%Y-%m-%d", time.localtime(time.time())), "%Y-%m-%d")) end = time.mktime( time.strptime( time.strftime("%Y-%m-%d 23:59:59", time.localtime(time.time())), "%Y-%m-%d %H:%M:%S")) item = OrderItem.select( OrderItem, Order).join(Order).where((Order.ordered > begin) & (Order.ordered < end) & (Order.status > 0) & (Order.status < 5) & (Order.user == uid) & (OrderItem.product == pid) & (OrderItem.item_type == 0)) cart = Cart.select().where((Cart.product == pid) & (Cart.user == uid) & (Cart.type == 0)) cart_c = 0 for n in cart: cart_c += n.quantity p = Product.get(id=pid) quantity = 0 for n in item: quantity += n.quantity if is_cart == 1: # 如果等于1 表示是购物车中操作 count = quantity + c else: count = quantity + c + cart_c if count > p.xgperusernum: result['flag'] = 1 result['quantity'] = p.xgperusernum - quantity if p.xgperusernum == 0: result['flag'] = 0 return result except Exception, ex: return result
def post(self, pid): store_user = self.get_store_user() resume = self.get_argument("presume", '') name = self.get_argument("pname", '') tags = self.get_argument("tags", '') intro = self.get_argument("pintro", '') quantity = float(self.get_argument("quantity", '0')) producer = self.get_argument("pproducer", '') metakeywords = self.get_argument("pmetakeywords", '') metadescription = self.get_argument("pmetadescription", '') metatitle = self.get_argument("pmetatitle", '') category = int(self.get_argument("pcategory", '1')) quality = self.get_argument("quality", '') standard = self.get_argument("standard", '') status = self.get_argument("standard", '1') prompt = self.get_argument("prompt", '') psname = self.get_argument("sname", '') psprice = float(self.get_argument("sprice", '0')) content = {} sku = int(time.time()) try: if pid == '0': p = Product() p.sku = str(sku) if not os.path.exists('upload/' + p.sku): os.mkdir('upload/' + p.sku) p.created = int(time.time()) p.categoryback = 1 content['operatetype'] = '创建产品' else: p = Product.get(Product.id == pid) content['operatetype'] = '修改产品' content['oldproduct'] = simplejson.dumps(str(p)) p.args = 'C' p.categoryfront = 166 #数据库内置分类 经销商 p.updatedtime = int(time.time()) p.updatedby = self.get_store_user() p.resume = resume p.name = name p.tags = tags p.intro = intro p.producer = producer p.metakeywords = metakeywords p.metadescription = metadescription p.metatitle = metatitle p.marketprice = 0 p.quantity = quantity p.quality = quality p.standard = standard p.xgperusernum = 50 p.xgtotalnum = 99999 p.status = int(status) # 默认上架 p.store = store_user.store.id p.is_store = 1 p.category_store = category p.prompt = prompt p.validate() p.save() if pid == '0': s = ProductStandard() else: s = ProductStandard.get( ProductStandard.id == p.defaultstandard) s.name = psname s.tags = '' s.price = psprice s.orginalprice = psprice s.weight = 0 s.ourprice = psprice s.relations = [] s.product = p s.save() s.relations = '[' + str(s.id) + ']' s.save() p.defaultstandard = s.id p.save() self.flash("保存成功") content['pid'] = p.id AdminLog.create(user=self.get_store_user(), dotime=int(time.time()), content=content) self.redirect('/store/product/' + str(p.id)) except Exception, e: self.flash("保存失败,请联系管理员" + e.message) self.redirect('/store/product/0')
def render(self): user = self.current_user client_car = self.handler.get_secure_cookie('car', None) list = [] count = 0 totalprice = 0 carproduct = { 'name': '', 'price': 0, 'oprice': 0, 'quantity': 0, 'imgurl': '', 'pid': 0, 'standardname': '', 'sku': '', 'psid': '', 'is_activity': 0, 'psid': 0, 'gid': 0, 'store_name': '', 'ourprice': 0, 'pf_price': 0 } carItems = [] giftItems = [] if client_car: carItems = simplejson.loads(client_car) if user: for pro in carItems: cart = Cart.select().where( (Cart.user == user.id) & (Cart.product == pro['pid'])) # & (Cart.type != 2) if cart.count() > 0: cart[0].quantity += int(pro['quantity']) cart[0].save() else: c1 = Cart() c1.user = user.id c1.product = pro['pid'] c1.product_standard = pro['psid'] c1.quantity = pro['quantity'] c1.save() cartitems = Cart.select().where( (Cart.user == self.current_user.id)) # & (Cart.type != 2) self.handler.clear_cookie('car') for i in cartitems: c = copy.deepcopy(carproduct) c['name'] = i.product.name pa = check_activity(i.product.id) if pa: c['price'] = pa["price"] c['quantity'] = 1 c['is_activity'] = 1 else: if i.type == 3 and i.product_offline: c['price'] = i.product_offline.price c['store_name'] = i.product_offline.store.name totalprice += float(i.product_offline.price) * float( i.quantity) elif i.type == 2: pr = Product_Reserve.select().where( Product_Reserve.product_standard == i.product_standard) if pr.count() > 0: c['price'] = pr[0].price totalprice += float(pr[0].price) * float( i.quantity) else: if user.grade == 0: c['price'] = i.product_standard.price totalprice += float( i.product_standard.price) * float(i.quantity) elif user.grade == 1: c['price'] = i.product_standard.ourprice totalprice += float( i.product_standard.ourprice) * float( i.quantity) elif user.grade == 1: c['price'] = i.product_standard.pf_price totalprice += float( i.product_standard.pf_price) * float( i.quantity) c['quantity'] = i.quantity c['oprice'] = i.product_standard.orginalprice c['ourprice'] = i.product_standard.ourprice c['pf_price'] = i.product_standard.pf_price c['standardname'] = i.product_standard.name c['psid'] = i.product_standard.id c['imgurl'] = i.product.cover c['pid'] = i.product.id c['sku'] = i.product.sku c['psid'] = i.product_standard.id count += int(i.quantity) list.append(c) current_time = time.strptime( time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), '%Y-%m-%d %H:%M:%S') giftitem = Gift.select().where( (Gift.user == self.current_user.id) & (Gift.status == 0) & (Gift.end_time > time.mktime(current_time))) for i in giftitem: c = copy.deepcopy(carproduct) c['name'] = i.product.name c['price'] = 0.0 c['quantity'] = i.quantity c['oprice'] = i.product_standard.orginalprice * i.product_standard.weight / 500 c['ourprice'] = i.product_standard.ourprice c['pf_price'] = i.product_standard.pf_price c['standardname'] = i.product_standard.name c['psid'] = i.product_standard.id c['imgurl'] = i.product.cover c['pid'] = i.product.id c['sku'] = i.product.sku c['is_activity'] = 1 c['gid'] = i.id if i.product.status == 1: c['status'] = 1 else: c['status'] = 2 giftItems.append(c) count += i.quantity else: for i in carItems: c = copy.deepcopy(carproduct) p = Product.get(id=i['pid']) ps = ProductStandard.get(id=i['psid']) c['name'] = p.name pa = check_activity(i['pid']) if pa: c['price'] = pa["price"] c['quantity'] = 1 c['is_activity'] = 1 else: c['price'] = ps.price c['quantity'] = i['quantity'] c['oprice'] = ps.orginalprice c['standardname'] = ps.name c['psid'] = ps.id c['imgurl'] = p.cover c['pid'] = i['pid'] c['sku'] = p.sku c['psid'] = i['psid'] totalprice += float(ps.price) * float(i['quantity']) count += int(i['quantity']) list.append(c) return self.render_string("layout/mycart.html", cartitems=list, count=count, gift_items=giftItems, totalprice=totalprice)