Beispiel #1
0
    def orderRequestPortManager(cls, request=HttpRequest()):
        #检测是否登录
        isLogin, account = UserInfo.checkIsLogin(request);
        if isLogin == True:
            if request.method == 'POST':
                operation = request.POST.get('operation', None);
                if operation == None:  #有可能传递过来的是json
                    try:
                        result = json.loads(request.body);
                        operation = result['operation'];
                    except Exception, e:
                        return Responses.responseJsonArray('fail', 'operation无法获取');

                if operation == 'add':
                    return cls.addOrder(request, account);
                elif operation == 'modify':
                    return cls.modifyOrder(request, account);
                elif operation == 'delete':
                    return cls.deleteOrder(request, account);
                else:
                    return Responses.responseJsonArray('fail', 'operation有误');
            elif request.method == 'GET':
                operation = request.GET.get('operation', None);
                if operation == 'get':
                    return cls.getOrder(request, account);
                else:
                    return Responses.responseJsonArray('fail', 'operation有误');
            else:
                return Responses.responseJsonArray('fail', '请使用get或post请求');
Beispiel #2
0
 def __userRegister(cls, request=HttpRequest()):
     #输入合法性检验
     account = request.POST.get('account', None);
     password = request.POST.get('password', None);
     print account , password
     checkResult = cls.__inputDataCheck(account, password);
     print account , password, checkResult
     if checkResult == True:
         hash_md5 = hashlib.md5(); #加密
         hash_md5.update(password);
         hashPassword = hash_md5.hexdigest();
         #查询数据库
         result = models.UsersTable.objects.filter(account=account);
         if result:
             return Responses.responseJsonArray("fail", "账号已被注册");
         else:
             #插入数据库
             result = models.UsersTable.objects.create(account=account, password=hashPassword);
             if result:
                 data = [{ 'account' : account}];
                 request.session['account'] = account;  #注册之后直接登录
                 return Responses.responseJsonArray("success", "注册成功", data);
             else:
                 return Responses.responseJsonArray("fail", "注册失败,请重试");
     else:
         return Responses.responseJsonArray("fail", checkResult);
Beispiel #3
0
def shoppingCart(request):
    isLogin, account = UserInfo.checkIsLogin(request);

    goodsList = [];
    totalPrice = 0;
    allSelect = 1;
    try:
        #先从购物车表获取goodsid,再获取商品
        condition = {
            'account' : account,
        }
        data = ShoppingCartInfo.getShoppingCartData(1, 2000, condition);
        if data:
            for obj in data:
                objList, pageResult = GoodsInfo.getGoodsData(1, 2000, {'goodsId' : obj['goodsId']});
                goods = objList[0];
                #从新计算价格,以最新的为准
                obj['sumPrice'] = str(float(goods['price'])*obj['count']);
                if obj['count'] > goods['inventoryCount']:
                    goods['isOverflow'] = 1;  #库存不足
                else:
                    goods['isOverflow'] = 0;
                goods['count'] = obj['count'];  #增加属性
                goods['sumPrice'] = obj['sumPrice'];
                goods['isSelect'] = obj['isSelect'];

                if not obj['isSelect']:
                    allSelect = 0;
                goodsList.append(goods);
                if obj['isSelect']:
                    totalPrice += float(goods['sumPrice']);
    except Exception, e:
        Responses.returnCheckLoginDrawPage(isLogin, 'goods/shoppingCart.html', 'data', None);
 def shoppingCartRequestPortManager(cls, request=HttpRequest()):
     #检测是否登录
     isLogin, account = UserInfo.checkIsLogin(request)
     if isLogin == True:
         if request.method == 'POST':
             operation = request.POST.get('operation', None)
             if operation == 'add':
                 return cls.addShoppingCart(request, account)
             elif operation == 'delete':
                 return cls.deleteShoppingCart(request, account)
             elif operation == 'modify':
                 return cls.modifyShoppingCart(request, account)
             elif operation == 'checkBox':
                 #修改商品是否选中
                 return cls.modifyCheckBox(request, account)
             elif operation == 'checkBoxAll':
                 return cls.modifyCheckBoxAll(request, account)
             else:
                 return Responses.responseJsonArray('fail', 'operation有误')
         elif request.method == 'GET':
             operation = request.GET.get('operation', None)
             if operation == 'get':
                 return cls.getShoppingCart(request, account)
             elif operation == 'checkStock':
                 return cls.checkStock(request, account)
             else:
                 return Responses.responseJsonArray('fail', 'operation有误')
         else:
             return Responses.responseJsonArray('fail', '请使用get或post请求')
     else:
         return Responses.responseJsonArray('fail', '未登录')
    def modifyCheckBoxAll(cls, request=HttpRequest(), account='0'):
        try:
            results = models.ShoppingCartTable.objects.filter(account=account)
            allSelect = True
            totalPrice = 0
            #总额
            if results:
                for obj in results:
                    totalPrice += float(obj.sumPrice)
                    #这里计算所有的总额
                    if not obj.isSelect:
                        allSelect = False

            data = [{
                'totalPrice': totalPrice
            }]
            if allSelect:
                #全不选所有
                models.ShoppingCartTable.objects.filter(
                    account=account).update(isSelect=False)
                return Responses.responseJsonArray('fail', '未全选',
                                                   [{
                                                       'totalPrice': 0
                                                   }])
            else:
                models.ShoppingCartTable.objects.filter(
                    account=account).update(isSelect=True)
                return Responses.responseJsonArray('success', '全选', data)
        except Exception, e:
            return Responses.responseJsonArray('fail', '数据异常')
