def changeBasicInfo(request): if request.method == 'POST': result = cookiesVerify(request) if (result == '0'): try: data = request.POST db = pymysql.connect('127.0.0.1', 'root', '522087905', 'mysite') cursor = db.cursor(pymysql.cursors.DictCursor) sql = """ update login_accountinfo as info set info.nickName = '{0}', info.school = '{1}', info.studentNo = '{2}' where info.id = {3}""".format(str(data['nickName']), str(data['school']), str(data['schoolNumber']), str(request.COOKIES['id'])) cursor.execute(sql) db.commit() db.close() sendBack = {'statusCode': '0', 'nickName': data['nickName']} # 修改成功 return JsonResponse(sendBack) except Exception as e: print('personalInfo()数据库连接失败', e) db.rollback() db.close() sendBack = {'statusCode': '2'} # 数据库连接失败 return JsonResponse(sendBack) else: sendBack = {'statusCode': '1'} # 登陆状态异常 return JsonResponse(sendBack)
def personalInfo(request): context = {"typeDic": typeDic} results = cookiesVerify(request) if (results == '0'): try: id = request.COOKIES['id'] db = pymysql.connect('127.0.0.1', 'root', '522087905', 'mysite') cursor = db.cursor(pymysql.cursors.DictCursor) sql = """ select * from login_accountinfo as info where info.id = {0}""".format(str(id)) cursor.execute(sql) info = cursor.fetchone() context['statusCode'] = '0' context.update(info) print(context) return render(request, "myinfo/personalInfo.html", context) except Exception as e: print('personalInfo()数据库连接失败', e) context['statusCode'] = '2' return render(request, "myinfo/personalInfo.html", context) else: context['statusCode'] = '1' # 登陆状态异常 return render(request, "myinfo/personalInfo.html", context)
def processSubmit(request): if request.method == 'POST': result = cookiesVerify(request) print(request.POST) data = request.POST if (result == '0'): # 密码认证正确 accountInfo = AccountInfo.objects.get( phoneNumber=request.COOKIES['phoneNumber']) affairInfo = AffairInfo(affairProviderId=accountInfo, type=data['type'], affairName=data['affairName'], affairDetail=data['affairDetail'], affairCreateTime=timezone.now(), lastUpdateTime=timezone.now(), needReceiverNum=int(data['receiverNum'])) if (data['reward'] == ''): affairInfo.rewardType = '0' affairInfo.rewardMoney = 0 else: judge = '0' # 0代表全是数字,则判断酬劳为RMB for c in data['reward']: if ((c <= '0' or c >= '9') and c != '.'): judge = '1' break affairInfo.rewardType = '0' if (judge == '0'): affairInfo.rewardMoney = float(data['reward']) print(float(data['reward'])) else: affairInfo.rewardType = '1' affairInfo.rewardThing = data['reward'] print(data.getlist('tag')) temp = '' for tag in data.getlist('tag'): # 里边会有多个标签 temp = temp + tag + ';' affairInfo.tag = temp affairInfo.save() count = 0 for imgFile in request.FILES.getlist('img_file'): count = count + 1 new_img = affairInfo.affairimg_set.create(img=imgFile, name=imgFile.name) sendBack = {'statusCode': '0'} return JsonResponse(sendBack) if (result == '1' or result == '2'): sendBack = {'statusCode': result} return JsonResponse(sendBack) sendBack = {'statusCode': '3'} return JsonResponse(sendBack)
def changeOrderStatus(request): # 验证登录 postData = json.loads(request.body) orderId = postData['orderId'] result = cookiesVerify(request) if (result == '0'): db = pymysql.connect('127.0.0.1', 'root', '522087905', 'mysite') cursor = db.cursor(pymysql.cursors.DictCursor) # 安全检查,看这该用户是否有此订单 sql = ''' select affairReceiverId_id from order_order_account where order_order_account.orderId_id = {0}'''.format(str(orderId)) cursor.execute(sql) data = cursor.fetchone() if (str(request.COOKIES['id']) != str(data['affairReceiverId_id'])): db.close() print("权限错误") return HttpResponseForbidden() # 开始在数据库中查找相关内容 # 查看orderStatus sql = """ select * from affair_order_receiver_condition as info where info.orderId = {0}""".format(str(orderId)) cursor.execute(sql) data = cursor.fetchone() oldOrderStatus = data['orderStatus'] newStatusCode = '1' if (oldOrderStatus != '0'): db.close() sendBack = {'statusCode': '0'} return JsonResponse(sendBack) # 修改orderStatus sql = """ update affair_order_receiver_condition as info set info.orderStatus = {0} where info.orderId = {1}""".format(str(newStatusCode), str(orderId)) cursor.execute(sql) db.commit() db.close sendBack = {'statusCode': '0'} return JsonResponse(sendBack) else: return HttpResponseForbidden()
def phoneNumberProcess(request): if request.method == 'POST': result = cookiesVerify(request) if (result == '0'): try: data = request.POST print(data) db = pymysql.connect('127.0.0.1', 'root', '522087905', 'mysite') cursor = db.cursor(pymysql.cursors.DictCursor) sql = """ select * from login_accountinfo as info where info.phoneNumber = {0}""".format(str(data['newPhoneNumber'])) cursor.execute(sql) phoneNumber = cursor.fetchone() print(phoneNumber) # 为空说明数据库中不存在这样的电话号码,即不重复,可以修改电话号码 if not phoneNumber: sql = """ update login_accountinfo as info set info.phoneNumber = '{0}' where info.id = {1}""".format(str(data['newPhoneNumber']), str(request.COOKIES['id'])) cursor.execute(sql) db.commit() db.close() sendBack = {'statusCode': '0', 'newPhoneNumber': data['newPhoneNumber']} # 修改成功 return JsonResponse(sendBack) else: db.close() sendBack = {'statusCode': '3'} return JsonResponse(sendBack) except Exception as e: print('processPasswordChange()数据库连接失败', e) db.rollback() db.close() sendBack = {'statusCode': '2'} # 数据库连接失败 return JsonResponse(sendBack) else: sendBack = {'statusCode': '1'} # 登陆状态异常 return JsonResponse(sendBack)
def processPasswordChange(request): if request.method == 'POST': result = cookiesVerify(request) if (result == '0'): try: data = request.POST db = pymysql.connect('127.0.0.1', 'root', '522087905', 'mysite') cursor = db.cursor(pymysql.cursors.DictCursor) sql = """ select passwd from login_accountinfo as info where info.id = {0}""".format(str(request.COOKIES['id'])) cursor.execute(sql) passwd = cursor.fetchone() print(passwd) if (passwd['passwd'] == data['rawPwd']): sql = """ update login_accountinfo as info set info.passwd = '{0}' where info.id = {1}""".format(str(data['pwd']), str(request.COOKIES['id'])) cursor.execute(sql) db.commit() db.close() sendBack = {'statusCode': '0', 'nickName': data['pwd']} # 修改成功 return JsonResponse(sendBack) else: db.close() sendBack = {'statusCode': '3', 'nickName': data['pwd']} return JsonResponse(sendBack) except Exception as e: print('processPasswordChange()数据库连接失败', e) db.rollback() db.close() sendBack = {'statusCode': '2'} # 数据库连接失败 return JsonResponse(sendBack) else: sendBack = {'statusCode': '1'} # 登陆状态异常 return JsonResponse(sendBack)
def processEditAffair(request, affairId): result = cookiesVerify(request) print(result) if (result == '0'): try: db = pymysql.connect('127.0.0.1', 'root', '522087905', 'mysite') cursor = db.cursor(pymysql.cursors.DictCursor) data = request.POST print(data) affairName = data['affairName'] affairType = data['type'] needReceiverNum = data['receiverNum'] reward = data['reward'] affairDetail = data['affairDetail'] temp = '' for tag in data.getlist('tag'): # 里边会有多个标签 temp = temp + tag + ';' tag = temp print(tag) if (data['reward'] == ''): rewardType = '0' rewardMoney = 0 rewardThing = 'nothing' else: judge = '0' # 0代表全是数字,则判断酬劳为RMB for c in data['reward']: if ((c <= '0' or c >= '9') and c != '.'): judge = '1' break rewardType = '0' if (judge == '0'): rewardMoney = float(data['reward']) rewardThing = 'nothing' else: rewardType = '1' rewardThing = data['reward'] rewardMoney = 0 sql = """ update affair_affairInfo as info set info.affairName = '{0}', info.needReceiverNum = {1}, info.tag = '{2}', info.affairDetail = '{3}', info.type = '{4}', info.rewardType = '{5}', info.rewardMoney = {6}, info.rewardThing = '{7}' where info.affairId = {8}""".format( str(affairName), str(needReceiverNum), str(affairDetail), str(affairDetail), str(affairType), str(rewardType), str(rewardMoney), str(rewardThing), str(affairId)) cursor.execute(sql) db.commit() sql = """ select needReceiverNum, receiverNum, statusFlag from affair_affairInfo where affairId = {0}""".format(str(affairId)) cursor.execute(sql) info = cursor.fetchone() if (info['statusFlag'] == '1') and (info['needReceiverNum'] > info['receiverNum']): sql = """ update affair_affairInfo set statusFlag = {0} where affairId = {1}""".format(str(0), str(affairId)) cursor.execute(sql) db.commit() if (request.FILES.getlist('img_file')): affairInfo = AffairInfo.objects.get(affairId=affairId) previousImg = AffairImg.objects.filter(affair_id=4) for img in previousImg: img.delete() for imgFile in request.FILES.getlist('img_file'): new_img = affairInfo.affairimg_set.create( img=imgFile, name=imgFile.name) db.close() sendBack = {"statusCode": "0"} return JsonResponse(sendBack) except Exception as e: db.rollback() db.close() print("processEditAffair()数据库操作失败:\n", e) sendBack = {"statusCode": "2"} return JsonResponse(sendBack) else: sendBack = {"statusCode": "1"} return JsonResponse(sendBack)