예제 #1
0
 def create(info):
     util = Util()
     adminID = info['adminID']
     adminName = info['adminName']
     adminPW = util.getMD5String(info['adminPW'])
     tel = info['tel']
     adminInfo = AdminInfo(adminID=adminID,
                           adminName=adminName,
                           adminPW=adminPW,
                           tel=tel)
     db.session.add(adminInfo)
     return (True, None)
예제 #2
0
    def generate(o, ossInfo):
        res = {}
        res['fileID'] = o.fileID
        res['fileName'] = o.fileName
        res['userID'] = o.userID
        res['isDirectory'] = o.isDirectory
        res['tag'] = o.tag
        res['createTime'] = str(o.createTime)

        util = Util()
        if o.isDirectory is False:
            ossInfo['objectKey'] = '%s/%s' % ('files', o.filePath)
            res['filePath'] = util.getSecurityFileUrl(ossInfo)
        return res
예제 #3
0
 def generate(img, ossInfo, directory, hd=None, isFile=False):
     res = {}
     res['imgPathID'] = img.imgPathID
     if hd is not None:
         ossInfo['objectKey'] = '%s/%s' % (directory, img.path)
     else:
         ossInfo['objectKey'] = '%s/%s@!constrain-300h' % (directory,
                                                           img.path)
     util = Util()
     if isFile is True:
         res['imgPath'] = util.getSecurityFileUrl(ossInfo)
     else:
         res['imgPath'] = util.getSecurityUrl(ossInfo)
     res['tag'] = img.tag
     res['imgName'] = img.imgName
     return res
예제 #4
0
 def generate(userInfo):
     util = Util()
     ossImgInfo = {}
     ossImgInfo['bucket'] = 'sjsecondhand'
     res = {}
     res['userID'] = userInfo.userID
     res['userName'] = userInfo.userName
     ossImgInfo['objectKey'] = 'portrait/%s' % userInfo.portraitPath
     res['portraitPath'] = util.getSecurityUrl(ossImgInfo)
     res['info'] = userInfo.info
     res['companyName'] = userInfo.companyName
     res['jobPosition'] = userInfo.jobPosition
     res['tel'] = userInfo.tel
     res['customizedCompanyID'] = userInfo.customizedCompanyID
     res['userType'] = userInfo.userType
     res['userTypeName'] = USER_TAG_DIC[userInfo.userType]
     res['jobNumber'] = userInfo.jobNumber
     res['disable'] = userInfo.disable
     return res
예제 #5
0
 def createCertificationGrade(self, jsonInfo):
     info = json.loads(jsonInfo)
     util = Util()
     for item1 in info:
         c1Dic = {}
         c1Dic['gradeID'] = util.generateID(item1['name'])
         c1Dic['gradeName'] = item1['name']
         (status, result) = CertificationGrade1.create(c1Dic)
         if status:
             db.session.commit()
         for item2 in item1['list']:
             query = db.session.query(CertificationGrade1).filter(
                 CertificationGrade1.gradeName == item1['name'])
             result = query.first()
             c2Dic = {}
             c2Dic['gradeID'] = util.generateID(item2['name'])
             c2Dic['gradeName'] = item2['name']
             c2Dic['superiorID'] = result.gradeID
             (status, result) = CertificationGrade2.create(c2Dic)
             if status:
                 db.session.commit()
             for item3 in item2['list']:
                 query = db.session.query(CertificationGrade2).filter(
                     CertificationGrade2.gradeName == item2['name'])
                 result = query.first()
                 c3Dic = {}
                 c3Dic['gradeID'] = util.generateID(item3['name'])
                 c3Dic['gradeName'] = item3['name']
                 c3Dic['superiorID'] = result.gradeID
                 (status, result) = CertificationGrade3.create(c3Dic)
                 if status:
                     db.session.commit()
                 for item4 in item3['list']:
                     if item3['list']:
                         query = db.session.query(
                             CertificationGrade3).filter(
                                 CertificationGrade3.gradeName ==
                                 item3['name'])
                         result = query.first()
                         c4Dic = {}
                         c4Dic['gradeID'] = util.generateID(item4)
                         c4Dic['gradeName'] = item4
                         c4Dic['superiorID'] = result.gradeID
                         (status,
                          result) = CertificationGrade4.create(c4Dic)
                         if status:
                             db.session.commit()
예제 #6
0
def deleteUser(info):
    wechatManager = WechatManager()
    util = Util()
    openID = info['fromUserName']
    try:
        query = db.session.query(UserInfo).filter(UserInfo.openid1 == openID)
        result = query.first()
        userID = result.userID
        #(1)删除subscribedKey表
        db.session.query(SubscribedKey).filter(
            SubscribedKey.userID == userID).delete(synchronize_session=False)
        #(2)删除searchKey表
        db.session.query(SearchKey).filter(
            SearchKey.foreignID == userID).delete(synchronize_session=False)
        # (3) 删除wechatPush表
        db.session.query(WeChatPush).filter(
            WeChatPush.toUserID == userID).delete(synchronize_session=False)
        # (4) 删除wechatPushHistory表
        db.session.query(WeChatPushHistory).filter(
            WeChatPushHistory.toUserID == userID).delete(
                synchronize_session=False)
        db.session.commit()
    except Exception as e:
        return (False, str(e))
