Esempio n. 1
0
    def post(self, oid, sid):

        result = {'status': False, 'msg': 0}
        user = self.get_current_user()

        if user:
            try:
                order = Order.get(id=oid)

                if order.uid == user.id:
                    try:
                        orderitem = OrderItem.get(OrderItem.oid == oid,
                                                  OrderItem.sid == sid)
                    except:
                        orderitem = OrderItem()

                    orderitem.oid = oid
                    orderitem.sid = sid
                    orderitem.num = orderitem.num + 1

                    try:
                        orderitem.save()
                        result['status'] = True
                        result['msg'] = 200
                    except Exception, ex:
                        logging.error(ex)
                        result['msg'] = 500
                else:
                    result['msg'] = 403
Esempio n. 2
0
    def post(self):
        result = {'status': False, 'msg': 0}
        user = self.get_current_user()

        if user:
            oiid = int(self.get_argument("oiid", 0))
            num = int(self.get_argument("num", 1))

            if (oiid > 0 and num > 0):
                try:
                    orderitem = OrderItem.get(id=oiid)
                    orderitem.num = num

                    try:
                        orderitem.save()
                        result['status'] = True
                        result['msg'] = 200

                    except Exception, ex:
                        logging.error(ex)
                        result['msg'] = 500
                except:
                    result['msg'] = 404
            else:
                result['msg'] = 400
        else:
            result['msg'] = 403

        self.write(simplejson.dumps(result))
Esempio n. 3
0
    def get(self, oiid):
        result = {'status': False, 'msg': 0}
        user = self.get_current_user()

        if user:
            try:
                orderitem = OrderItem.get(id=oiid)
                order = Order.get(id=orderitem.oid)

                if order.uid == user.id:
                    if OrderItem.select().where(
                            OrderItem.oid == orderitem.oid).count() == 1:
                        order.delete_instance()

                        if user.order > 0:
                            user.order = user.order - 1
                            user.save()
                            self.session['user'] = user
                            self.session.save()

                    orderitem.delete_instance()
                    result['status'] = True
                    result['msg'] = 200

                else:
                    result['msg'] = 403

            except Exception, ex:
                logging.error(ex)
                result['msg'] = 500
Esempio n. 4
0
 def post(self, oid, sid):
     
     result = {'status' : False, 'msg' : 0}
     user = self.get_current_user()
     
     if user:
         try:
             order = Order.get(id = oid)
             
             if order.uid == user.id:
                 try:
                     orderitem = OrderItem.get(OrderItem.oid == oid, OrderItem.sid == sid)
                 except:
                     orderitem = OrderItem()
                 
                 orderitem.oid = oid
                 orderitem.sid = sid
                 orderitem.num = orderitem.num + 1
                 
                 try:
                     orderitem.save()
                     result['status'] = True
                     result['msg'] = 200
                 except Exception, ex:
                     logging.error(ex)
                     result['msg'] = 500
             else:
                 result['msg'] = 403
Esempio n. 5
0
 def get(self, oiid):
     result = {'status' : False, 'msg' : 0}
     user = self.get_current_user()
     
     if user:
         try:
             orderitem  = OrderItem.get(id = oiid)
             order = Order.get(id = orderitem.oid)
             
             if order.uid == user.id:
                 if OrderItem.select().where(OrderItem.oid == orderitem.oid).count() == 1:
                     order.delete_instance()
                     
                     if user.order > 0:
                         user.order = user.order - 1
                         user.save()
                         self.session['user'] = user
                         self.session.save()
                 
                 orderitem.delete_instance()
                 result['status'] = True
                 result['msg'] = 200
                 
             else:
                 result['msg'] = 403
             
         except Exception, ex:
             logging.error(ex)
             result['msg'] = 500
Esempio n. 6
0
 def post(self):
     result = {'status' : False, 'msg' : 0}
     user = self.get_current_user()
     
     if user:
         oiid = int(self.get_argument("oiid", 0))
         num = int(self.get_argument("num", 1))
         
         if (oiid > 0 and num > 0):
             try:
                 orderitem = OrderItem.get(id = oiid)
                 orderitem.num = num
                 
                 try:
                     orderitem.save()
                     result['status'] = True
                     result['msg'] = 200
                 
                 except Exception, ex:
                     logging.error(ex)
                     result['msg'] = 500
             except:
                 result['msg'] = 404
         else:
             result['msg'] = 400  
     else:
         result['msg'] = 403
     
     self.write(simplejson.dumps(result))
Esempio n. 7
0
    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:
Esempio n. 8
0
    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: