Beispiel #1
0
def Query_site(request):
    print('Query_site')
    try:
        if request.method == 'GET':
            _id_client = request.GET.get('id_client')
            print(_id_client)
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                c = Client.objects.get(pk=_id_client)
                print(c)
                sites = c.client_site_set.all()
                data = serializers.serialize('json', sites)
                da = json.loads(data)
                print(da)
                lis = (100, da)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis = (101, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
        else:
            lis = (103, 300)
            json_str = json.dumps(lis)
            return HttpResponse(json_str)
    except:
        lis = (104, 300)
        json_str = json.dumps(lis)
        return HttpResponse(json_str)
Beispiel #2
0
def Add_site(request):
    print('Add_site')
    try:
        if request.method == 'POST':
            _id_client = request.POST.get('id_client')
            _datas = request.POST.get('datas')
            _da = json.loads(_datas)
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            if Verify(_ciphertext, _time):
                if Client_site.objects.filter(site=_da['name']):
                    lis = (102, 300)
                    json_str = json.dumps(lis)
                    return HttpResponse(json_str)
                else:
                    client = Client.objects.get(pk=_id_client)
                    site = Client_site(site=_da['name'], client=client)
                    site.save()
                    lis = (100, 300)
                    json_str = json.dumps(lis)
                    return HttpResponse(json_str)
            else:
                lis = (101, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
        else:
            lis = (103, 300)
            json_str = json.dumps(lis)
            return HttpResponse(json_str)
    except:
        lis = (104, 300)
        json_str = json.dumps(lis)
        return HttpResponse(json_str)
Beispiel #3
0
def Query_buy_client(request):
    print('j接收到请求')
    try:
        if request.method == 'GET':
            _id_buy = request.GET.get('id_buy')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            print('j接收到请求')
            if Verify(_ciphertext,_time):
                b = Buy_list.objects.filter(buy=_id_buy)
                data = serializers.serialize('json', b)
                da = json.loads(data)
                lis = (100, da)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101, 300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103, 300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #4
0
def Query_buy_list(request):
    print('Query_buy_list')
    try:
        if request.method == 'GET':
            _id_buy_list = request.GET.get('id_buy_list')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                print('Query_buy_l_id_buy_listist', _id_buy_list)
                b = Buy_list.objects.get(pk=_id_buy_list)
                all = b.buy_good_set.all()
                data = serializers.serialize('json', all, fields=('count', 'quantity', 'price', 'cost','good_name','good_specification','good_photo'))
                data_sz = json.loads(data)
                print('Query_buy_list',data_sz)
                lis = (100, data_sz)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101, 300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103, 300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #5
0
def Alter_postage(request):
    try:
        if request.method == 'POST':
            _postage = float(request.POST.get('postage'))
            _id_buy_list = request.POST.get('id_buy_list')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            if Verify(_ciphertext, _time):
                buy_list = Buy_list.objects.get(pk=_id_buy_list)
                buy_list.postage = round(_postage,2)
                buy_list.save()
                lis = (100,300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101,300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103,300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #6
0
def Query_good_specification(request):
    print("Query_good_specification")
    try:
        if request.method == 'GET':
            _id_good = request.GET.get('id_good')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext,_time):
                g = Good.objects.get(pk=_id_good)
                spe = g.good_specification_set.all()
                data = serializers.serialize('json',spe,fields=('specificati'))
                da = json.loads(data)
                lis = (100, da)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis = (101, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
        else:
            lis = (103, 300)
            json_str = json.dumps(lis)
            return HttpResponse(json_str)
    except:
        lis = (104, 300)
        json_str = json.dumps(lis)
        return HttpResponse(json_str)
Beispiel #7
0
def Alter_cost(request):
    try:
        if request.method == 'POST':
            _cost = float(request.POST.get('cost'))
            _id_buy = request.POST.get('id_buy')
            _postcost = float(request.POST.get('postcost'))
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
           # print('接收到请求',_id_buy)
            if Verify(_ciphertext, _time):
                buy = Buy.objects.get(pk=_id_buy)
                buy.cost = round(_cost,2)
                buy.postcost = round(_postcost, 2)
                buy.save()
                lis = (100,300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101,300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103,300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #8
0
def Alter_remark(request):
    print('Alter_remark')
    try:
        if request.method == 'POST':
            _id_buy_list = request.POST.get('id_buy_list')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            _remark = request.POST.get('remark')
            if Verify(_ciphertext, _time):
                buy_list = Buy_list.objects.get(pk=_id_buy_list)
                buy_list.remarks = _remark
                buy_list.save()
                lis = (100, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis0 = (101, 300)
                json_str0 = json.dumps(lis0)
                return HttpResponse(json_str0)
        else:
            lis1 = (103, 300)
            json_str1 = json.dumps(lis1)
            return HttpResponse(json_str1)
    except:
        lis2 = (104, 300)
        json_str2 = json.dumps(lis2)
        return HttpResponse(json_str2)
Beispiel #9
0
def Query_dg(request):
    try:
        if request.method == 'GET':
            _id_wx = request.GET.get('id_wx')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext,_time):
                b = User.objects.get(id_wx=_id_wx)
                _buys = b.buy_set.all()
                data = serializers.serialize('json',_buys)
                da = json.loads(data)
                lis = (100, da)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis = (101, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
        else:
            lis = (103, 300)
            json_str = json.dumps(lis)
            return HttpResponse(json_str)
    except:
        lis = (104, 300)
        json_str = json.dumps(lis)
        return HttpResponse(json_str)
Beispiel #10
0
def Delete_buy_list(request):
    try:
        if request.method == 'GET':

            _id_wx = request.GET.get('id_wx')
            _id_buy_list = request.GET.get('id_buy_list')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))

            print(_id_wx,_id_buy_list)
            if Verify(_ciphertext, _time):
                buy_list = Buy_list.objects.get(pk=_id_buy_list)
                buy_list.delete()

                user = User.objects.get(id_wx=_id_wx)
                user.get_list = True
                user.save()
                lis = (100, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101, 300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103, 300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #11
0
def Query_category_good(request):
    print('Query_category_good')
    try:
        if request.method == 'GET':
            _id_category = request.GET.get('id_category')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                print('Query', _id_category)
                c = Category.objects.get(pk=_id_category)
                goods = c.good_set.all()
                data = serializers.serialize('json', goods)
                da = json.loads(data)
                print('今天真惨', data)
                lis = (100, da)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis0 = (101, 300)
                json_str0 = json.dumps(lis0)
                return HttpResponse(json_str0)
        else:
            lis1 = (103, 300)
            json_str1 = json.dumps(lis1)
            return HttpResponse(json_str1)
    except:
        lis2 = (104, 300)
        json_str2 = json.dumps(lis2)
        return HttpResponse(json_str2)
Beispiel #12
0
def Fix_dgsite(request):
    print('Fix_dgsite')
    try:
        if request.method == 'POST':
            _id_buy_list = request.POST.get('id_buy_list')
            _site = request.POST.get('site')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            if Verify(_ciphertext, _time):
                buy_list = Buy_list.objects.get(pk=_id_buy_list)
                buy_list.client_site = _site
                buy_list.save()
                lis = (100, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis = (101, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
        else:
            lis = (103, 300)
            json_str = json.dumps(lis)
            return HttpResponse(json_str)
    except:
        lis = (104, 300)
        json_str = json.dumps(lis)
        return HttpResponse(json_str)
Beispiel #13
0
def Add_dg(request):
    print('Add_dg')
    try:
        if request.method == 'POST':
            _id_wx = request.POST.get('id_wx')
            _user = User.objects.get(id_wx=_id_wx)
            _name = request.POST.get('name')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            if Verify(_ciphertext, _time):
                buy = Buy(name=_name,user=_user)
                buy.save()
                user = User.objects.get(id_wx=_id_wx)
                user.get_list = True
                user.save()
                id_buy = buy.id
                lis = (100,id_buy)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101,300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis2 = (103.300)
            json_str = json.dumps(lis2)
            return HttpResponse(json_str)

    except:
        lis3 = (104,300)
        json_str = json.dumps(lis3)
        return HttpResponse(json_str)
Beispiel #14
0
def Add_dglist(request):
    print("Add_dglist")
    try:
        if request.method == 'POST':

            _id_client = request.POST.get('id_client')
            _id_buy = request.POST.get('id_buy')
            _id_wx = request.POST.get('id_wx')
            client = Client.objects.get(pk=_id_client)
            print(client)

            _buy = Buy.objects.get(pk=_id_buy)
            print(_buy)
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))


            if Verify(_ciphertext, _time):
                if Buy_list.objects.filter(buy=_buy).filter(client=client):
                    lis2 = (102,300)
                    json_str = json.dumps(lis2)
                    print('6,相同客户')
                    return HttpResponse(json_str)
                else:
                    try:
                        _site = client.client_site_set.all()[0:1].get()
                        buy_list = Buy_list(client=client, buy=_buy, client_name=client.name, client_phone=client.phone,
                                            client_site=_site.site)
                    except :
                        buy_list = Buy_list(client=client, buy=_buy, client_name=client.name, client_phone=client.phone,
                                            client_site='')
                    buy_list.save()

                    user = User.objects.get(id_wx = _id_wx)
                    user.get_list = True
                    user.save()
                    da = {'id_buylist':buy_list.pk,'clientid':buy_list.client_id, 'name':buy_list.client.name, 'phone':buy_list.client.phone,
                                            'site':buy_list.client_site}
                    lis = (100,da)
                    json_str = json.dumps(lis)
                    return HttpResponse(json_str)

            else:
                lis1 = (101,300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis2 = (103,300)
            json_str = json.dumps(lis2)
            return HttpResponse(json_str)

    except:
        lis3 = (104,300)
        json_str = json.dumps(lis3)
        return HttpResponse(json_str)
Beispiel #15
0
def Query_good_detail(request):
    print('Query_good_detail')
    try:
        if request.method == 'GET':
            _id_good = request.GET.get('id_good')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                print('Query', _id_good)
                g = Good.objects.get(pk=_id_good)
                goodspe = g.good_specification_set.all()
                data = serializers.serialize('json', goodspe)
                da = json.loads(data)
                print(g.label)
                if g.label is None:
                    print('no', g.photo)
                    da = {
                        'name': g.name,
                        'photo': g.photo,
                        'remark': g.remark,
                        'category': '无',
                        'categoryid': '',
                        'spe': da
                    }
                else:
                    print('ok', g.photo)
                    da = {
                        'name': g.name,
                        'photo': g.photo,
                        'remark': g.remark,
                        'category': g.label.name,
                        'categoryid': g.label_id,
                        'spe': da
                    }

                lis = (100, da)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis0 = (101, 300)
                json_str0 = json.dumps(lis0)
                return HttpResponse(json_str0)
        else:
            lis1 = (103, 300)
            json_str1 = json.dumps(lis1)
            return HttpResponse(json_str1)
    except:
        lis2 = (104, 300)
        json_str2 = json.dumps(lis2)
        return HttpResponse(json_str2)
Beispiel #16
0
def Query_category(request):
    print('Query_category')
    try:
        if request.method == 'GET':
            _id_wx = request.GET.get('id_wx')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                b = User.objects.get(id_wx=_id_wx)
                _category = b.category_set.all()
                data = serializers.serialize('json', _category)
                return HttpResponse(data)
            else:
                return HttpResponse('101')
        else:
            return HttpResponse('103')
    except:
        return HttpResponse('104')
Beispiel #17
0
def Select_good(request):
    print('Select_good')
    try:
        if request.method == 'GET':
            _id_wx = request.GET.get('id_wx')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                b = User.objects.get(id_wx=_id_wx)
                _goods = b.good_set.all()
                data = serializers.serialize('json', _goods)
                print(data)
                return HttpResponse(data)
            else:
                return HttpResponse('101')
        else:
            return HttpResponse('103')
    except:
        return HttpResponse('104')
Beispiel #18
0
def Alter_buy_good(request):
    print('Alter_buy_good')
    try:
        if request.method == 'POST':
            _id_wx = request.POST.get('id_wx')
            _price = float(request.POST.get('price'))
            _cost = float(request.POST.get('cost'))
            _count = int(request.POST.get('count'))
            _id_buy_good = request.POST.get('id_buy_good')
            _id_buy_list = request.POST.get('id_buy_list')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            print(_id_wx,_price,_cost,_count,_id_buy_good)
            if Verify(_ciphertext, _time):
                buy_good = Buy_good.objects.get(pk=_id_buy_good)
                print(buy_good.price)
                buy_good.price = round(_price,2)
                buy_good.cost = round(_cost,2)
                buy_good.count = _count
                buy_good.save()
                #修改商品的待收款额
                # 设置代购列表中某人的待收款额
                Set_total(_id_buy_list)
                user = User.objects.get(id_wx=_id_wx)
                user.get_list = True
                user.save()
                lis = (100,300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)
            else:
                lis1 = (101,300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103,300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #19
0
def Delete_category(request):
    print('Delete_category')
    try:
        if request.method == 'POST':
            _id_wx = request.POST.get('id_wx')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            _id = request.POST.get('id')
            if Verify(_ciphertext, _time):
                b = User.objects.get(id_wx=_id_wx)
                print(_id)
                _client = b.client_set.get(pk=_id)
                print(_client)
                _client.delete()
                return HttpResponse('100')
            else:
                return HttpResponse('101')
        else:
            return HttpResponse('103')
    except:
        return HttpResponse('104')
Beispiel #20
0
def Get_inform(request):
    print('Get_inform')
    try:
        if request.method == 'GET':
            _id_wx = request.GET.get('id_wx')
            _ciphertext = int(request.GET.get('ciphertext'))
            _time = int(request.GET.get('text'))
            if Verify(_ciphertext, _time):
                _user = User.objects.get(id_wx=_id_wx)

                _inform = Inform.objects.all().last()

                if _user.confirm_inform_set.all().filter(inform=_inform):

                    lis = (102, 300)
                    json_str = json.dumps(lis)
                    return HttpResponse(json_str)
                else:
                    coninform = Confirm_inform(inform=_inform, user=_user)

                    coninform.save()
                    da = {'content': _inform.content, 'id_inform': _inform.pk}

                    lis = (100, da)
                    json_str = json.dumps(lis)
                    return HttpResponse(json_str)
            else:
                lis1 = (101, 300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103, 300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #21
0
def Delete_good(request):
    try:
        if request.method == 'POST':
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            _id = request.POST.get('id')
            print('要删除的ID是', _id, _ciphertext, _time)
            if Verify(_ciphertext, _time):
                print('我要删除', )
                _good = Good.objects.get(pk=_id)
                _photo_url = _good.photo
                print('我要删除的图片的名字', _photo_url)
                #删除七牛图片
                re = delete_photo(_photo_url)
                print(re)
                _good.delete()
                return HttpResponse('100')
            else:
                return HttpResponse('101')
        else:
            return HttpResponse('103')
    except:
        return HttpResponse('104')
Beispiel #22
0
def Save_pay(request):
    print('Save_pay')
    try:
        if request.method == 'POST':
            _id = request.POST.get('id')
            _gathering = float(request.POST.get('gathering'))
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            if Verify(_ciphertext, _time):
                buy_list=Buy_list.objects.get(pk=_id)
                s = buy_list.gathering
                buy_list.gathering = _gathering
                buy_list.save()
                _buy = Buy.objects.get(pk=buy_list.buy_id)
                x = _buy.gathering
                valpay = x - s + _gathering
                _buy.gathering = valpay
                _buy.save()
                lis = (100, 300)
                json_str = json.dumps(lis)
                return HttpResponse(json_str)

            else:
                lis1 = (101, 300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)

        else:
            lis3 = (103, 300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)

    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #23
0
def Add_category(request):
    print('Add_category')
    try:
        if request.method == 'POST':
            _id_wx = request.POST.get('id_wx')
            _user = User.objects.get(id_wx=_id_wx)
            _datas = request.POST.get('datas')
            _da = json.loads(_datas)
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            if Verify(_ciphertext, _time):
                if Category.objects.filter(user=_user).filter(
                        name=_da['name']):
                    return HttpResponse('102')
                else:
                    client = Category(name=_da['name'], user=_user)
                    client.save()
                    return HttpResponse('100')
            else:
                return HttpResponse('101')
        else:
            return HttpResponse('103')
    except:
        return HttpResponse('104')
Beispiel #24
0
def Add_dggood(request):
    print('Add_dggood')
    rate = {'0': 'HKD', '1': 'CNY', '2': 'KRW', '3': 'AUD', '4': 'JPY', '5': 'GBP', '6': 'USD'}
    try:
        if request.method == 'POST':
            _id_good = request.POST.get('id_good')
            _id_buy_list = request.POST.get('id_buy_list')
            _count = int(request.POST.get('count'))
            _id_wx = request.POST.get('id_wx')
            _id_spe = request.POST.get('id_spe')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            print(_id_spe,_id_good,_id_buy_list)
            if Verify(_ciphertext, _time):
                _good = Good.objects.get(pk=_id_good)
                _buy_list = Buy_list.objects.get(pk=_id_buy_list)

                if _id_spe!='':
                    print('spespe',_id_spe)
                    _spe = Good_specification.objects.get(pk=_id_spe)
                    if Buy_good.objects.filter(buy_list=_buy_list).filter(spe=_spe):
                        lis2 = (102, 300)
                        json_str = json.dumps(lis2)
                        return HttpResponse(json_str)
                    else:
                        print(_buy_list)
                        _price = round(_spe.price, 2)
                        bz = _spe.purchase_currency
                        _cost = round(_spe.purchase_price * BZ(bz), 2)
                        buy_good = Buy_good(count=_count, good=_good, buy_list=_buy_list, cost=_cost, price=_price,good_name=_good.name,good_specification=_spe.specificati,good_photo=_good.photo,spe=_spe)
                        buy_good.save()
                        user = User.objects.get(id_wx=_id_wx)
                        user.get_list = True
                        user.save()
                        lis = (100, 300)
                        json_str = json.dumps(lis)
                        return HttpResponse(json_str)
                else:
                    print('buygood', _id_spe)
                    if Buy_good.objects.filter(buy_list=_buy_list).filter(good=_good):
                        lis2 = (102, 300)
                        json_str = json.dumps(lis2)
                        return HttpResponse(json_str)
                    else:
                        print(_buy_list)
                        buy_good = Buy_good(count=_count, good=_good, buy_list=_buy_list,
                                            good_name=_good.name,
                                            good_photo=_good.photo )
                        buy_good.save()
                        user = User.objects.get(id_wx=_id_wx)
                        user.get_list = True
                        user.save()
                        lis = (100, 300)
                        json_str = json.dumps(lis)
                        return HttpResponse(json_str)
            else:
                lis1 = (101, 300)
                json_str = json.dumps(lis1)
                return HttpResponse(json_str)
        else:
            lis3 = (103, 300)
            json_str = json.dumps(lis3)
            return HttpResponse(json_str)
    except:
        lis4 = (104, 300)
        json_str = json.dumps(lis4)
        return HttpResponse(json_str)
Beispiel #25
0
def Add_good(request):
    print('Add_good')
    try:
        if request.method == 'POST':
            _id_wx = request.POST.get('id_wx')
            _user = User.objects.get(id_wx=_id_wx)
            _photo = request.POST.get('photo')
            _purchase_currency = request.POST.get('purchase_currency')
            _ciphertext = int(request.POST.get('ciphertext'))
            _time = int(request.POST.get('text'))
            _id = request.POST.get('id')
            _categoryid = request.POST.get('categoryid')
            _speNub = request.POST.get('speNub')

            _datas = request.POST.get('datas')
            _da = json.loads(_datas)

            print('商品数据', _da)
            if Verify(_ciphertext, _time):
                #修改_id有定义
                if Isset(_id):
                    _good = Good.objects.get(pk=_id)
                    if Isset(_categoryid):
                        _categ = Category.objects.get(pk=_categoryid)
                        _good.label = _categ
                        _good.name = _da.get('name')
                        _good.photo = _photo
                        _good.remark = _da.get('remark')
                        _good.save()
                        fix_good_specificati(_good, _da, _purchase_currency,
                                             _speNub)
                    else:
                        _good.name = _da.get('name')
                        _good.photo = _photo
                        _good.remark = _da.get('remark')
                        _good.save()
                        fix_good_specificati(_good, _da, _purchase_currency,
                                             _speNub)

                    return HttpResponse('100')
                #新增
                else:
                    if Isset(_categoryid):
                        _categ = Category.objects.get(pk=_categoryid)
                    else:
                        _categ = None
                    good = Good(name=_da.get('name'),
                                photo=_photo,
                                user=_user,
                                remark=_da.get('remark'),
                                label=_categ)
                    good.save()
                    add_good_specificati(good, _da, _purchase_currency,
                                         _speNub)
                    return HttpResponse('100')
            else:
                return HttpResponse('101')
        else:
            return HttpResponse('103')
    except:
        return HttpResponse('104')