Beispiel #6
0
 def deleteCollect(cls, request=HttpRequest(), account='0'):
     goodsId = request.POST.get('goodsId', None);
     try:
         result = models.CollectTable.objects.filter(goodsId=goodsId, account=account).delete();
         return Responses.responseJsonArray('success', '删除成功');
     except Exception, e:
         return Responses.responseJsonArray('fail', '删除失败');
Beispiel #7
0
 def userInfoRequestPortManager(cls, request=HttpRequest()):
     if request.method == 'POST':
         operation = request.POST.get('operation', None);
         if operation == 'register':   #注册
             return cls.__userRegister(request);
         elif operation == 'login':   # 登录
             return cls.__userLogin(request);
         elif operation == 'logout':  #注销
             return cls.__userLogout(request);
         elif operation == 'modify':
             return cls.__userModify(request);
         else:
             return Responses.responseJsonArray('fail', 'operation有误');
     elif request.method == 'GET':
         operation = request.GET.get('operation', None);
         if operation == 'getUserInfo':   #获取用户资料
             return cls.__getUserInfo(request);
         elif operation == 'superUser':  #判断用户是否是管理员
             return cls.checkIsSuperUser(request);
         elif operation == 'isLogin':
             isLogin, account = cls.checkIsLogin(request);
             if isLogin:
                 return Responses.responseJsonArray('success', '已登录', [{'isLogin': True,
                                                                        'account': account}]);
             else:
                 return Responses.responseJsonArray('fail', '未登录');
         else:
             return Responses.responseJsonArray('fail', 'operation有误');
     else:
         return Responses.responseJsonArray('fail', '请使用get或post请求');
Beispiel #8
0
class CollectInfo(object):

    #管理请求端口,分发任务
    @classmethod
    def collectRequestPortManager(cls, request=HttpRequest()):
        #检测是否登录
        isLogin, account = UserInfo.checkIsLogin(request);
        if isLogin == True:
            if request.method == 'POST':
                operation = request.POST.get('operation', None);
                if operation == 'add':
                    return cls.addCollect(request, account);
                elif operation == 'delete':
                    return cls.deleteCollect(request, account);
                else:
                    return Responses.responseJsonArray('fail', 'operation有误');
            elif request.method == 'GET':
                operation = request.GET.get('operation', None);
                if operation == 'get':
                    return cls.getCollect(request, account);
                elif operation == 'check':
                    return cls.checkCollect(request, account);
                else:
                    return Responses.responseJsonArray('fail', 'operation有误');
            else:
                return Responses.responseJsonArray('fail', '请使用get或post请求');
        else:
            return Responses.responseJsonArray('fail', '未登录');

    #添加collect
    @classmethod
    def addCollect(cls, request=HttpRequest(), account='0'):
        collectId = '00000';
        try:
            while True:
                collectId = str(random.randint(10000, 60000));
                if not models.CollectTable.objects.filter(collectId=collectId):
                    break;
        except Exception, e:
            return Responses.responseJsonArray('fail', '添加失败,请重试');

        goodsId = request.POST.get('goodsId', None);
        data = {
                    'collectId' : collectId,
                    'account' : account,
                    'goodsId' : goodsId
                }
        try:
            result = models.CollectTable.objects.filter(goodsId=goodsId);
            if result:
                return Responses.responseJsonArray('success', '已存在');
            result = models.CollectTable.objects.create(**data);
            if result:
                data = [model_to_dict(result)];
                return Responses.responseJsonArray('success', '添加成功', data);
            else:
                return Responses.responseJsonArray('fail', '添加失败,请重试');
        except Exception, e:
            return Responses.responseJsonArray('fail', '添加失败,请重试');
