Ejemplo n.º 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
Ejemplo n.º 2
0
def user2meBack(user):
    user_me_back = {}
    user_me_back['id'] = user.id
    user_me_back['qunid'] = user.qunid
    user_me_back['usertype'] = user.usertype
    user_me_back['identity'] = user.identity
    user_me_back['state'] = user.state
    user_me_back['phone'] = user.phone
    user_me_back['userIcon'] = user.image
    user_me_back['name'] = user.name
    user_me_back['email'] = user.email
    user_me_back['id_number'] = user.id_number
    user_me_back['address'] = user.address
    user_me_back['school'] = user.school
    user_me_back['gold'] = user.gold
    user_me_back['zannum'] = user.zannum
    user_me_back['tuijiannum'] = user.tuijiannum
    user_me_back['commentnum'] = user.commentnum
    user_me_back['shoucangnum'] = user.shoucangnum
    user_me_back['wechat'] = user.wechat
    user_me_back['alipay'] = user.alipay
    user_me_back['parameter1'] = user.parameter1
    user_me_back['parameter2'] = user.parameter2
    user_me_back['parameter3'] = user.parameter3
    user_me_back['parameter4'] = user.parameter4
    user_me_back['parameter5'] = user.parameter5
    user_me_back['parameter6'] = user.parameter6
    user_me_back['parameter7'] = user.parameter7
    user_me_back['parameter8'] = user.parameter8
    user_me_back['parameter9'] = user.parameter9
    user_me_back['parameter10'] = user.parameter10
    user_me_back['parameter11'] = user.parameter11
    user_me_back['parameter12'] = user.parameter12
    user_me_back['parameter13'] = user.parameter13
    user_me_back['parameter14'] = user.parameter14
    user_me_back['parameter15'] = user.parameter15
    user_me_back['parameter16'] = user.parameter16
    user_me_back['parameter17'] = user.parameter17
    user_me_back['parameter18'] = user.parameter18
    user_me_back['parameter19'] = user.parameter19
    user_me_back['parameter20'] = user.parameter20
    try:
        allqun = []

        # =====================获取自己加入的群组,在群组社交中使用====================
        if (ResultCode.app_name == "群组社交"):
            allUserquns = UserqunDAO.getqunInfouserid(user.id)
            if (allUserquns):
                for i in range(len(allUserquns)):
                    quntemp = QunDAO.getqunInfoqunid(allUserquns[i].qunid)
                    if (not quntemp):  # 说明群已经删了

                        UserqunDAO.deluserqunforid(allUserquns[i].id)
                        diary = Diary()
                        diary.userid = user.id
                        diary.qunid = allUserquns[i].qunid
                        diary.state = ResultCode.DIARY_JUST_ME
                        diary.type = fun.daqun().type1
                        DiaryDAO.updatediaryforqunid(diary)

                    else:
                        quntemp.userstate = allUserquns[i].userstate
                        allqun.append(quntemp)

                        # ============================获取自己创建的群组  在爱吃系统中使用==========================
        if (ResultCode.app_name == "爱吃"):
            quntemp = QunDAO.getqunInfoqunid(user.qunid)
            if (quntemp):  # 说明群已经删了
                quntemp.userstate = ResultCode.USERQUN_QUNZHU
                allqun.append(quntemp)

        # print("用户不包含公共平台,共有群组数目"+allqun.size())
        # 创建一个自由群  草稿 全网
        # allqun.append(fun.daqun())

        user_me_back['allQun'] = fun.allqun2back(allqun)

    except Exception as e:
        print(e)
    return user_me_back
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def user2meBack(user):
    user_me_back = User_me_back()
    user_me_back.id=user.id
    user_me_back.qunid=user.qunid
    user_me_back.usertype=user.usertype
    user_me_back.identity=user.identity
    user_me_back.state=user.state
    user_me_back.phone=user.phone
    user_me_back.userIcon=user.image
    user_me_back.name=user.name
    user_me_back.email=user.email
    user_me_back.id_number=user.id_number
    user_me_back.address=user.address
    user_me_back.school=user.school
    user_me_back.gold=user.gold
    user_me_back.zannum=user.zannum
    user_me_back.tuijiannum=user.tuijiannum
    user_me_back.commentnum=user.commentnum
    user_me_back.shoucangnum=user.shoucangnum
    user_me_back.wechat=user.wechat
    user_me_back.alipay=user.alipay
    user_me_back.parameter1=user.parameter1
    user_me_back.parameter2=user.parameter2
    user_me_back.parameter3=user.parameter3
    user_me_back.parameter4=user.parameter4
    user_me_back.parameter5=user.parameter5
    user_me_back.parameter6=user.parameter6
    user_me_back.parameter7=user.parameter7
    user_me_back.parameter8=user.parameter8
    user_me_back.parameter9=user.parameter9
    user_me_back.parameter10=user.parameter10
    user_me_back.parameter11=user.parameter11
    user_me_back.parameter12=user.parameter12
    user_me_back.parameter13=user.parameter13
    user_me_back.parameter14=user.parameter14
    user_me_back.parameter15=user.parameter15
    user_me_back.parameter16=user.parameter16
    user_me_back.parameter17=user.parameter17
    user_me_back.parameter18=user.parameter18
    user_me_back.parameter19=user.parameter19
    user_me_back.parameter20=user.parameter20
    try:
        allqun = []

        #=====================获取自己加入的群组,在群组社交中使用====================
        if(ResultCode.app_name=="群组社交"):
            allUserquns=UserqunDAO.getqunInfouserid(user.id)
            if(allUserquns):
                for i in range(len(allUserquns)):
                    quntemp=QunDAO.getqunInfoqunid(allUserquns[i].qunid)
                    if(not quntemp):   #说明群已经删了

                        UserqunDAO.deluserqunforid(allUserquns[i].id)
                        diary = Diary()
                        diary.userid=user.id
                        diary.qunid=allUserquns[i].qunid
                        diary.state=ResultCode.DIARY_JUST_ME
                        diary.type=fun.daqun().type1
                        DiaryDAO.updatediaryforqunid(diary)

                    else:
                        quntemp.userstate=allUserquns[i].userstate
                        allqun.add(quntemp)


      #============================获取自己创建的群组  在爱吃系统中使用==========================
        if(ResultCode.app_name=="爱吃"):
            quntemp=QunDAO.getqunInfoqunid(user.qunid)
            if(quntemp):   #说明群已经删了
                quntemp.userstate=ResultCode.USERQUN_QUNZHU
                allqun.add(quntemp)



        #print("用户不包含公共平台,共有群组数目"+allqun.size())
        #创建一个自由群  草稿 全网
        #allqun.add(fun.daqun())

        user_me_back.allQun=allqun

    except Exception as e:
        print(e)
    return user_me_back
Ejemplo n.º 6
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)