コード例 #1
0
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 result
コード例 #2
0
ファイル: views.py プロジェクト: loulonglong/django
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)
コード例 #3
0
def addtongzhiword(request):
    result = {}
    message = Notice()
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        state = int(request.POST.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.POST.get("messagetype",
                                           None))  # 读取post数据,None为默认值
        contenttype = int(request.POST.get("contenttype",
                                           None))  # 读取post数据,None为默认值
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        state = int(request.GET.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.GET.get("messagetype",
                                          None))  # 读取post数据,None为默认值
        contenttype = int(request.GET.get("contenttype",
                                          None))  # 读取post数据,None为默认值
        send_id = int(request.GET.get("send_id", None))  # 读取post数据,None为默认值

    print("增加通知(仅文字)接口参数:发送用户id:", send_id, "内容:", content, "接收者:", receive_id)
    try:
        message.messagetype = messagetype
        message.contenttype = contenttype
        message.state = state
        message.send_id = send_id
        message.receive_id = receive_id
        message.content = content
        message.time = TimeUtil.getCurrentTime()
        message.date = TimeUtil.getCurrentDate()
        TongzhiDAO.addTongzhi(message)

        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 result
コード例 #4
0
def addtongzhivideo(request):
    message = Notice()
    result = {}
    videPath = []

    realPath = request.getSession().getServletContext().getRealPath("tongzhi/")
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        state = int(request.POST.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.POST.get("messagetype",
                                           None))  # 读取post数据,None为默认值
        contenttype = int(request.POST.get("contenttype",
                                           None))  # 读取post数据,None为默认值
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        state = int(request.GET.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.GET.get("messagetype",
                                          None))  # 读取post数据,None为默认值
        contenttype = int(request.GET.get("contenttype",
                                          None))  # 读取post数据,None为默认值
        send_id = int(request.GET.get("send_id", None))  # 读取post数据,None为默认值

    print("增加通知(视频)接口参数:发送用户id:", send_id, "内容:", content, "接收用户", receive_id)
    print("上传视频的根目录为:", realPath)

    files = request.FILES.getlist('files')
    for i in range(len(files)):
        multFile = files[i]
        filename = send_id + "_" + str(time.time()) + "_" + str(i) + ".png"
        if (not multFile):
            print("文件未上传")
        else:
            print("文件的长度为:" + multFile.getSize())
            print("文件的类型:" + multFile.getContentType())
            print("文件的属性域:" + multFile.getName())
            print("文件的原名:" + multFile.getOriginalFilename())
            #?????????????????
            filepath = realPath + "/" + filename

            f_obj = open(filepath, 'wb+')
            for chunk in multFile.chunks():
                f_obj.write(chunk)
            f_obj.close()

            fileName = "/userDiary/" + filename
            videPath.add(fileName)
    if (len(videPath) > 0):
        message.videourl = videPath[0]  # 将缩略图放在第一个
        message.messagetype = messagetype
        message.contenttype = contenttype
        message.state = state
        message.send_id = send_id
        message.receive_id = receive_id
        message.content = content
        message.time = TimeUtil.getCurrentTime()
        message.date = TimeUtil.getCurrentDate()
        TongzhiDAO.addTongzhi(message)
    else:
        # 无视频
        result["data"] = "0"
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ""
        result["message"] = "失败"

    return result
コード例 #5
0
def addtongzhiimg(request):
    message = Notice()
    result = {}
    imagePath = []
    realPath = request.getSession().getServletContext().getRealPath("tongzhi/")
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        state = int(request.POST.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.POST.get("messagetype",
                                           None))  # 读取post数据,None为默认值
        contenttype = int(request.POST.get("contenttype",
                                           None))  # 读取post数据,None为默认值
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        state = int(request.GET.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.GET.get("messagetype",
                                          None))  # 读取post数据,None为默认值
        contenttype = int(request.GET.get("contenttype",
                                          None))  # 读取post数据,None为默认值
        send_id = int(request.GET.get("send_id", None))  # 读取post数据,None为默认值

    print("增加通知(图片)接口参数:发送用户id:", send_id, "接收用户id", receive_id)
    print("上传图片的根目录为:", realPath)

    files = request.FILES.getlist('files')

    for i in range(len(files)):
        multFile = files[i]
        filename = send_id + "_" + str(time.time()) + "_" + str(i) + ".png"
        if (not multFile):
            print("文件未上传")
        else:
            print("文件的长度为:" + multFile.getSize())
            print("文件的类型:" + multFile.getContentType())
            print("文件的属性域:" + multFile.getName())
            print("文件的原名:" + multFile.getOriginalFilename())
            # ?????????????????
            filepath = realPath + "/" + filename

            f_obj = open(filepath, 'wb+')
            for chunk in multFile.chunks():
                f_obj.write(chunk)
            f_obj.close()

            fileName = "/userDiary/" + filename
            imagePath.add(fileName)

    if (len(imagePath) > 0):
        # 有图像
        imgnum = len(imagePath)
        if imgnum > 0: message.imgone = imagePath[0]
        if imgnum > 1: message.imgtwo = imagePath[1]
        if imgnum > 2: message.imgthree = imagePath[2]
        if imgnum > 3: message.imgfour = imagePath[3]
        if imgnum > 4: message.imgfive = imagePath[4]
        if imgnum > 5: message.imgsix = imagePath[5]
        if imgnum > 6: message.imgseven = imagePath[6]
        if imgnum > 7: message.imgeight = imagePath[7]
        if imgnum > 8: message.imgnine = imagePath[8]

        message.messagetype = messagetype
        message.contenttype = contenttype
        message.state = state
        message.send_id = send_id
        message.receive_id = receive_id
        message.content = content
        message.time = TimeUtil.getCurrentTime()
        message.date = TimeUtil.getCurrentDate()
        TongzhiDAO.addTongzhi(message)
    else:
        # 无图像
        message.messagetype = messagetype
        message.contenttype = contenttype
        message.state = state
        message.send_id = send_id
        message.receive_id = receive_id
        message.content = content
        message.time = TimeUtil.getCurrentTime()
        message.date = TimeUtil.getCurrentDate()
        TongzhiDAO.addTongzhi(message)

    result["data"] = "0"
    result["respcode"] = ResultCode.SUCCESS
    result["errorcode"] = ""
    result["message"] = "成功"
    return result