예제 #7
0
def createUser(info):
    wechatManager = WechatManager()
    util = Util()
    openID = info['fromUserName']
    (status, userInfo) = wechatManager.getUserInfo(openID=openID)
    if status is True:
        try:
            unionid = util.generateUnionID(userInfo['nickname'])
            query = db.session.query(UserInfo).filter(
                UserInfo.unionid == unionid)
            result = query.first()
            userID = util.generateID(openID)
            createInfo = {}
            createInfo['userID'] = userID
            createInfo['userName'] = userInfo['nickname']
            createInfo['tel'] = ''
            createInfo['createTime'] = datetime.now()
            createInfo['openid1'] = openID
            createInfo['unionid'] = unionid
            if result is not None:
                #第一种情况,用户已经登录过小程序
                appUserID = result.userID
                openid2 = result.openid2
                #(0)创建新的用户记录
                createInfo['openid2'] = openid2
                UserInfo.createWeChat(createInfo=createInfo)
                #(1)变更Tender中userID
                # 速度太慢,暂时不修改。 若要绑定手机号,一手机号ID为主
                # db.session.query(Tender).filter(
                #     Tender.userID == appUserID
                # ).update({Token.userID: userID}, synchronize_session=False)
                #(2)变更订阅表subscribedKey中userID
                db.session.query(SubscribedKey).filter(
                    SubscribedKey.userID == appUserID).update(
                        {SubscribedKey.userID: userID},
                        synchronize_session=False)
                #(3)变更关注表Favorite中的userID
                db.session.query(Favorite).filter(
                    Favorite.userID == appUserID).update(
                        {Favorite.userID: userID}, synchronize_session=False)
                #(4)变更tokenID表中的userID
                db.session.query(Token).filter(
                    Token.userID == appUserID).update(
                        {Token.userID: userID}, synchronize_session=False)
                # search key update
                db.session.query(SearchKey).filter(
                    and_(SearchKey.tag == SEARCH_KEY_TAG_SUBSCRIBE,
                         SearchKey.foreignID == appUserID)).update(
                             {SearchKey.foreignID: userID},
                             synchronize_session=False)
                #(5)删除userInfo中的appUserID
                db.session.query(UserInfo).filter(
                    UserInfo.userID == appUserID).delete(
                        synchronize_session=False)
            else:
                # 第二种情况,用户没有登录过小程序
                # createInfo = {}
                UserInfo.createPublic(createInfo=createInfo)
            db.session.commit()
        except Exception as e:
            return (False, str(e))
예제 #8
0
def pushTemplateMessage():
    util = Util()
    (status, accessToken) = util.getAccessToken()
    query = db.session.query(WeChatPush, UserInfo, Tender).outerjoin(
        UserInfo, WeChatPush.toUserID == UserInfo.userID).outerjoin(
            Tender, WeChatPush.tenderID == Tender.tenderID)
    allResult = query.all()
    postDic = {}

    def generate(result):
        index = len(postDic)
        userInfo = result.UserInfo
        tender = result.Tender
        userID = userInfo.openid1
        templateData = {}
        templateData['touser'] = userID
        templateData['userid'] = userInfo.userID
        templateData['template_id'] = TEMPLATEID
        templateData['url'] = 'http://weixin.qq.com/download'
        templateData['remark'] = '  ' + tender.title + ';' + '\n'
        templateData['miniprogram'] = {
            "appid": MINIAPPID,
            "pagepath": "pages/myFavorite/myFavorite"
        }
        if not postDic.has_key(userID):
            templateData['remark'] = '[1]  ' + templateData['remark']
            postDic[userID] = templateData
            postDic[userID]['count'] = 1
        else:
            postDic[userID]['count'] = postDic[userID]['count'] + 1
            templateData['remark'] = '[' + str(
                postDic[userID]['count']) + ']  ' + templateData['remark']
            postDic[userID][
                'remark'] = postDic[userID]['remark'] + templateData['remark']

    [generate(result) for result in allResult]

    for key, value in postDic.iteritems():
        #更新推送历史
        toUserID = value['userid']
        publishTime = datetime.now()
        pushQuery = db.session.query(WeChatPush).filter(
            WeChatPush.toUserID == toUserID)
        pushAllResult = pushQuery.all()
        for result in pushAllResult:
            createInfo = {}
            createInfo['pushedID'] = result.pushedID
            createInfo['tenderID'] = result.tenderID
            createInfo['toUserID'] = result.toUserID
            createInfo['createTime'] = result.createTime
            createInfo['publishTime'] = publishTime
            WeChatPushHistory.create(createInfo=createInfo)
        pushQuery.delete(synchronize_session=False)
        db.session.commit()
        value['data'] = {
            "first": {
                "value": "最新提醒!"
            },
            "keyword1": {
                "value": "订阅提醒"
            },
            "keyword2": {
                "value": "更新" + str(value['count']) + '条',
            },
            "remark": {
                "value": value['remark'],
                "color": "#1ebdff"
            }
        }
        postData = json.dumps(value)
        postUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s" % accessToken
        urlResp = urllib.urlopen(url=postUrl, data=postData)
        urlResp = json.loads(urlResp.read())
        return (True, urlResp)