def updatecaidanword(request): result = {} diary = Diary() if request.method == "POST": content = request.POST.get("content", None) # 读取post数据,None为默认值 qunid = request.POST.get("qunid", None) # 读取post数据,None为默认值 qundiarytype = request.POST.get("qundiarytype", None) # 读取post数据,None为默认值 state = request.POST.get("state", None) # 读取post数据,None为默认值 money = request.POST.get("money", None) # 读取post数据,None为默认值 urltitle = request.POST.get("urltitle", None) # 读取post数据,None为默认值 urlcontent = request.POST.get("urlcontent", None) # 读取post数据,None为默认值 userid = request.POST.get("userid", None) # 读取post数据,None为默认值 diaryid = request.POST.get("diaryid", None) # 读取post数据,None为默认值 if request.method == "GET": content = request.GET.get("content", None) # 读取get数据,None为默认值 qunid = request.GET.get("qunid", None) # 读取get数据,None为默认值 qundiarytype = request.POST.get("qundiarytype", None) # 读取get数据,None为默认值 state = request.POST.get("state", None) # 读取get数据,None为默认值 money = request.POST.get("money", None) # 读取get数据,None为默认值 urltitle = request.POST.get("urltitle", None) # 读取get数据,None为默认值 urlcontent = request.POST.get("urlcontent", None) # 读取get数据,None为默认值 userid = request.POST.get("userid", None) # 读取get数据,None为默认值 diaryid = request.POST.get("diaryid", None) # 读取get数据,None为默认值 print("修改菜单(图片)接口参数:用户id:", userid, "内容:", content, "可见群组", qunid) try: diary = DiaryDAO.selectDiary(diaryid) diary.diarytype(ResultCode.CONTENT_TYPEIMG) diary.state = state diary.userid = userid diary.content = content diary.qunid = qunid diary.type = qundiarytype diary.urltitle = urltitle diary.urlcontent = urlcontent diary.money = money diary.time = TimeUtil.getCurrentTime() diary.date = TimeUtil.getCurrentDate() DiaryDAO.updatediary(diary) result["data"] = "0" result["respcode"] = ResultCode.SUCCESS result["errorcode"] = "" result["message"] = "修改日志成功" except Exception as e: print(e) result["data"] = "0" result["respcode"] = ResultCode.FAIL result["errorcode"] = ResultCode.FAIL result["message"] = "修改日志失败" return JsonResponse(result)
def setstate(request): result = {} if request.method == "POST": diaryid = request.POST.get("diaryid", None) # 读取post数据,None为默认值 tip = request.POST.get("tip", None) # 读取post数据,None为默认值 type = request.POST.get("type", None) # 读取post数据,None为默认值 if request.method == "GET": diaryid = request.GET.get("diaryid", None) # 读取get数据,None为默认值 tip = request.GET.get("tip", None) # 读取get数据,None为默认值 type = request.GET.get("type", None) # 读取get数据,None为默认值 print("修改状态:日志ID", diaryid, "状态:", type) try: diary = DiaryDAO.selectDiary(diaryid) if (diary): if (type == "2" and not diary.type == "2"): #如果新类型为出售中,并且之前不是出售中,则增加用户的积分 user = UserDAO.getUserInfoId(diary.userid) #查询用户 user.zannum = user.zannum + diary.money #设置用户赞积分 UserDAO.updateUserInfo(user) if (type == "3" and not diary.type == "3"): #如果新类型为已汇款,并且之前不是已汇款,则增加用户的汇款金额 user = UserDAO.getUserInfoId(diary.userid) #查询用户 user.gold(user.gold + diary.money) #设置用户已回款金额 #如果之前是出售中,则删除出售中金额 if (diary.type == "2"): user.zannum(user.zannum - diary.money) #设置用户赞积分 UserDAO.updateUserInfo(user) diary.urlcontent = tip diary.type = type diary.date = TimeUtil.getCurrentDate() diary.time = TimeUtil.getCurrentTime() DiaryDAO.updatediary(diary) result["data"] = "0" result["respcode"] = ResultCode.SUCCESS result["errorcode"] = "" result["message"] = "修改日志成功" print('修改日志成功') return JsonResponse(result) except Exception as e: print(e) result["data"] = "0" result["respcode"] = ResultCode.FAIL result["errorcode"] = ResultCode.FAIL result["message"] = "修改日志失败" print('修改日志失败') return JsonResponse(result)
def addComment(request): result = {} comment = Comment() if request.method == "POST": diaryid = request.POST.get("diaryid", None) # 读取post数据,None为默认值 comment_user_id = request.POST.get("userid", None) # 读取post数据,None为默认值 comment_detail = request.POST.get("content", None) # 读取post数据,None为默认值 if request.method == "GET": diaryid = request.GET.get("diaryid", None) # 读取get数据,None为默认值 comment_user_id = request.GET.get("userid", None) # 读取get数据,None为默认值 comment_detail = request.POST.get("content", None) # 读取get数据,None为默认值 print("增加评论接口参数:日志ID", diaryid, "评论用户ID", comment_user_id, "评论内容", comment_detail) try: comment.comment_detail = comment_detail comment.comment_user_id = comment_user_id comment.diaryid = diaryid comment.comment_time = TimeUtil.getCurrentTimeAndDate() CommentDAO.addComment(comment) diary = DiaryDAO.selectDiary(diaryid) diary.commentnum = diary.commentnum() + 1 DiaryDAO.updatediary(diary) result["data"] = "0" result["errorcode"] = "" result["message"] = "评论成功" result["respcode"] = ResultCode.SUCCESS print('评论成功') except Exception as e: print(e) result["data"] = "" result['errorcode'] = ResultCode.FAIL result["message"] = "评论失败" result["respcode"] = ResultCode.FAIL print('评论失败') return JsonResponse(result)
def getdiaryurl(request): global urlpath if request.method == "POST": diaryid = request.POST.get("diaryid", None) # 读取post数据,None为默认值 if request.method == "GET": diaryid = request.GET.get("diaryid", None) # 读取post数据,None为默认值 print("web查看日志(链接)接口参数:日志id:", diaryid) diary = DiaryDAO.selectDiary(diaryid) if (diary): diary.tuijiannum = diary.tuijiannum + 1 DiaryDAO.updatediary(diary) qun = QunDAO.getqunInfoqunid(diary.qunid) if (diary.diarytype == ResultCode.CONTENT_TYPEURL): filepath = diary.urlcontent if (filepath and not filepath == ''): realPath = request.getSession().getServletContext( ).getRealPath("") htmlfile = open(realPath + filepath) contentstr = htmlfile.readlines() contentstr = contentstr.replace('src="/', 'src="' + urlpath + '/') dict = { 'contentstr': contentstr, 'title': diary.urltitle, 'paper_time': diary.date, 'paper_qun': qun.aname, 'tuijian_num': str(diary.tuijiannum), } return render_to_response("diaryurl_back.html", dict) # 返回文件响应,第二个参数必须为字典 else: pass
def deldealinfomore(request): result = {} if request.method == "POST": deal = request.POST.get("deal", 0) # 读取post数据,None为默认值 userid_source = request.POST.get("userid_source", 0) # 读取post数据,None为默认值 diaryid_source = request.POST.get("diaryid_source", 0) # 读取post数据,None为默认值 qunid_source = request.POST.get("qunid_source", 0) # 读取post数据,None为默认值 userid_destination = request.POST.get("userid_destination", 0) # 读取post数据,None为默认值 diaryid_destination = request.POST.get("diaryid_destination", 0) # 读取post数据,None为默认值 qunid_destination = request.POST.get("qunid_destination", 0) # 读取post数据,None为默认值 if request.method == "GET": deal = request.GET.get("deal", 0) # 读取get数据,None为默认值 userid_source = request.GET.get("userid_source", 0) # 读取get数据,None为默认值 diaryid_source = request.GET.get("diaryid_source", 0) # 读取get数据,None为默认值 qunid_source = request.GET.get("qunid_source", 0) # 读取get数据,None为默认值 userid_destination = request.GET.get("userid_destination", 0) # 读取get数据,None为默认值 diaryid_destination = request.GET.get("diaryid_destination", 0) # 读取get数据,None为默认值 qunid_destination = request.GET.get("qunid_destination", 0) # 读取get数据,None为默认值 print("删除更多操作接口参数:deal", deal) more = More() more.deal = deal more.userid_source = userid_source more.userid_destination = userid_destination more.diaryid_source = diaryid_source more.diaryid_destination = diaryid_destination more.qunid_source = qunid_source more.qunid_destination = qunid_destination more = MoreDAO.selectmoreInfomore(more) if (more): MoreDAO.deldealInfoid(more.id) result["data"] = "" result["respcode"] = ResultCode.SUCCESS result["errorcode"] = ResultCode.SUCCESS result["message"] = "删除处理成功" #如果是日志点赞则添加到日志属性中去 if (more.diaryid_destination): diary = DiaryDAO.selectDiary(more.diaryid_destination) if (diary): if (more.deal == ResultCode.DIARY_ZAN): diary.zannum = diary.zannum - 1 DiaryDAO.updatediary(diary) elif (more.deal == ResultCode.DIARY_SHOUCANG): diary.shoucangnum = diary.shoucangnum - 1 DiaryDAO.updatediary(diary) elif (more.deal == ResultCode.DIARY_TUIJIAN): diary.tuijiannum = diary.tuijiannum - 1 DiaryDAO.updatediary(diary) #如果是群组点赞 则添加到群属性中 elif (more.qunid_destination()): qun = QunDAO.getqunInfoqunid(more.qunid_destination) if (qun): if (more.deal == ResultCode.QUN_ZAN): qun.zannum = qun.zannum - 1 QunDAO.updatequnInfoqun(qun) elif (more.deal == ResultCode.QUN_SHOUCANG): qun.shoucangnum = qun.shoucangnum - 1 QunDAO.updatequnInfoqun(qun) elif (more.deal == ResultCode.QUN_TUIJIAN): qun.tuijiannum = qun.tuijiannum - 1 QunDAO.updatequnInfoqun(qun) #如果是用户点赞 则添加到用户属性中 elif (more.userid_destination): user = UserDAO.getUserInfoId(more.userid_destination) if (user): if (more.deal == ResultCode.USER_ZAN): user.zannum = user.zannum - 1 UserDAO.updateUserInfo(user) if (more.deal == ResultCode.USER_SHOUCANG): user.shoucangnum = user.shoucangnum - 1 UserDAO.updateUserInfo(user) if (more.deal == ResultCode.USER_TUIJIAN): user.tuijiannum = user.tuijiannum - 1 UserDAO.updateUserInfo(user) return JsonResponse(result)
def deldeal(request): result = {} if request.method == "POST": id = request.POST.get("id", None) # 读取post数据,None为默认值 if request.method == "GET": id = request.GET.get("id", None) # 读取get数据,None为默认值 print("删除更多操作接口参数:操作id", id) more = MoreDAO.selectdealInfoid(id) try: MoreDAO.deldealInfoid(id) result["data"] = "" result["respcode"] = ResultCode.SUCCESS result["errorcode"] = ResultCode.SUCCESS result["message"] = "删除处理成功" #如果是日志点赞则添加到日志属性中去 if (more.diaryid_destination): diary = DiaryDAO.selectDiary(more.diaryid_destination) if (diary): if (more.deal == ResultCode.DIARY_ZAN): diary.zannum = diary.zannum - 1 DiaryDAO.updatediary(diary) elif (more.deal == ResultCode.DIARY_SHOUCANG): diary.shoucangnum = diary.shoucangnum - 1 DiaryDAO.updatediary(diary) elif (more.deal == ResultCode.DIARY_TUIJIAN): diary.tuijiannum = diary.tuijiannum - 1 DiaryDAO.updatediary(diary) #如果是群组点赞 则添加到群属性中 elif (more.qunid_destination): qun = QunDAO.getqunInfoqunid(more.qunid_destination) if (qun): if (more.deal == ResultCode.QUN_ZAN): qun.zannum = qun.zannum - 1 QunDAO.updatequnInfoqun(qun) elif (more.deal == ResultCode.QUN_SHOUCANG): qun.shoucangnum = qun.shoucangnum - 1 QunDAO.updatequnInfoqun(qun) elif (more.deal == ResultCode.QUN_TUIJIAN): qun.tuijiannum = qun.tuijiannum - 1 QunDAO.updatequnInfoqun(qun) #如果是用户点赞 则添加到用户属性中 elif (more.userid_destination): user = UserDAO.getUserInfoId(more.userid_destination) if (user): if (more.deal == ResultCode.USER_ZAN): user.zannum = user.zannum - 1 UserDAO.updateUserInfo(user) if (more.deal == ResultCode.USER_SHOUCANG): user.shoucangnum = user.shoucangnum - 1 UserDAO.updateUserInfo(user) if (more.deal == ResultCode.USER_TUIJIAN): user.tuijiannum = user.tuijiannum - 1 UserDAO.updateUserInfo(user) except Exception as e: result["data"] = "" result["respcode"] = ResultCode.FAIL result["errorcode"] = ResultCode.FAIL result["message"] = "删除处理成功" return JsonResponse(result)
def adddeal(request): result = {} if request.method == "POST": deal = request.POST.get("deal", None) # 读取post数据,None为默认值 userid_source = request.POST.get("userid_source", 0) # 读取post数据,None为默认值 diaryid_source = request.POST.get("diaryid_source", 0) # 读取post数据,None为默认值 qunid_source = request.POST.get("qunid_source", 0) # 读取post数据,None为默认值 userid_destination = request.POST.get("userid_destination", 0) # 读取post数据,None为默认值 diaryid_destination = request.POST.get("diaryid_destination", 0) # 读取post数据,None为默认值 qunid_destination = request.POST.get("qunid_destination", 0) # 读取post数据,None为默认值 if request.method == "GET": deal = request.GET.get("deal", None) # 读取get数据,None为默认值 userid_source = request.GET.get("userid_source", 0) # 读取get数据,None为默认值 diaryid_source = request.GET.get("diaryid_source", 0) # 读取get数据,None为默认值 qunid_source = request.GET.get("qunid_source", 0) # 读取get数据,None为默认值 userid_destination = request.GET.get("userid_destination", 0) # 读取get数据,None为默认值 diaryid_destination = request.GET.get("diaryid_destination", 0) # 读取get数据,None为默认值 qunid_destination = request.GET.get("qunid_destination", 0) # 读取get数据,None为默认值 print("添加更多操作接口参数:操作类型", deal, "源用户id", userid_source, "源日志id:", diaryid_source, "目的用户id:", userid_destination, "目的日志id:", diaryid_destination, "源群id:", qunid_source, "目的群id:", qunid_destination) if (userid_source == userid_destination): result["data"] = "" result["respcode"] = ResultCode.FAIL result["errorcode"] = ResultCode.FAIL result["message"] = "添加处理失败" return JsonResponse(result) more = More() more.deal = deal more.userid_source = userid_source more.userid_destination = userid_destination more.diaryid_source = diaryid_source more.diaryid_destination = diaryid_destination more.qunid_source = qunid_source more.qunid_destination = qunid_destination more1 = MoreDAO.selectmoreInfomore(more) if (more1): result["data"] = model_to_dict(more1) result["respcode"] = ResultCode.SUCCESS result["errorcode"] = ResultCode.SUCCESS result["message"] = "添加处理成功" else: try: MoreDAO.adddeal(more) more = MoreDAO.selectmoreInfomore(more) result["data"] = model_to_dict(more) result["respcode"] = ResultCode.SUCCESS result["errorcode"] = ResultCode.SUCCESS result["message"] = "添加处理成功" #如果是日志点赞则添加到日志属性中去 if (diaryid_destination != 0): diary = DiaryDAO.selectDiary(diaryid_destination) if (diary): if (deal == ResultCode.DIARY_ZAN): diary.zannum = diary.zannum + 1 DiaryDAO.updatediary(diary) elif (deal == ResultCode.DIARY_SHOUCANG): diary.shoucangnum = diary.shoucangnum + 1 DiaryDAO.updatediary(diary) elif (deal == ResultCode.DIARY_TUIJIAN): diary.tuijiannum = diary.tuijiannum + 1 DiaryDAO.updatediary(diary) #如果是群组点赞 则添加到群属性中 elif (qunid_destination != 0): qun = QunDAO.getqunInfoqunid(qunid_destination) if (qun): if (deal == ResultCode.QUN_ZAN): qun.zannum = qun.zannum + 1 QunDAO.updatequnInfoqun(qun) elif (deal == ResultCode.QUN_SHOUCANG): qun.shoucangnum = qun.shoucangnum + 1 QunDAO.updatequnInfoqun(qun) elif (deal == ResultCode.QUN_TUIJIAN): qun.tuijiannum = qun.tuijiannum + 1 QunDAO.updatequnInfoqun(qun) #如果是用户点赞 则添加到用户属性中 elif (userid_destination != 0): user = UserDAO.getUserInfoId(userid_destination) if (user): if (deal == ResultCode.USER_ZAN): user.zannum = user.zannum + 1 UserDAO.updateUserInfo(user) if (deal == ResultCode.USER_SHOUCANG): user.shoucangnum = user.shoucangnum + 1 UserDAO.updateUserInfo(user) if (deal == ResultCode.USER_TUIJIAN): user.tuijiannum = user.tuijiannum + 1 UserDAO.updateUserInfo(user) except Exception as e: result["data"] = "" result["respcode"] = ResultCode.FAIL result["errorcode"] = ResultCode.FAIL result["message"] = "添加处理失败" return JsonResponse(result)
def updatecaidanimg(request): diary = Diary() result = {} imagePath = [] realPath = STATICFILES_DIRS[0] + "/upload/userDiary/" # realPath = request.getSession().getServletContext().getRealPath("userDiary/") if request.method == "POST": content = request.POST.get("content", None) # 读取post数据,None为默认值 qunid = request.POST.get("qunid", None) # 读取post数据,None为默认值 qundiarytype = request.POST.get("qundiarytype", None) # 读取post数据,None为默认值 state = request.POST.get("state", None) # 读取post数据,None为默认值 money = request.POST.get("money", None) # 读取post数据,None为默认值 urltitle = request.POST.get("urltitle", None) # 读取post数据,None为默认值 urlcontent = request.POST.get("urlcontent", None) # 读取post数据,None为默认值 userid = request.POST.get("userid", None) # 读取post数据,None为默认值 diaryid = request.POST.get("diaryid", None) # 读取post数据,None为默认值 if request.method == "GET": content = request.GET.get("content", None) # 读取get数据,None为默认值 qunid = request.GET.get("qunid", None) # 读取get数据,None为默认值 qundiarytype = request.POST.get("qundiarytype", None) # 读取get数据,None为默认值 state = request.POST.get("state", None) # 读取get数据,None为默认值 money = request.POST.get("money", None) # 读取get数据,None为默认值 urltitle = request.POST.get("urltitle", None) # 读取get数据,None为默认值 urlcontent = request.POST.get("urlcontent", None) # 读取get数据,None为默认值 userid = request.POST.get("userid", None) # 读取get数据,None为默认值 diaryid = request.POST.get("diaryid", None) # 读取get数据,None为默认值 print("修改菜单(图片)接口参数:用户id:", userid, "内容:", content, "可见群组", qunid) print("上传图片的根目录为:" + realPath) diary = DiaryDAO.selectDiary(diaryid) files = request.FILES.getlist('files') for i in range(len(files)): multFile = files[i] filenameString = userid + "_" + str(int( time.time())) + "_" + str(i) + ".png" if (not multFile): print("文件未上传") else: # print("文件的长度为:" + multFile.getSize()) # print("文件的类型:" + multFile.getContentType()) # print("文件的属性域:" + multFile.getName()) # print("文件的原名:" + multFile.getOriginalFilename()) filepath = realPath + "/" + filenameString f_obj = open(filepath, 'wb+') for chunk in multFile.chunks(): f_obj.write(chunk) f_obj.close() fileName = STATIC_URL1 + "upload/userDiary/" + filenameString imagePath.append(fileName) imgnum = len(imagePath) if imgnum > 0: diary.imgone = imagePath[0] if imgnum > 1: diary.imgone = imagePath[1] if imgnum > 2: diary.imgone = imagePath[2] if imgnum > 3: diary.imgone = imagePath[3] if imgnum > 4: diary.imgone = imagePath[4] if imgnum > 5: diary.imgone = imagePath[5] if imgnum > 6: diary.imgone = imagePath[6] if imgnum > 7: diary.imgone = imagePath[7] if imgnum > 8: diary.imgone = imagePath[8] diary.diarytype = ResultCode.CONTENT_TYPEIMG diary.state = state diary.userid = userid diary.content = content diary.qunid = qunid diary.type = qundiarytype diary.urltitle = urltitle diary.urlcontent = urlcontent diary.money = money diary.time = TimeUtil.getCurrentTime() diary.date = TimeUtil.getCurrentDate() DiaryDAO.updatediary(diary) result["data"] = "0" result["respcode"] = ResultCode.SUCCESS result["errorcode"] = "" result["message"] = "修改成功" return JsonResponse(result)