コード例 #6
0
def addqunchatmessage(request):
    result = {}
    message = Chat_Message()
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取post数据,None为默认值
        messagetype = request.POST.get("messagetype",
                                       None)  # 读取post数据,None为默认值
        contenttype = request.POST.get("contenttype",
                                       None)  # 读取post数据,None为默认值
        send_id = request.POST.get("send_id", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取post数据,None为默认值
        messagetype = request.GET.get("messagetype", None)  # 读取post数据,None为默认值
        contenttype = request.GET.get("contenttype", None)  # 读取post数据,None为默认值
        send_id = request.GET.get("send_id", None)  # 读取post数据,None为默认值

    print("增加群聊(仅文字)接口参数:发送用户id:", send_id, "内容:", content, "接收群:", qunid)

    #查询一遍是否存在聊天关系  此关系在进群时就存在
    chatuser = Chatuser()
    chatuser.send_id = qunid
    chatuser.receive_id = send_id
    chatuser.usertype = ResultCode.CHATUSER_TYPE_QUN
    chatuser = ChatuserDAO.querychatqunexist(chatuser)
    if (chatuser == None):
        message.abid = str(qunid)
        #在发送端添加主动发送的群聊关系
        chatuser = Chatuser()
        chatuser.usertype = ResultCode.CHATUSER_TYPE_QUN  #群聊用户
        chatuser.state = ResultCode.CHATUSER_OLD  #设置聊天关系为已读
        chatuser.send_id = qunid
        chatuser.receive_id = send_id  #用户查询聊天对象是根据receiveid查询的,所以讲接收端设置为自己
        chatuser.date = TimeUtil.getCurrentDate()
        chatuser.time = TimeUtil.getCurrentTime()
        chatuser.content = content
        chatuser.abid = str(qunid)
        ChatuserDAO.addchatuser(chatuser)

    #如果存在这个关系群
    else:
        message.abid = chatuser.abid  #设置message的abid
        #设置发送端群聊关系信息
        chatuser.state = ResultCode.CHATUSER_OLD  #设置聊天关系为没有新信息
        chatuser.date = TimeUtil.getCurrentDate()
        chatuser.time = TimeUtil.getCurrentTime()
        chatuser.content = content
        ChatuserDAO.updatachatuserforid(chatuser)

        #设置所有接收收端群聊关心信息
        chatuser.state = ResultCode.CHATUSER_NEW
        ChatuserDAO.updatachatuserforabid(chatuser)

    #添加聊天信息
    message.messagetype = messagetype
    message.contenttype = contenttype
    message.send_id = send_id
    message.content = content
    message.receive_id = qunid
    message.time = TimeUtil.getCurrentTime()
    message.date = TimeUtil.getCurrentDate()
    Chat_MessageDAO.addMessage(message)

    #通知接收者
    try:
        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)
コード例 #7
0
def addchatmessage(request):
    result = {}
    message = Chat_Message()
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        receive_id = request.POST.get("receive_id", None)  # 读取post数据,None为默认值
        send_id = request.POST.get("send_id", None)  # 读取post数据,None为默认值
        messagetype = request.POST.get("messagetype",
                                       None)  # 读取post数据,None为默认值
        contenttype = request.POST.get("contenttype",
                                       None)  # 读取post数据,None为默认值
        abid = request.POST.get("abid", 0)  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        receive_id = request.GET.get("receive_id", None)  # 读取post数据,None为默认值
        send_id = request.GET.get("send_id", None)  # 读取post数据,None为默认值
        messagetype = request.GET.get("messagetype", None)  # 读取post数据,None为默认值
        contenttype = request.GET.get("contenttype", None)  # 读取post数据,None为默认值
        abid = request.GET.get("abid", 0)  # 读取post数据,None为默认值

    print("增加聊天(仅文字)接口参数:发送用户id:", send_id, "内容:", content, "接收者:", receive_id,
          "abid", abid)

    # 如果abid=0,则表明之前不存在聊天关系或不知道之前存在的聊天关系  在pc端就不知道abid
    if (not abid or "_" not in abid):
        # 查询一遍是否存在聊天关系   只用查询接收端就好,因为一端有两段都有
        mychatuser = Chatuser.objects.create(send_id=send_id,
                                             receive_id=receive_id)
        mychatuser = ChatuserDAO.querychatuserexist(mychatuser)
        if (not mychatuser):
            message.abid = str(send_id) + "_" + str(receive_id)
            # 在发送端添加主动发送的群聊关系
            mychatuser = Chatuser.objects.create()
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_SEND  #主动发送的用户
            mychatuser.state = ResultCode.CHATUSER_OLD  #设置聊天关系为已读
            mychatuser.send_id = receive_id
            mychatuser.receive_id = send_id  #用户查询聊天对象是根据receiveid查询的
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            mychatuser.abid = str(send_id) + "_" + str(receive_id)
            ChatuserDAO.addchatuser(mychatuser)
            #在接收端添加被动接收的群聊关系
            mychatuser = Chatuser.objects.create()
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
            mychatuser.state = ResultCode.CHATUSER_NEW  #设置聊天关系为有新信息
            mychatuser.send_id = send_id
            mychatuser.receive_id = receive_id
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            mychatuser.abid = str(send_id) + "_" + str(receive_id)
            ChatuserDAO.addchatuser(mychatuser)

        #如果存在这个关系群
        else:
            message.abid = mychatuser.abid  #设置message的abid
            #设置接收端聊天关系信息
            mychatuser.state = ResultCode.CHATUSER_NEW  #设置聊天关系为没有信息
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            ChatuserDAO.updatachatuserforuser(mychatuser)
            #设置接收端聊天关系信息
            mychatuser.send_id = receive_id
            mychatuser.receive_id = send_id
            mychatuser = ChatuserDAO.querychatuserexist(mychatuser)
            if (mychatuser):
                mychatuser.state = ResultCode.CHATUSER_OLD
                mychatuser.date = TimeUtil.getCurrentDate()
                mychatuser.sime = TimeUtil.getCurrentTime()
                mychatuser.content = content
                ChatuserDAO.updatachatuserforuser(mychatuser)
    else:
        message.abid = abid  #设置message的abid
        mychatuser = Chatuser.objects.create()
        mychatuser.send_id = send_id
        mychatuser.receive_id = receive_id
        arrStrings = abid.split("_")
        #如果abid的前面是接收者id,表明聊天关系是接收者主动发送引起的
        if (arrStrings[0] == str(receive_id)):
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_SEND
        else:
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
        mychatuser = ChatuserDAO.querychatuserexist(mychatuser)

        if (mychatuser == None):
            result['data'] = ''
            result["respcode"] = ResultCode.FAIL
            result["errorcode"] = ""
            result["message"] = "对方已删除好友关系"
            return JsonResponse(result)

        #设置接收端聊天关系信息
        mychatuser.state = ResultCode.CHATUSER_NEW  #设置聊天关系为没有信息
        mychatuser.date = TimeUtil.getCurrentDate()
        mychatuser.time = TimeUtil.getCurrentTime()
        mychatuser.content = content
        ChatuserDAO.updatachatuserforuser(mychatuser)

        #sendid用户在查询的时候是看receiveid的,所以要反过来写。
        mychatuser.send_id = receive_id
        mychatuser.receive_id = send_id
        mychatuser = ChatuserDAO.querychatuserexist(mychatuser)
        if (mychatuser):
            mychatuser.state = ResultCode.CHATUSER_OLD
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            ChatuserDAO.updatachatuserforuser(mychatuser)

    #添加聊天信息
    message.messagetype = messagetype
    message.contenttype = contenttype
    message.send_id = send_id
    message.content = content
    message.receive_id = receive_id
    message.time = TimeUtil.getCurrentTime()
    message.date = TimeUtil.getCurrentDate()
    Chat_MessageDAO.addMessage(message)

    result["data"] = "0"
    result["respcode"] = ResultCode.SUCCESS
    result["errorcode"] = ""
    result["message"] = "成功"

    return JsonResponse(result)
