Beispiel #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
Beispiel #2
0
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
Beispiel #3
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
Beispiel #4
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)