Exemplo n.º 1
0
def add_app_feedback(openid,imei,content,usercontact,clientid,channelno,version,brandFlag,modelFlag,deviceFlag):
    """
        添加用户反馈信息

        openid         反馈的用户
        imei           设备imei
        content        反馈内容
        usercontact    联系方式
        clientid       ClientId
        channelno      渠道号
        version        版本号
        brandFlag      品牌
        modelFlag      机型
        deviceFlag     子机型
    """

    nowTime = datetime.datetime.now() 
    inform_time = nowTime.strftime('%Y-%m-%d %H:%M:%S')  
     
    try:
        with db.MysqlConnection(config.GLOBAL_SETTINGS['db']) as con:    
            # 设置保存的信息的字编码 
            con.execute("SET NAMES utf8mb4;") 
            sql = "insert into FeedBack (OpenId,Imei,Content,UserContact,ClientId,ChannelNo,Version,BrandFlag,ModelFlag,DeviceFlag,CreateTime,UpdateTime,Status) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
            sql_result = con.execute_rowcount(sql,openid,imei,content,usercontact,clientid,channelno,version,brandFlag,modelFlag,deviceFlag,inform_time,inform_time,1)  
            if sql_result==1:
                con.commit()  
            return sql_result
            
    except Exception,ex:   
        mylogger = logger.GlobalLogger() 
        mylogger.write(u'appinform add_app_inform  error: %s' % (ex))
        return 0
Exemplo n.º 2
0
 def initialize(self):
     self.logger = logger.GlobalLogger()
     stat_config = config.GLOBAL_SETTINGS.get('stat')
     svcid = stat_config.get('svcid') if stat_config else '0'
     self.stat = stats.CommonStat(config.GLOBAL_SETTINGS['logger'], 'V1.1',
                                  svcid)
     self._dynamic_value = {}
     self._template_loader = tornado.template.Loader(
         os.path.join(config.GLOBAL_SETTINGS['root_path'], "templates"))
Exemplo n.º 3
0
def add_app_comment(comment_obj):
    """
        添加用户评分和评论
        comment_obj   包含评分和评论的字典对象

            commentid    # 评论id,更新评论时不为0
            openid       # 用户openId
            username     # 用户名
            appid        # 应用id
            userscore    # 评分
            vercode      # 本地版本代码
            vername      # 本地版本号
            comments     # 评论内容,空串代表无评论
            brand        # 品牌
            model        # 机型
            device       # 子机型
            ip           # 网络ip
    """

    nowTime = datetime.datetime.now()
    inform_time = nowTime.strftime('%Y-%m-%d %H:%M:%S')

    commentId = comment_obj['commentid']
    openId = comment_obj['openid']
    userName = comment_obj['username']
    appId = comment_obj['appid']
    score = comment_obj['userscore']
    verCode = comment_obj['vercode']
    verName = comment_obj['vername']
    comments = comment_obj['comments']
    brand = comment_obj['brand']
    model = comment_obj['model']
    device = comment_obj['device']
    ip = comment_obj['ip']

    try:
        pass

        # # 1.判断是评分还是评论,userscore=0表示评论,userscore!=0表示评分操作
        # if score==0:
        #     # 用户评论
        #     pass
        # else:
        #     # 用户评分
        #     pass

        # with db.MysqlConnection(config.GLOBAL_SETTINGS['db']) as con:
        #     sql = "insert into FeedBack (OpenId,Content,UserContact,ClientId,ChannelNo,Version,CreateTime,UpdateTime,Status) values (%s,%s,%s,%s,%s,%s,%s,%s,%s);"
        #     sql_result = con.execute_rowcount(sql,openid,content,usercontact,clientid,channelno,version,inform_time,inform_time,1)
        #     if sql_result==1:
        #         con.commit()
        #     return sql_result

    except Exception, ex:
        mylogger = logger.GlobalLogger()
        mylogger.write(u'appinform add_app_inform  error: %s' % (ex))
        return 0
Exemplo n.º 4
0
def init():
    """可以放初始化相关操作
    """
    import base_utils.logger as logger
    logger.GlobalLogger(config.GLOBAL_SETTINGS['logger'])