コード例 #8
0
ファイル: views.py プロジェクト: 626626cdllp/django
def getinfo(ocrtext,qun,user,filepath):
    ocrtext=ocrtext.replace(" ", "")
    respContent=""
    if (len(allname)==0):
        # 主要配置表中有,就都能识别
        jsonobj=json.loads(qun.gonggao.replace('\'','\"'))   # 获取配置的价格表
        for keystr in jsonobj:
            money = jsonobj[keystr]
            onerow = keystr.split("|")
            if (len(onerow)==3):
                allname.append(keystr)
                allqiye.append(onerow[0])
                allchanpin.append(onerow[1])
                allbank.append(onerow[2])
                alljiage.append(money)

    # 分为大杯和中杯饮品,和多少元代金券
    bank=""
    qiye=""
    chanpin = ""
    quanma=""
    money=0
    canshibie=False
    # 先用企业和商品类型识别一遍,这个为必须包含项
    for i in range(len(allqiye)):
        if (allqiye[i] in ocrtext and allchanpin[i] in ocrtext):
            qiye = allqiye[i]
            chanpin=allchanpin[i]
            bank = allbank[i]
            money= float(alljiage[i])
            canshibie=True
            break


    # 如果不能识别,就返回不能识别说明
    if (not canshibie):
        respContent = '无法识别此类商品或此类商品已不再收录,您可以回复jg查看收录商品,或通过其他方式上传。\n\n'\
                      + '<a href="'+urlpath+'piaoquan/mydiary?qunid=999&typeindex=1&userid='+str(user.id)+'">券码管理</a>\n\n'\
                      + '<a href="'+urlpath+'piaoquan/setting?userid='+str(user.id)+'">个人账户中心</a>\n\n'\
                      + '回复“jg”查询商品价格!'
        # print(respContent)
        return respContent
    # 再用企业、商品类型、银行识别一遍,作为次选。因为银行并不是必选项
    for i in range(len(allqiye)):
        if (allqiye[i] in ocrtext and allchanpin[i] in ocrtext and allbank[i] in ocrtext):
            qiye = allqiye[i]
            chanpin=allchanpin[i]
            bank = allbank[i]
            money= float(alljiage[i])
            break

    # print(qiye, chanpin, bank, money)
    # 如果有图片就使用图片识别券码
    if (filepath):
        try:
            code = QRcode.ocr_qrcode_zxing(filepath)  # 识别图中的二维码
            print("第一种方式二维码识别结果:",code)
            # if(code==None or code=="null" or code==""):
            #     code = QRcode.ocr_qrcode_zxing(filepath)   # 识别图中的二维码
            # else:
            #     # 判断编码是不是只有字母数字和=
            #     regexstr="^[a-zA-Z=0-9]+$"
            #     pattern = re.compile(regexstr)
            #     result = re.match(pattern,code)
            #     if (not result):
            #         return '无法识别二维码'

# 				print("二维码识别结果:"+code)
            if (code.find("=")>-1):
                quanma = code[0:code.find("=")]
            else:
                quanma = code
        except Exception as e:
            print("二维码识别出错:",e)


    # 没有图片或者图片匹配不到就正则表达式识别
    if (quanma==""):
        # 识别券码
        regexstr="[0-9A-Za-z]{10,30}"    # 查找指定的字符串
        pattern=re.compile(regexstr)
        matcher = re.match(pattern, ocrtext)
        i = 0
        while(matcher.groups(i)):
            # 如果在匹配到的数字前出现的“订单编号”,则放弃
            if (matcher.start(i)-8>0):
                if ('订单编号' in ocrtext[matcher.start(i)-8,matcher.start(i)]):
                    i += 1
                    continue

            quanma= matcher.group(i)
            break



    # 如果券码为""
    if (quanma==""):
        # 如果没有图片,则放弃
        if (filepath==None):
            respContent = "无法识别券码,请通过其他方式上传,或者联系客服\n\n"\
                          + "<a href=\""+urlpath+"piaoquan/mydiary.jsp?qunid=999&typeindex=1&userid="+str(user.getId())+"\">券码管理</a>\n\n"\
                          + "<a href=\""+urlpath+"piaoquan/setting.jsp?userid="+str(user.getId())+"\">个人账户中心</a>\n\n"\
                          + "回复“jg”查询商品价格!"
            return respContent
        else:
            # 如果有图片,则券号自定义为no+时间+index
            global index
            index+=1
            quanma="no"+TimeUtil.getCurrentDate1()+TimeUtil.getCurrentTime1()+str(index)



    # 修改图片名称为券号的名称
    picname =""
    if(filepath):
        mulu = filepath[0:filepath.rfind('/') + 1]   # 目录(带最后的/)
        # picname = filepath[filepath.rfind('/') + 1:]  # 文件名
        geshi =filepath[filepath.index('.')+1:]
        picname = quanma+"."+geshi
        newfilepath = mulu+picname
        if (os.path.exists(newfilepath)):
            os.remove(newfilepath)

        os.rename(filepath,newfilepath)
        print('将图片重命名为新图片名称:',newfilepath)

    content = qiye + "|" + chanpin + "|" + bank #要存储返回的内容
    tip="该票券不是第一次上传了\n"
    diary = DiaryDAO.selectDiaryforSerial(quanma)
    if (not diary):
        diary = Diary()
        diary.userid= user.id
        diary.qunid= 999
        if (not filepath):
            diary.diarytype=ResultCode.CONTENT_TYPEWORD  # 设置日志只有短信
        else:
            diary.diarytype=ResultCode.CONTENT_TYPEIMG  # 设置日志包含图片
        diary.type="1"
        diary.serial=quanma
        diary.state=0
        diary.content=content
        diary.time=TimeUtil.getCurrentTime()
        diary.date=TimeUtil.getCurrentDate()
        diary.money=10*int(money)    # 怎么设置价格
        if(filepath):
            datenow = TimeUtil.getCurrentMonth()
            diary.imgone= STATIC_URL1+ "upload/img/"+datenow+"/"+picname
        DiaryDAO.addDiary(diary)
        tip=""
        # 修改用户的以上传金额
        user.tuijiannum = user.tuijiannum+diary.money  # 设置用户以上传金额
        UserDAO.updateUserInfo(user)


    respContent = "您的券码已经收到录入,等待橙子权益的汇款即可。\n\n商品:"+content+"\n券码:"+quanma+"\n价格:¥"+str(money) \
                  + "\n\n<a href=\""+urlpath+"piaoquan/setting.jsp?userid="+str(user.id)+"\">个人账户中心</a>\n\n"\
                  + "<a href=\""+urlpath+"piaoquan/mydiary.jsp?qunid=999&typeindex=1&userid="+str(user.id)+"\">券码管理</a>\n\n"+tip\
                  + "回复“jg”查询商品价格!"

    return respContent