Beispiel #9
0
 def deleteAddress(cls, request=HttpRequest(), account='0'):
     addressId = request.POST.get('addressId', None)
     try:
         result = models.AddressTable.objects.filter(
             addressId=addressId, account=account).delete()
         return Responses.responseJsonArray('success', '删除成功')
     except Exception, e:
         return Responses.responseJsonArray('fail', '删除失败')
Beispiel #10
0
class GoodsInfo(object):

    #管理请求端口,分发任务
    @classmethod
    def goodsRequestPortManager(cls, request=HttpRequest()):
        if request.method == 'POST':
            operation = request.POST.get('operation', None)
            if operation == 'add':
                return cls.addGoods(request)
            elif operation == 'modify':
                return cls.modifyGoods(request)
            elif operation == 'delete':
                return cls.deleteGoods(request)
            else:
                return Responses.responseJsonArray('fail', 'operation有误')
        elif request.method == 'GET':
            operation = request.GET.get('operation', None)
            if operation == 'get':
                return cls.getGoods(request)
            else:
                return Responses.responseJsonArray('fail', 'operation有误')
        else:
            return Responses.responseJsonArray('fail', '请使用get或post请求')

    #分页查找商品,返回json
    @classmethod
    def getGoods(cls, request=HttpRequest()):
        try:
            goodsName = request.GET.get('goodsName', None)
            goodsId = request.GET.get('goodsId', None)
            subClass = request.GET.get('subClass', None)
            page = int(request.GET.get('page', '1'))
            pageSize = int(request.GET.get('pageSize', '20'))
        except ValueError, e:
            page = 1
            pageSize = 2000

        if page <= 1:
            page = 1
        if pageSize <= 20:
            pageSize = 2000

        condition = {}
        if goodsName:
            condition['goodsName'] = goodsName
        if goodsId:
            condition['goodsId'] = goodsId
        if subClass:
            condition['subClass'] = subClass
        data, pageResult = cls.getGoodsData(page, pageSize, condition)

        if data:
            return Responses.responseJsonArray('success', '请求成功', data)
        else:
            return Responses.responseJsonArray('fail', '没有数据')
Beispiel #11
0
 def __getUserInfo(cls, request=HttpRequest()):
     isLogin, account = cls.checkIsLogin(request);
     if isLogin == True:
         #查找用户信息
         data = cls.getUserInfoData(account);
         if data:
             return Responses.responseJsonArray("success", "查找用户信息", data);
         else:
             return Responses.responseJsonArray("fail", "查找失败");
     else:
         return Responses.responseJsonArray("fail", "未登录");
Beispiel #12
0
def search(request):
    isLogin, account = UserInfo.checkIsLogin(request);
    goodsName = request.GET.get('keyword', None);
    goodsList = GoodsInfo.searchGoods(1, 50, goodsName);
    data = {
        'subClass' : 'undefine',
        'goodsList' : goodsList
    }
    if goodsList:
        return Responses.returnDrawPage(isLogin, 'goods/goodsBrowse.html', 'data', data);
    else:
        return Responses.returnDrawPage(isLogin, 'common/noresult.html', 'data', None);