Exemplo n.º 5
0
def add_app_score(comment_obj):
    """
        添加应用评分 
        comment_obj   包含评分和评论的字典对象

            commentid    # 评论id,更新评论时不为0
            openid       # 用户openId
            username     # 用户名
            appid        # 应用id
            userscore    # 评分
            vercode      # 本地版本代码
            vername      # 本地版本号
            comments     # 评论内容,空串代表无评论
            brand        # 品牌
            model        # 机型
            device       # 子机型
            ip           # 网络ip
    """

    nowTime = datetime.datetime.now()
    inform_time = nowTime.strftime('%Y-%m-%d %H:%M:%S')

    try:
        # 1.判断是评分还是评论,userscore=0表示评论,userscore!=0表示评分操作
        commentId = comment_obj['commentid']
        openId = comment_obj['openid']
        userName = comment_obj['username']
        appId = comment_obj['appid']
        userScore = comment_obj['userscore']
        verCode = comment_obj['vercode']
        verName = comment_obj['vername']
        # comments = comment_obj['comments']
        brand = comment_obj['brand']
        model = comment_obj['model']
        device = comment_obj['device']
        ip = comment_obj['ip']

        # 缓存中查询该用户是否已经对该应用进行过评分操作
        cache_obj = get_redis_cache()
        key = APISrcCommentCacheName.APP_PASSED_CACHE % appId
        filed = _CACHE_APPID_OPENID_KEY % (appId, openId)

        # 判断是否已经评论过
        if cache_obj.hexists(key, filed):
            value = cache_obj.hget(key, filed)
            comment = json.loads(value)
            return comment['commentid']

        with db.MysqlConnection(config.GLOBAL_SETTINGS['db']) as con:
            sql_result = 0
            # 先查询有没有进行过评分
            sql = "select CommentID,OpenId,UserName,AppID,UserScore,LocalVerCode,LocalVerName,Comments,CommentTime,AuditStatus,Status from AppComments where AppID=%s and OpenId=%s and AuditStatus=1 and Status=1;"
            query_obj = con.query(sql, appId, openId)
            if query_obj:
                sql_result = query_obj[0]['CommentID']
                # 将其添加到缓存中
                #
                # {commentid:评论id,openid:用户openid,username:用户名,appid:应用id,userscore:用户评分,vercode:本地版本代码,vername:本地版本号,comments:评论内容,commenttime:评论时间}
                #
                comment = {}
                comment['commentid'] = query_obj[0]['CommentID']
                comment['openid'] = query_obj[0]['OpenId']
                comment['username'] = query_obj[0]['UserName']
                comment['appid'] = query_obj[0]['AppID']
                comment['userscore'] = query_obj[0]['UserScore']
                comment['vercode'] = query_obj[0]['LocalVerCode']
                comment['vername'] = query_obj[0]['LocalVerName']
                comment['comments'] = query_obj[0]['Comments']
                comment['commenttime'] = query_obj[0]['CommentTime'].strftime(
                    '%Y-%m-%d %H:%M:%S')
                value = json.dumps(comment)
                # 添加到缓存中
                add_comments_passed_cache(cache_obj, key, filed, value)

            else:
                # 添加评分信息
                sql = "insert into AppComments (OpenId,UserName,AppID,UserScore,LocalVerCode,LocalVerName,Comments,BrandFlag,ModelFlag,DeviceFlag,IP,CommentTime,AuditStatus,Status,UpdateTime) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
                sql_result = con.execute_lastrowid(sql, openId, userName,
                                                   appId, userScore, verCode,
                                                   verName, '', brand, model,
                                                   device, ip, inform_time, 1,
                                                   1, inform_time)
                if sql_result != 0:
                    # 修改总的评分
                    sum_result = update_app_sum_score(appId, userScore)
                    if sum_result:
                        con.commit()
                    else:
                        sql_result = 0

            return sql_result

    except Exception, ex:
        mylogger = logger.GlobalLogger()
        mylogger.write(u'appinform add_app_score  error: %s' % (ex))
        return 0