def remove(): """删除广告""" resjson.action_code = 10 adv_id = toint(request.args.get('adv_id', '0')) if adv_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) adv = Adv.query.get(adv_id) if not adv: return resjson.print_json(10, _(u'广告不存在')) model_delete(adv, commit=True) return resjson.print_json(0, u'ok')
def remove(): """删除文章""" resjson.action_code = 10 post_id = toint(request.args.get('post_id', '0')) if post_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) item = Post.query.get(post_id) if not item: return resjson.print_json(10, _(u'文章不存在')) model_delete(item, commit=True) return resjson.print_json(0, u'ok')
def address_remove(): """删除地址""" resjson.action_code = 13 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() ua_id = toint(request.args.get('ua_id', '0')) # 检查 user_address = UserAddress.query.filter(UserAddress.ua_id == ua_id).filter( UserAddress.uid == uid).first() if not user_address: return resjson.print_json(0, u'ok') model_delete(user_address, commit=True) return resjson.print_json(0, u'ok')
def category_remove(): """删除分类""" resjson.action_code = 12 cat_id = toint(request.args.get('cat_id', '0')) if cat_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) category = PostCategories.query.get(cat_id) if not category: return resjson.print_json(10, _(u'分类不存在')) item = Post.query.filter(Post.cat_id == cat_id).all() if item: return resjson.print_json(11, _(u'分类下有文章,禁止删除!')) model_delete(category, commit=True) return resjson.print_json(0, u'ok')
def remove(): """删除购物车商品""" resjson.action_code = 13 uid = get_uid() session_id = session.sid carts_id = request.args.get('carts_id', '').strip() carts_id = carts_id.split(',') # 检查 if len(carts_id) == 0: return resjson.print_json(10, _(u'请选择需要删除的商品')) for cart_id in carts_id: # 获取购物车商品 q = Cart.query.filter(Cart.cart_id == cart_id).filter( Cart.checkout_type == 1) if uid: q = q.filter(Cart.uid == uid) else: q = q.filter(Cart.session_id == session_id) cart = q.first() if cart is None: return resjson.print_json(11, _(u'购物车里找不到商品')) # 删除购物车商品 model_delete(cart) db.session.commit() cs = CartService(uid, session_id) cs.check() session['cart_total'] = cs.cart_total data = { 'cart_total': cs.cart_total, 'items_quantity': cs.items_quantity, 'items_amount': cs.items_amount } return resjson.print_json(0, u'ok', data)
def update(self): """更新订单""" try: self.check() except OrderException as e: raise e discount_desc = None # 删除已用订单地址 model_delete(self.order_address) # 创建订单地址 data = { 'order_id': self.order_id, 'name': self.shipping_address.name, 'mobile': self.shipping_address.mobile, 'province': self.shipping_address.province, 'city': self.shipping_address.city, 'district': self.shipping_address.district, 'address': self.shipping_address.address, 'zip': self.shipping_address.zip, 'add_time': self.current_time, 'update_time': self.current_time} model_create(OrderAddress, data) # 还原已用优惠券 if self._coupon and self._coupon != self.coupon: data = { 'is_valid': 1, 'order_id': 0, 'use_time': 0} model_update(self._coupon, data) discount_desc = '' # 使用优惠券 if self.coupon: data = { 'is_valid': 0, 'order_id': self.order_id, 'use_time': self.current_time} model_update(self.coupon, data) discount_desc = _(u'使用优惠券%s: %s' % (self.coupon.coupon_id, self.coupon.coupon_name)) # 更新订单金额 self.order_amount = self.items_amount + self.shipping_amount # 更新应付金额 self.pay_amount = self.order_amount - self.discount_amount # 更新订单 data = { 'goods_amount': self.items_amount, 'order_amount': self.order_amount, 'discount_amount': self.discount_amount, 'pay_amount': self.pay_amount, 'shipping_id': self.shipping_id, 'shipping_name': self.shipping.shipping_name, 'shipping_code': self.shipping.shipping_code, 'shipping_amount': self.shipping_amount, 'update_time': self.current_time} if discount_desc is not None: data['discount_desc'] = discount_desc model_update(self.order, data) db.session.commit() return True