Beispiel #13
0
def bottomStaticPage(request, page):
    isLogin, account = UserInfo.checkIsLogin(request);
    if page == 'about':
        return Responses.returnDrawPage(isLogin, 'static/about.html', 'about', None);
    elif page == 'bigSale':
        return Responses.returnDrawPage(isLogin, 'static/bigSale.html', 'bigsale', None);
    elif page == 'privacy':
        return Responses.returnDrawPage(isLogin, 'static/privacy.html', 'privacy', None);
    elif page == 'saleBack':
        return Responses.returnDrawPage(isLogin, 'static/saleBack.html', 'saleback', None);
    else:
        return HttpResponseRedirect('noresults/');
Beispiel #14
0
    def checkCollect(cls, request=HttpRequest(), account='0'):

        goodsId = request.GET.get('goodsId', None);

        try:
            results = models.CollectTable.objects.filter(account=account, goodsId=goodsId);
            if results:
                data = [];
                for obj in results:
                    obj = model_to_dict(obj);
                    data.append(obj);
                return Responses.responseJsonArray('success', '已收藏', data);
            else:
                return Responses.responseJsonArray('fail', '未收藏');
        except Exception, e:
            return Responses.responseJsonArray('fail', '未找到');
Beispiel #15
0
def home(request):
    isLogin, account = UserInfo.checkIsLogin(request);
    goods, pageResult = GoodsInfo.getGoodsData(1, 30, None);

    try:
        goodsList = {
            'banner1' : goods[1],
            'banner2' : goods[3],
            'banner3' : goods[5],
            'banner4' : goods[9],
            'hotGoods1' : goods[10],
            'hotGoods2' : goods[11],
            'hotGoods3' : goods[12],
            'hotGoods4' : goods[13],
            'hotGoods5' : goods[14],
            'hotGoods6' : goods[15],
            'first1' : goods[16],
            'first2' : goods[17],
            'first3' : goods[18],
            'first4' : goods[19],
            'first5' : goods[20],
            'first6' : goods[21]
        };
    except Exception, e:
        return Responses.returnDrawPage(isLogin, 'home/home.html', 'goodsList', None);
Beispiel #16
0
 def checkStock(cls, request=HttpRequest(), account='0'):
     try:
         goodsList = models.ShoppingCartTable.objects.filter(
             account=account, isSelect=True)
         if goodsList:
             for obj in goodsList:
                 goods = models.GoodsTable.objects.get(goodsId=obj.goodsId)
                 if obj.count > goods.inventoryCount:
                     return Responses.responseJsonArray('fail', '存在库存不足')
                     #库存不足
             return Responses.responseJsonArray('success', '库存充足')
             #库存足
         else:
             return Responses.responseJsonArray('fail', '存在库存不足')
             #库存不足
     except Exception, e:
         return Responses.responseJsonArray('fail', '数据异常')
Beispiel #17
0
 def deleteShoppingCart(cls, request=HttpRequest(), account='0'):
     goodsId = request.POST.get('goodsId', None)
     try:
         models.ShoppingCartTable.objects.filter(goodsId=goodsId,
                                                 account=account).delete()
         results = models.ShoppingCartTable.objects.filter(account=account,
                                                           isSelect=True)
         totalPrice = 0
         if results:
             for obj in results:
                 totalPrice += float(obj.sumPrice)
         data = [{
             'totalPrice': totalPrice
         }]
         return Responses.responseJsonArray('success', '删除成功', data)
     except Exception, e:
         return Responses.responseJsonArray('fail', '删除失败')
Beispiel #18
0
 def addCollect(cls, request=HttpRequest(), account='0'):
     collectId = '00000';
     try:
         while True:
             collectId = str(random.randint(10000, 60000));
             if not models.CollectTable.objects.filter(collectId=collectId):
                 break;
     except Exception, e:
         return Responses.responseJsonArray('fail', '添加失败,请重试');