コード例 #9
0
ファイル: ChatController.py プロジェクト: loulonglong/django
def addchatmessage(request):
    result = {}
    message = Chat_Message()
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        receive_id = request.POST.get("receive_id", None)  # 读取post数据,None为默认值
        send_id = request.POST.get("send_id", None)  # 读取post数据,None为默认值
        messagetype = request.POST.get("messagetype",
                                       None)  # 读取post数据,None为默认值
        contenttype = request.POST.get("contenttype",
                                       None)  # 读取post数据,None为默认值
        abid = request.POST.get("abid", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        receive_id = request.GET.get("receive_id", None)  # 读取post数据,None为默认值
        send_id = request.GET.get("send_id", None)  # 读取post数据,None为默认值
        messagetype = request.GET.get("messagetype", None)  # 读取post数据,None为默认值
        contenttype = request.GET.get("contenttype", None)  # 读取post数据,None为默认值
        abid = request.GET.get("abid", None)  # 读取post数据,None为默认值

    print("增加聊天(仅文字)接口参数:发送用户id:" + send_id + "内容:" + content + "接收者:" +
          receive_id + "abid" + abid)

    # 如果abid=0,则表明之前不存在聊天关系或不知道之前存在的聊天关系  在pc端就不知道abid
    if (abid == None or "_" not in abid):
        # 查询一遍是否存在聊天关系   只用查询接收端就好,因为一端有两段都有
        mychatuser = Chatuser.objects.create(send_id=send_id,
                                             receive_id=receive_id)
        mychatuser = ChatuserDAO.querychatuserexist(mychatuser)
        if (mychatuser == None):
            message.abid = str(send_id) + "_" + str(receive_id)
            # 在发送端添加主动发送的群聊关系
            mychatuser = Chatuser.objects.create()
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_SEND  #主动发送的用户
            mychatuser.state = ResultCode.CHATUSER_OLD  #设置聊天关系为已读
            mychatuser.send_id = receive_id
            mychatuser.receive_id = send_id  #用户查询聊天对象是根据receiveid查询的
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            mychatuser.abid = str(send_id) + "_" + str(receive_id)
            ChatuserDAO.addchatuser(mychatuser)
            #在接收端添加被动接收的群聊关系
            mychatuser = Chatuser.objects.create()
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
            mychatuser.state = ResultCode.CHATUSER_NEW  #设置聊天关系为有新信息
            mychatuser.send_id = send_id
            mychatuser.receive_id = receive_id
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            mychatuser.abid = str(send_id) + "_" + str(receive_id)
            ChatuserDAO.addchatuser(mychatuser)

        #如果存在这个关系群
        else:
            message.abid = mychatuser.abid  #设置message的abid
            #设置接收端聊天关系信息
            mychatuser.state = ResultCode.CHATUSER_NEW  #设置聊天关系为没有信息
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            ChatuserDAO.updatachatuserforuser(mychatuser)
            #设置接收端聊天关系信息
            mychatuser.send_id = receive_id
            mychatuser.receive_id = send_id
            mychatuser = ChatuserDAO.querychatuserexist(mychatuser)
            if (mychatuser != None):
                mychatuser.state = ResultCode.CHATUSER_OLD
                mychatuser.date = TimeUtil.getCurrentDate()
                mychatuser.sime = TimeUtil.getCurrentTime()
                mychatuser.content = content
                ChatuserDAO.updatachatuserforuser(mychatuser)
    else:
        message.abid = abid  #设置message的abid
        mychatuser = Chatuser.objects.create()
        mychatuser.send_id = send_id
        mychatuser.receive_id = receive_id
        arrStrings = abid.split("_")
        #如果abid的前面是接收者id,表明聊天关系是接收者主动发送引起的
        if (arrStrings[0].equals(str(receive_id))):
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_SEND
        else:
            mychatuser.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
        mychatuser = ChatuserDAO.querychatuserexist(mychatuser)

        if (mychatuser == None):
            result['data'] = ''
            result["respcode"] = ResultCode.FAIL
            result["errorcode"] = ""
            result["message"] = "对方已删除好友关系"
            return result

        #设置接收端聊天关系信息
        mychatuser.state = ResultCode.CHATUSER_NEW  #设置聊天关系为没有信息
        mychatuser.date = TimeUtil.getCurrentDate()
        mychatuser.time = TimeUtil.getCurrentTime()
        mychatuser.content = content
        ChatuserDAO.updatachatuserforuser(mychatuser)

        #sendid用户在查询的时候是看receiveid的,所以要反过来写。
        mychatuser.send_id = receive_id
        mychatuser.receive_id = send_id
        mychatuser = ChatuserDAO.querychatuserexist(mychatuser)
        if (mychatuser != None):
            mychatuser.state = ResultCode.CHATUSER_OLD
            mychatuser.date = TimeUtil.getCurrentDate()
            mychatuser.time = TimeUtil.getCurrentTime()
            mychatuser.content = content
            ChatuserDAO.updatachatuserforuser(mychatuser)

    #添加聊天信息
    message.messagetype = messagetype
    message.contenttype = contenttype
    message.send_id = send_id
    message.content = content
    message.receive_id = receive_id
    message.time = TimeUtil.getCurrentTime()
    message.date = TimeUtil.getCurrentDate()
    Chat_MessageDAO.addMessage(message)

    result["data"] = "0"
    result["respcode"] = ResultCode.SUCCESS
    result["errorcode"] = ""
    result["message"] = "成功"
    '''
    #通知接收者
    try:
        if(messagetype==ResultCode.MESSAGE_TYPE_SIXIN):
            user=UserDAO.getUserInfoId(receive_id);
            if(user.push_channelId !=None and user.push_channelId()!=''):
                message_back = fun.chatmessage2back(message);
                jsonobject = json.loads(message_back);
                print(str(jsonobject));
                #push.AndroidPushMsgToSingleDevicemain(user.getPush_channelId(), "您有新的私信", content, ResultCode.PUSH_NEW_SIXIN,object.toString());
    except Exception as e:
        print(e)
    '''
    return result
コード例 #10
0
def updatecaidanimg(request):
    diary = Diary()
    result = {}
    imagePath = []
    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 = "/userDiary/" + filenameString
            imagePath.add(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 result
コード例 #11
0
def adddiaryword(request):
    result={}
    if request.method == "POST":
        diaryid = request.POST.get("diaryid", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取post数据,None为默认值
        state = request.POST.get("state", None)  # 读取post数据,None为默认值
        dealtype = request.POST.get("dealtype", None)  # 读取post数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取post数据,None为默认值
        parameter1 = request.POST.get("parameter1", None)  # 读取post数据,None为默认值
        parameter2 = request.POST.get("parameter2", None)  # 读取post数据,None为默认值
        parameter3 = request.POST.get("parameter3", None)  # 读取post数据,None为默认值
        parameter4 = request.POST.get("parameter4", None)  # 读取post数据,None为默认值
        parameter5 = request.POST.get("parameter5", None)  # 读取post数据,None为默认值
        parameter6 = request.POST.get("parameter6", None)  # 读取post数据,None为默认值
        parameter7 = request.POST.get("parameter7", None)  # 读取post数据,None为默认值
        parameter8 = request.POST.get("parameter8", None)  # 读取post数据,None为默认值
        parameter9 = request.POST.get("parameter9", None)  # 读取post数据,None为默认值
        parameter10 = request.POST.get("parameter10", None)  # 读取post数据,None为默认值

    if request.method == "GET":
        diaryid = request.GET.get("diaryid", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取get数据,None为默认值
        state = request.GET.get("state", None)  # 读取get数据,None为默认值
        dealtype = request.GET.get("dealtype", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值
        parameter1 = request.GET.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.GET.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.GET.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.GET.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.GET.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.GET.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.GET.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.GET.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.GET.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.GET.get("parameter10", None)  # 读取get数据,None为默认值

    print("增加日志处理接口参数:用户id:" + userid + "群id:" + qunid)

    try:
        dealdiary=Diarydeal()
        dealdiary.diaryid=diaryid
        dealdiary.qunid=qunid
        dealdiary.userid=userid
        dealdiary.state=state
        dealdiary.dealtype=dealtype
        dealdiary.date=TimeUtil.getCurrentDate()
        dealdiary.time=TimeUtil.getCurrentTime()
        dealdiary.parameter1=parameter1
        dealdiary.parameter2=parameter2
        dealdiary.parameter3=parameter3
        dealdiary.parameter4=parameter4
        dealdiary.parameter5=parameter5
        dealdiary.parameter6=parameter6
        dealdiary.parameter7=parameter7
        dealdiary.parameter8=parameter8
        dealdiary.parameter9=parameter9
        dealdiary.parameter10=parameter10

        DiaryDealDAO.addDealDiary(dealdiary)
        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 result
コード例 #12
0
def adddsomeiarydeal(request):
    result={}
    if request.method == "POST":
        liststr = request.POST.get("liststr", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取post数据,None为默认值
        useridstr = request.POST.get("userid", None)  # 读取post数据,None为默认值
        state = request.POST.get("state", None)  # 读取post数据,None为默认值
        dealtype = request.POST.get("dealtype", None)  # 读取post数据,None为默认值
        parameter1 = request.POST.get("parameter1", None)  # 读取post数据,None为默认值
        parameter2 = request.POST.get("parameter2", None)  # 读取post数据,None为默认值
        parameter3 = request.POST.get("parameter3", None)  # 读取post数据,None为默认值
        parameter4 = request.POST.get("parameter4", None)  # 读取post数据,None为默认值
        parameter5 = request.POST.get("parameter5", None)  # 读取post数据,None为默认值
        parameter6 = request.POST.get("parameter6", None)  # 读取post数据,None为默认值
        parameter7 = request.POST.get("parameter7", None)  # 读取post数据,None为默认值
        parameter8 = request.POST.get("parameter8", None)  # 读取post数据,None为默认值
        parameter9 = request.POST.get("parameter9", None)  # 读取post数据,None为默认值
        parameter10 = request.POST.get("parameter10", None)  # 读取post数据,None为默认值

    if request.method == "GET":
        liststr = request.GET.get("liststr", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取get数据,None为默认值
        useridstr = request.GET.get("userid", None)  # 读取get数据,None为默认值
        state = request.GET.get("state", None)  # 读取get数据,None为默认值
        dealtype = request.GET.get("dealtype", None)  # 读取get数据,None为默认值
        parameter1 = request.GET.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.GET.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.GET.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.GET.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.GET.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.GET.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.GET.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.GET.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.GET.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.GET.get("parameter10", None)  # 读取get数据,None为默认值

    userid=0
    if(useridstr):
        userid = int(useridstr)


    print("增加多个日志处理接口参数:liststr:" + liststr)

    dealdiaryList =[]
    dealdiaryList = json.loads(liststr)

    if(not dealdiaryList and len(dealdiaryList)!=0):
        userdeal = Userdeal()
        userdeal.userid=userid
        userdeal.qunid=qunid
        userdeal.state=state
        userdeal.dealtype=dealtype
        userdeal.date=TimeUtil.getCurrentDate()
        userdeal.time=TimeUtil.getCurrentTime()
        userdeal.parameter1=parameter1
        userdeal.parameter2=parameter2
        userdeal.parameter3=parameter3
        userdeal.parameter4=parameter4
        userdeal.parameter5=parameter5
        userdeal.parameter6=parameter6
        userdeal.parameter7=parameter7
        userdeal.parameter8=parameter8
        userdeal.parameter9=parameter9
        userdeal.parameter10=parameter10


        UserDealDAO.addUserDeal(userdeal)
        userdeal = UserDealDAO.selectUserDealfordeal(userdeal)
        if(userdeal):
            for i in range(len(dealdiaryList)):
                dealdiary = dealdiaryList[i]
                dealdiary.dealid=userdeal.id
                dealdiary.date=userdeal.date
                dealdiary.time=userdeal.time
                DiaryDealDAO.addDealDiary(dealdiary)


    result["data"]="0"
    result["respcode"]= ResultCode.SUCCESS
    result["errorcode"]=""
    result["message"]= "添加日志处理成功"

    return result
コード例 #13
0
def addcaidan(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为默认值

    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为默认值

    print("增加菜单(图片)接口参数:用户id:", userid, "内容:", content, "可见群组", qunid)
    print("上传图片的根目录为:" + realPath)
    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 + "uploa/userDiary/" + filenameString
            imagePath.append(fileName)

    # 有图像
    imgnum = len(imagePath)
    if imgnum > 0: diary.imgone = imagePath[0]
    if imgnum > 1: diary.imgtwo = imagePath[1]
    if imgnum > 2: diary.imgthree = imagePath[2]
    if imgnum > 3: diary.imgfour = imagePath[3]
    if imgnum > 4: diary.imgfive = imagePath[4]
    if imgnum > 5: diary.imgsix = imagePath[5]
    if imgnum > 6: diary.imgseven = imagePath[6]
    if imgnum > 7: diary.imgeight = imagePath[7]
    if imgnum > 8: diary.imgnine = imagePath[8]

    diary.diarytype = ResultCode.CONTENT_CAIDAN_IMG
    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.addDiary(diary)

    result["data"] = "0"
    result["respcode"] = ResultCode.SUCCESS
    result["errorcode"] = ""
    result["message"] = "上传文件成功"

    return JsonResponse(result)
コード例 #14
0
ファイル: views.py プロジェクト: loulonglong/django
def userRegist(request):
    user = User()
    result = {}
    if request.method == "POST":
        phone = request.POST.get("phone", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", 0)  # 读取get数据,None为默认值
        password = request.POST.get("password", None)  # 读取post数据,None为默认值
        name = request.POST.get("name", None)  # 读取post数据,None为默认值
        identity = request.POST.get("identity", None)  # 读取post数据,None为默认值
        email = request.POST.get("email", None)  # 读取post数据,None为默认值
        address = request.POST.get("address", None)  # 读取post数据,None为默认值
        school = request.POST.get("school", None)  # 读取post数据,None为默认值
        usertype = request.POST.get("usertype", 0)  # 读取post数据,None为默认值
        usericon = request.POST.get("usericon", None)  # 读取get数据,None为默认值
        wechat = request.POST.get("wechat", None)  # 读取get数据,None为默认值
        alipay = request.POST.get("alipay", None)  # 读取get数据,None为默认值
        parameter1 = request.POST.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.POST.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.POST.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.POST.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.POST.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.POST.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.POST.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.POST.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.POST.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.POST.get("parameter10", None)  # 读取get数据,None为默认值
        parameter11 = request.POST.get("parameter11", None)  # 读取get数据,None为默认值
        parameter12 = request.POST.get("parameter12", None)  # 读取get数据,None为默认值
        parameter13 = request.POST.get("parameter13", None)  # 读取get数据,None为默认值
        parameter14 = request.POST.get("parameter14", None)  # 读取get数据,None为默认值
        parameter15 = request.POST.get("parameter15", None)  # 读取get数据,None为默认值
        parameter16 = request.POST.get("parameter16", None)  # 读取get数据,None为默认值
        parameter17 = request.POST.get("parameter17", None)  # 读取get数据,None为默认值
        parameter18 = request.POST.get("parameter18", None)  # 读取get数据,None为默认值
        parameter19 = request.POST.get("parameter19", None)  # 读取get数据,None为默认值
        parameter20 = request.POST.get("parameter20", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        phone = request.GET.get("phone", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", 0)  # 读取get数据,None为默认值
        password = request.GET.get("password", None)  # 读取get数据,None为默认值
        name = request.GET.get("name", None)  # 读取get数据,None为默认值
        identity = request.GET.get("identity", None)  # 读取get数据,None为默认值
        email = request.GET.get("email", None)  # 读取get数据,None为默认值
        address = request.GET.get("address", None)  # 读取get数据,None为默认值
        school = request.GET.get("school", None)  # 读取get数据,None为默认值
        usertype = request.GET.get("usertype", 0)  # 读取post数据,None为默认值
        usericon = request.GET.get("usericon", None)  # 读取get数据,None为默认值
        wechat = request.GET.get("wechat", None)  # 读取get数据,None为默认值
        alipay = request.GET.get("alipay", None)  # 读取get数据,None为默认值
        parameter1 = request.GET.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.GET.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.GET.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.GET.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.GET.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.GET.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.GET.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.GET.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.GET.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.GET.get("parameter10", None)  # 读取get数据,None为默认值
        parameter11 = request.GET.get("parameter11", None)  # 读取get数据,None为默认值
        parameter12 = request.GET.get("parameter12", None)  # 读取get数据,None为默认值
        parameter13 = request.GET.get("parameter13", None)  # 读取get数据,None为默认值
        parameter14 = request.GET.get("parameter14", None)  # 读取get数据,None为默认值
        parameter15 = request.GET.get("parameter15", None)  # 读取get数据,None为默认值
        parameter16 = request.GET.get("parameter16", None)  # 读取get数据,None为默认值
        parameter17 = request.GET.get("parameter17", None)  # 读取get数据,None为默认值
        parameter18 = request.GET.get("parameter18", None)  # 读取get数据,None为默认值
        parameter19 = request.GET.get("parameter19", None)  # 读取get数据,None为默认值
        parameter20 = request.GET.get("parameter20", None)  # 读取get数据,None为默认值

    print("注册用户接口参数:电话", phone, "密码", password, "名称:", name)
    if (not phone or not password):
        result["data"] = ""
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ResultCode.FAIL
        result["message"] = "注册失败,电话密码不能为空"
        print("注册失败,电话密码不能为空")
        return JsonResponse(result)

    # 先查询手机号是否已经注册过了
    u = UserDAO.queryuserforphone(phone)
    if u:
        result["data"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ResultCode.USEREXIST
        result["message"] = "注册失败,用户已经存在"
        print("注册失败用户存在")
    else:
        # u1 = UserDAO.queryUserForidentity(identity)
        # if u1:
        #     result["data"] = ResultCode.FAIL
        #     result["respcode"] = ResultCode.FAIL
        #     result["errorcode"] = ResultCode.USEREXIST
        #     result["message"] = "注册失败,该用户已经注册过一次"
        # else:
        user.usertype = usertype
        if (usertype == 0):
            user.state = ResultCode.USERQUN_NOT  # 客户从手机端注册,,默认为未审核
        if (usertype == 1):
            user.state = ResultCode.USERQUN_QUNZHU  # 代理商从pc端注册,默认为审核
        user.image = usericon
        user.email = email
        user.phone = phone
        user.password = password
        user.name = name
        user.address = address
        user.school = school
        user.identity = identity
        user.wechat = wechat
        user.alipay = alipay
        user.parameter1 = parameter1
        user.parameter2 = parameter2
        user.parameter3 = parameter3
        user.parameter4 = parameter4
        user.parameter5 = parameter5
        user.parameter6 = parameter6
        user.parameter7 = parameter7
        user.parameter8 = parameter8
        user.parameter9 = parameter9
        user.parameter10 = parameter10
        user.parameter11 = parameter11
        user.parameter12 = parameter12
        user.parameter13 = parameter13
        user.parameter14 = parameter14
        user.parameter15 = parameter15
        user.parameter16 = parameter16
        user.parameter17 = parameter17
        user.parameter18 = parameter18
        user.parameter19 = parameter19
        user.parameter20 = parameter20

        UserDAO.regist(user)  # 注册函数  无返回值
        users = UserDAO.login(user)  # 同时登陆,返回数据,尤其是ID号
        # 如果注册时需要加入群组,这里加入群组
        if (qunid):
            try:
                # 添加用户群关系就是加入了群组
                qun = QunDAO.getqunInfoqunid(qunid)
                userqun = Userqun()
                userqun.userid = users.id
                userqun.qunid = qunid
                userquntemp = UserqunDAO.getuserqunInfouserqun(userqun)
                if (not userquntemp):
                    if (qun.quntype == ResultCode.QUN_USER
                            or qun.quntype == ResultCode.QUN_USER_DIARY or
                            qun.quntype == ResultCode.QUN_USER_DIARY_NOT_USER):
                        userqun.userstate = ResultCode.USERQUN_NOT
                    else:
                        userqun.userstate = ResultCode.USERQUN_YUAN
                    UserqunDAO.adduserqun(userqun)

                    # 添加群聊关系
                    chatuser = Chatuser()
                    chatuser.send_id = qunid
                    chatuser.receive_id = users.id
                    chatuser.usertype = ResultCode.CHATUSER_TYPE_QUN
                    chatuser.state = ResultCode.CHATUSER_HIDE
                    chatuser.abid = str(qunid)
                    chatuser.content = ""
                    chatuser.time = TimeUtil.getCurrentTime()
                    chatuser.date = TimeUtil.getCurrentDate()
                    ChatuserDAO.addchatuser(chatuser)
            except Exception as e:
                print(e)
        usermeback = user2meBack(users)

        result["data"] = usermeback
        result["respcode"] = ResultCode.SUCCESS
        result["errorcode"] = ""
        result["message"] = "注册成功"
        print("注册成功")

    return JsonResponse(result)
コード例 #15
0
ファイル: ChatController.py プロジェクト: loulonglong/django
def addqunchatmessage(request):
    result = {}
    message = Chat_Message()
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取post数据,None为默认值
        messagetype = request.POST.get("messagetype",
                                       None)  # 读取post数据,None为默认值
        contenttype = request.POST.get("contenttype",
                                       None)  # 读取post数据,None为默认值
        send_id = request.POST.get("send_id", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取post数据,None为默认值
        messagetype = request.GET.get("messagetype", None)  # 读取post数据,None为默认值
        contenttype = request.GET.get("contenttype", None)  # 读取post数据,None为默认值
        send_id = request.GET.get("send_id", None)  # 读取post数据,None为默认值

        print("增加群聊(仅文字)接口参数:发送用户id:" + send_id + "内容:" + content + "接收群:" +
              qunid)

        #查询一遍是否存在聊天关系  此关系在进群时就存在
        chatuser = Chatuser()
        chatuser.send_id = qunid
        chatuser.receive_id = send_id
        chatuser.usertype = ResultCode.CHATUSER_TYPE_QUN
        chatuser = ChatuserDAO.querychatqunexist(chatuser)
    if (chatuser == None):
        message.abid = str(qunid)
        #在发送端添加主动发送的群聊关系
        chatuser = Chatuser()
        chatuser.usertype = ResultCode.CHATUSER_TYPE_QUN  #群聊用户
        chatuser.state = ResultCode.CHATUSER_OLD  #设置聊天关系为已读
        chatuser.send_id = qunid
        chatuser.receive_id = send_id  #用户查询聊天对象是根据receiveid查询的,所以讲接收端设置为自己
        chatuser.date = TimeUtil.getCurrentDate()
        chatuser.time = TimeUtil.getCurrentTime()
        chatuser.content = content
        chatuser.abid = str(qunid)
        ChatuserDAO.addchatuser(chatuser)

    #如果存在这个关系群
    else:
        message.abid = chatuser.abid()  #设置message的abid
        #设置发送端群聊关系信息
        chatuser.state = ResultCode.CHATUSER_OLD  #设置聊天关系为没有新信息
        chatuser.date = TimeUtil.getCurrentDate()
        chatuser.time = TimeUtil.getCurrentTime()
        chatuser.content = content
        ChatuserDAO.updatachatuserforid(chatuser)

        #设置所有接收收端群聊关心信息
        chatuser.state = ResultCode.CHATUSER_NEW
        ChatuserDAO.updatachatuserforabid(chatuser)

    #添加聊天信息
    message.messagetype = messagetype
    message.contenttype = contenttype
    message.send_id = send_id
    message.content = content
    message.receive_id = qunid
    message.time = TimeUtil.getCurrentTime()
    message.date = TimeUtil.getCurrentDate()
    ChatuserDAO.addMessage(message)

    #通知接收者
    try:
        result["data"] = "0"
        result["respcode"] = ResultCode.SUCCESS
        result["errorcode"] = ""
        result["message"] = "成功"
        '''
       if(messagetype==ResultCode.MESSAGE_TYPE_SIXIN)
        {
            User user=userService.getUserInfoId(receive_id);
            if(user.getPush_channelId()!=None and !user.getPush_channelId().equals(""))
            push.AndroidPushMsgToSingleDevicemain(user.getPush_channelId(), "您有新的私信", content, ResultCode.PUSH_NEW_SIXIN);
        }
       '''
    except Exception as e:
        print(e)
        result["data"] = "0"
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ResultCode.FAIL
        result["message"] = "失败"

        return result
コード例 #16
0
ファイル: views.py プロジェクト: loulonglong/django
def login(request):
    result = {}
    user = User()
    if request.method == "POST":
        phone = request.POST.get("phone", None)  # 读取get数据,None为默认值
        password = request.POST.get("password", None)  # 读取get数据,None为默认值
        identity = request.POST.get("identity", None)  # 读取get数据,None为默认值
        school = request.POST.get("school", None)  # 读取get数据,None为默认值
        qunid = request.POST.get("qunid", 0)  # 读取get数据,None为默认值

    if request.method == "GET":
        phone = request.GET.get("phone", None)  # 读取get数据,None为默认值
        password = request.GET.get("password", None)  # 读取get数据,None为默认值
        identity = request.GET.get("identity", None)  # 读取get数据,None为默认值
        school = request.GET.get("school", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", 0)  # 读取get数据,None为默认值

    print("用户登录接口参数:电话", phone, "密码", password)
    user.phone = phone
    user.password = password

    user = UserDAO.login(user)
    if (user):
        if (identity): user.identity = identity
        if (school): user.school = school
        UserDAO.updateUserInfo(user)
        # 如果登陆时需要加入群组,这里加入群组
        if (qunid):
            try:
                qun = QunDAO.getqunInfoqunid(qunid)
                userqun = Userqun()
                userqun.userid = user.id
                userqun.qunid = qunid
                userquntemp = UserqunDAO.getuserqunInfouserqun(userqun)
                if (not userquntemp):
                    if (qun.quntype == ResultCode.QUN_USER
                            or qun.quntype == ResultCode.QUN_USER_DIARY or
                            qun.quntype == ResultCode.QUN_USER_DIARY_NOT_USER):
                        userqun.userstate = ResultCode.USERQUN_NOT
                    else:
                        userqun.userstate = ResultCode.USERQUN_YUAN

                    UserqunDAO.adduserqun(userqun)

                    # 添加群聊关系
                    chatuser = Chatuser()
                    chatuser.send_id = qunid
                    chatuser.receive_id = user.id
                    chatuser.usertype = ResultCode.CHATUSER_TYPE_QUN
                    chatuser.state = ResultCode.CHATUSER_HIDE
                    chatuser.abid = str(qunid)
                    chatuser.content = ""
                    chatuser.time = TimeUtil.getCurrentTime()
                    chatuser.date = TimeUtil.getCurrentDate()
                    ChatuserDAO.addchatuser(chatuser)

            except Exception as e:
                print(e)

        user_me_back = user2meBack(user)
        # appBean = AppVersionDAO.queryVersionById(1)   # 这里要求数据库中首先在版本表中存在版本的相关信息
        result["data"] = user_me_back
        result["respcode"] = ResultCode.SUCCESS
        result["errorcode"] = ""
        result["message"] = "登陆成功"
        print('登陆成功')
    else:
        result["data"] = ""
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ResultCode.FAIL
        result["message"] = "账号或密码错误"
        print('账号密码错误')

    return JsonResponse(result)
コード例 #17
0
ファイル: views.py プロジェクト: loulonglong/django
def addtongzhiurl(request):
    message = Notice()
    result = {}
    imagePath = []
    realPath = STATICFILES_DIRS[0] + "/upload/tongzhi/"
    # realPath = request.getSession().getServletContext().getRealPath("tongzhi/")
    if request.method == "POST":
        content = request.POST.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        state = int(request.POST.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.POST.get("messagetype",
                                           None))  # 读取post数据,None为默认值
        contenttype = int(request.POST.get("contenttype",
                                           None))  # 读取post数据,None为默认值
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        content = request.GET.get("content", None)  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        state = int(request.GET.get("state", None))  # 读取post数据,None为默认值
        messagetype = int(request.GET.get("messagetype",
                                          None))  # 读取post数据,None为默认值
        contenttype = int(request.GET.get("contenttype",
                                          None))  # 读取post数据,None为默认值
        send_id = int(request.GET.get("send_id", None))  # 读取post数据,None为默认值
    #urlpath = request.getParameter("urlpath"

    print("增加通知(链接)接口参数:发送用户id:", send_id, "内容:", content, "接收用户id",
          receive_id)
    print("上传图片的根目录为:", realPath)

    files = request.FILES.getlist('files')

    for i in range(len(files)):
        multFile = files[i]
        filename = send_id + "_" + str(time.time()) + "_" + str(i) + ".png"
        if (not multFile):
            print("文件未上传")
        else:
            '''
            print("文件的长度为:" + multFile.getSize())
            print("文件的类型:" + multFile.getContentType())
            print("文件的属性域:" + multFile.getName())
            print("文件的原名:" + multFile.getOriginalFilename())
            '''
            filepath = realPath + "/" + filename

            f_obj = open(filepath, 'wb+')
            for chunk in multFile.chunks():
                f_obj.write(chunk)
            f_obj.close()

            fileName = STATIC_URL1 + "upload/tongzhi/" + filename
            imagePath.append(fileName)

    if (len(imagePath) > 0):
        message.imgone = imagePath[0]  # 将缩略图放在第一个
        message.messagetype = messagetype
        message.contenttype = contenttype
        message.state = state
        message.send_id = send_id
        message.receive_id = receive_id
        message.content = content
        message.time = TimeUtil.getCurrentTime()
        message.date = TimeUtil.getCurrentDate()
        TongzhiDAO.addTongzhi(message)

    else:
        # 无图像
        message.messagetype = messagetype
        message.contenttype = contenttype
        message.state = state
        message.send_id = send_id
        message.receive_id = receive_id
        message.content = content
        message.time = TimeUtil.getCurrentTime()
        message.date = TimeUtil.getCurrentDate()
        TongzhiDAO.addTongzhi(message)

    result["data"] = "0"
    result["respcode"] = ResultCode.SUCCESS
    result["errorcode"] = ""
    result["message"] = "成功"
    return JsonResponse(result)