Beispiel #19
0
    def deleteOrder(cls, request=HttpRequest(), account='0'):
        orderId = request.POST.get('orderId', None);
        try:
            #查看是否为超级用户
            result = models.UsersTable.objects.get(account=account);
            if result.superUser == True:
                #管理员
                result = models.UserOrderTable.objects.filter(orderId=orderId).update(managerDelete=True);
            else:  #普通用户
                result = models.UserOrderTable.objects.filter(orderId=orderId).update(userDelete=True);

            result = models.UserOrderTable.objects.get(orderId=orderId);
            if result.userDelete and result.managerDelete:  #如果用户和管理员都删除了,才真正的删除
                models.UserOrderTable.objects.get(orderId=orderId).delete();

            return Responses.responseJsonArray('success', '删除成功');
        except Exception, e:
            return Responses.responseJsonArray('fail', '删除失败');
Beispiel #20
0
 def addAddress(cls, request=HttpRequest(), account='0'):
     addressId = '00000'
     try:
         while True:
             addressId = str(random.randint(10000, 60000))
             if not models.AddressTable.objects.filter(addressId=addressId):
                 break
     except Exception, e:
         return Responses.responseJsonArray('fail', '添加失败,请重试')
Beispiel #21
0
 def addOrder(cls, request=HttpRequest(), account='0'):
     #产生订单号
     orderId = '00000';
     try:
         while True:
             orderId = str(random.randint(10000, 60000));
             if not models.UserOrderTable.objects.filter(orderId=orderId):
                 break;
     except Exception, e:
         return Responses.responseJsonArray('fail', '产生订单号失败');
Beispiel #22
0
 def goodsRequestPortManager(cls, request=HttpRequest()):
     if request.method == 'POST':
         operation = request.POST.get('operation', None)
         if operation == 'add':
             return cls.addGoods(request)
         elif operation == 'modify':
             return cls.modifyGoods(request)
         elif operation == 'delete':
             return cls.deleteGoods(request)
         else:
             return Responses.responseJsonArray('fail', 'operation有误')
     elif request.method == 'GET':
         operation = request.GET.get('operation', None)
         if operation == 'get':
             return cls.getGoods(request)
         else:
             return Responses.responseJsonArray('fail', 'operation有误')
     else:
         return Responses.responseJsonArray('fail', '请使用get或post请求')
Beispiel #23
0
 def __userLogin(cls, request=HttpRequest()):
     #输入合法性检验
     account = request.POST.get('account', None);
     password = request.POST.get('password', None);
     checkResult = cls.__inputDataCheck(account, password);
     if checkResult == True:
         #查询数据库
         hash_md5 = hashlib.md5();
         hash_md5.update(password);
         hashPassword = hash_md5.hexdigest();
         try:
             results = models.UsersTable.objects.filter(account=account, password=hashPassword);
             if results[0]:#登录成功
                 data = [{ 'account' : account}];
                 request.session['account'] = account;
                 return Responses.responseJsonArray("success", "登录成功", data);
             else:
                 return Responses.responseJsonArray("fail", "账户或密码错误");
         except Exception, e:
             return Responses.responseJsonArray("fail", "账户或密码错误");
Beispiel #24
0
def userBackgroupAddress(request):
    #获取order信息
    isLogin, account = UserInfo.checkIsLogin(request);
    #获取地址
    addressList = AddressInfo.getAddressData(1, 2000, account, {'account' : account});
    data = {
        'addressList' : addressList,
        'superUser' : UserInfo.checkIsSuperUser(request)
    }

    return Responses.returnCheckLoginDrawPage(isLogin, 'myBackgroup/myAddress.html', 'data', data);
Beispiel #25
0
    def addGoods(cls, request=HttpRequest()):

        goodsId = '00000'
        try:  #产生goodsId
            while True:
                goodsId = str(random.randint(10000, 60000))
                if not models.GoodsTable.objects.filter(
                        goodsId=goodsId).count():
                    break
        except Exception, e:
            return Responses.responseJsonArray('fail', '添加失败,请重试')
Beispiel #26
0
def userBackgroupUserInfo(request):
    #获取order信息
    isLogin, account = UserInfo.checkIsLogin(request);
    userInfo = UserInfo.getUserInfoData(account);
    data = [];
    if userInfo:
        userInfo=userInfo[0];
        data = {
            'userInfo' : userInfo,
            'superUser' : UserInfo.checkIsSuperUser(request)
        }
    return Responses.returnCheckLoginDrawPage(isLogin, 'myBackgroup/myPersonal.html', 'data', data);
Beispiel #27
0
    def modifyCheckBox(cls, request=HttpRequest(), account='0'):

        goodsId = request.POST.get('goodsId', None)
        try:
            goodsList = models.ShoppingCartTable.objects.filter(
                goodsId=goodsId, account=account)
            goods = goodsList[0]
            if goods:
                if goods.isSelect:  #本身是选中的则是不选中
                    models.ShoppingCartTable.objects.filter(
                        goodsId=goodsId,
                        account=account).update(isSelect=False)
                else:
                    models.ShoppingCartTable.objects.filter(
                        goodsId=goodsId, account=account).update(isSelect=True)
            else:
                return Responses.responseJsonArray('fail', '商品已失效')

            results = models.ShoppingCartTable.objects.filter(account=account)
            allSelect = True
            totalPrice = 0
            #总额
            if results:
                for obj in results:
                    if not obj.isSelect:
                        allSelect = False
                    if obj.isSelect:
                        totalPrice += float(obj.sumPrice)

            data = [{
                'totalPrice': totalPrice
            }]
            if allSelect:
                return Responses.responseJsonArray('success', '全选', data)
            else:
                return Responses.responseJsonArray('fail', '未全选', data)
        except Exception, e:
            return Responses.responseJsonArray('fail', '数据异常')
Beispiel #28
0
def goodsInfo(request, goodsId):
    isLogin, account = UserInfo.checkIsLogin(request);
    condition = {
        'goodsId': goodsId
    };
    goodsList, pageResult = GoodsInfo.getGoodsData(1, 20, condition);

    minImageUrls = [];
    descImageUrls = [];
    if goodsList:
        for (key, value) in goodsList[0].items():
            if key[0:11] == 'minImageUrl' and value != '':
                minImageUrls.append(value);
            if key[0:12] == 'descImageUrl' and value != '':
                descImageUrls.append(value);
    else:
        return Responses.returnDrawPage(isLogin, 'common/noresult.html', 'data', None);

    goods = goodsList[0];
    goods['minImageUrls'] = minImageUrls;
    goods['descImageUrls'] = descImageUrls;

    return Responses.returnDrawPage(isLogin, 'goods/goodsInfo.html', 'goods', goods);
Beispiel #29
0
    def __userModify(cls, request=HttpRequest()):
        isLogin, account = cls.checkIsLogin(request);
        if isLogin:
            condition = {};
            if request.POST.get('password', None):
                password = request.POST.get('password', None);
                hash_md5 = hashlib.md5();
                hash_md5.update(password);
                hashPassword = hash_md5.hexdigest();
                condition['password'] = hashPassword;
            if request.POST.get('nickname', None):
                condition['nickname'] = request.POST.get('nickname', None);
            if request.POST.get('email', None):
                condition['email'] = request.POST.get('email', None);

            try:
                result = models.UsersTable.objects.filter(account=account).update(**condition);
                if result:
                    return Responses.responseJsonArray('success', '修改成功');
                else:
                    return Responses.responseJsonArray('fail', '修改失败');
            except Exception, e:
                return Responses.responseJsonArray('fail', '修改失败');
Beispiel #30
0
 def modifyOrder(cls, request=HttpRequest(), account='0'):
     orderId = request.POST.get('orderId', None);
     if not orderId:
         return Responses.responseJsonArray('fail', '没有orderId');
     status = request.POST.get('status', None);
     company = request.POST.get('company', None);
     expressId = request.POST.get('expressId', None);
     condition = {};
     if status:
         condition['status'] = status;
     if status:
         condition['company'] = company;
     if status:
         condition['expressId'] = expressId;
     try:
         if status:
             #开启事务
             with transaction.atomic():
                 models.UserOrderTable.objects.filter(orderId=orderId).update(**condition)
                 return Responses.responseJsonArray('success', '修改成功', [condition]);
         else:
             return Responses.responseJsonArray('fail', '没有对应订单');
     except Exception, e:
         return Responses.responseJsonArray('fail', '修改失败');