示例#1
0
def replyClickMB4(fromuser):
    '''创建空白问卷'''
    #流程:录入问卷基本信息(标题、描述、公开结果、公开调查、目标样本数、筛选条件,640px图),录入问卷题目,预览并选择发布问卷类型(有奖/红包/互助问卷分别支付后发布,普通问卷直接发布)
    #如果用户当前未编辑完成的问卷个数超过5个,就不允许创建新的问卷,要先删除无用的问卷
    retval = ''
    fsid = mdb.get_fsid_byopenid(fromuser)
    retmsg, count = mdb.get_nocomplete(fsid,
                                       [-1, 0, 1, 2, 3])  #先检查该用户是否有未完成的问卷
    delaySendMessage(fromuser, retmsg)
    cacher_random_checker.popRandomValueForFSID(fsid)
    limit = 5
    if count < limit:
        c0, c1, c2, c3 = mdb.count_aire(fsid)
        retval = {
            "title":
            "创建问卷",
            "url":
            mforweixin.get_mp_authurl("%s/createqs" % (HOST_NOS)),
            "description":
            "您发布过%d个普通问卷,%d个有奖问卷,%d个红包问卷,%d个互助问卷,有%d个正在编辑中。\n\n点击创建新问卷" %
            (c0, c1, c2, c3, count),
            "picUrl":
            ""
        }
    return retval
示例#2
0
def replyClick22(fromuser):
    '''创建普通问卷'''
    # 判断用户今日是否可创建普通问卷,如不可创建,回复文本消息提示今天已创建过。若可创建,回复外链图文消息。用户点击图文消息打开创建普通问卷页面,图文消息的url是带用户ID参数的
    retval = ''
    fsid = mdb.get_fsid_byopenid(fromuser)
    retmsg, count = mdb.get_nocomplete(fsid, [0])  #先检查该用户是否有未完成的有奖问卷,有就提示他
    delaySendMessage(fromuser, retmsg)
    cacher_random_checker.popRandomValueForFSID(fsid)
    limit = int(web.config.app_configuration.get('sys:limit_0', 2))
    if count < limit:
        count = mdb.count_today_aire(fsid)[0]
        if count >= limit:
            return '您今天已经创建了%d个普通问卷,请明天再来。' % limit
        else:
            retval = {
                "title":
                "创建普通问卷",
                "url":
                mforweixin.get_mp_authurl("%s/nopay1" % (HOST_NOS)),
                "description":
                "您今天创建了%d个普通问卷,还可以创建%d个。\n\n点击去创建" % (count, limit - count),
                "picUrl":
                ""
            }
        return retval
示例#3
0
def replyClick31(fromuser):
    '''我的信息'''
    # 回复一个图文消息,显示用户的统计信息:发了多少个问卷、答了多少个问卷、中奖几次,引荐了多少粉丝,个人基本信息。提示点击可修改个人信息。
    # 个人信息页面可查看自己的个人信息,可编辑。
    retval = ''
    FSOBJ = mdb.get_fans_byopenid(fromuser)
    fsid = FSOBJ.FS_ID if FSOBJ else ''
    p0, p1, p2, p3, a0, a1, a2, a3, win, suma2, f1 = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0  #发了多少个问卷(无偿,有偿,红包)、答了多少个问卷(无偿,有偿,红包)、中奖几次(中奖,红包),引荐了多少粉丝
    if fsid:
        cacher_random_checker.popRandomValueForFSID(fsid)
        p0, p1, p2, p3, a0, a1, a2, a3, win, suma2, f1 = mdb.stat_fans_byfsid(
            fsid)
        info = '省份:%s\n城市:%s\n年龄:%s\n婚姻:%s\n学历:%s\n收入:%s' % (
            FSOBJ.PROVINCE.encode('utf8') if FSOBJ.PROVINCE else '',
            FSOBJ.CITY.encode('utf8') if FSOBJ.CITY else '',
            mdb.get_basetitle('AGE', FSOBJ.P2_AGE),
            mdb.get_basetitle('MARRIAGE', FSOBJ.P2_MARRIAGE),
            mdb.get_basetitle('ACADEMIC', FSOBJ.P2_ACADEMIC),
            mdb.get_basetitle('INCOME', FSOBJ.P2_INCOME))
        retval = {
            "title":
            "我的信息",
            "url":
            mforweixin.get_mp_authurl("%s/p31" % (HOST_NOS)),
            "description":
            "发布: 普通%d个,有奖%d个,红包%d个,互助%d个\n参与: 普通%d个,有奖%d个,红包%d个,互助%d个\n中奖次数: %d次。获得红包: %.2f元%s\n引荐粉丝: %d\n\n%s\n\n可点击修改个人信息"
            % (p0, p1, p2, p3, a0, a1, a2, a3, win, suma2,
               (',未发%.2f' % FSOBJ.NOTPAY_A2 if FSOBJ.NOTPAY_A2 else ''), f1,
               info)
        }
        #向自己人发送随机数
        if fsid in web.config.app_configuration['run:selfman']:
            delaySendMessage(fromuser,
                             cacher_random_checker.genRandomValueForFSID(fsid))
    return retval
示例#4
0
def set_winaward(QNOBJ, winno, cjje, enddate):
    '''为问卷设置:中奖号、成交金额、结束日期'''
    retdat = mdb.set_award(QNOBJ.QN_ID, winno, cjje)
    if retdat.has_key('success') and retdat['success']:
        FSWIN = retdat['success']
        if mdb.canSendServiceMessage(FSWIN):
            #向中奖用户发送中奖通知。用户可能无法收到客服消息,因其主动操作已超过48小时
            rtmsg = {
                "title":
                "中奖通知",
                "url":
                mforweixin.get_mp_authurl("%s/p13" % (HOST_NOS), QNOBJ.QN_ID),
                "description":
                '恭喜您!您参与的有奖问卷【%s】已中奖,奖品【%s】,请查阅中奖详情及领奖方法。' %
                (QNOBJ.QN_TITLE.encode('utf8'),
                 QNOBJ.PRIZE_TITLE.encode('utf8')),
                "picurl":
                QNOBJ['SHARE_PICURL']
            }
            delaySendMessage(FSWIN.OPENID, rtmsg)
        #向问卷发布人发送抽奖结果通知。问卷发布人是当天结束问卷的,他的主动操作在48小时内,是可以收到客服消息的
        FSOBJ = mdb.get_fans_byfsid(QNOBJ.FS_ID)
        if mdb.canSendServiceMessage(FSOBJ):
            rtmsg = {
                "title":
                "开奖通知",
                "url":
                mforweixin.get_mp_authurl("%s/p23" % (HOST_NOS)),
                "description":
                '您发布的有奖问卷【%s】已完成抽奖,请查阅开奖详情。' % (QNOBJ.QN_TITLE.encode('utf8')),
                "picurl":
                QNOBJ['SHARE_PICURL']
            }
            delaySendMessage(FSOBJ.OPENID, rtmsg)
        mdb.set_qsend(QNOBJ.QN_ID, enddate)
        return ''
    else:
        print 'ExceptionLottery:', QNOBJ.QN_ID, retdat['error']
        return retdat['error']
示例#5
0
def getTopicArticleBody(TPOBJ):
    '''为话题问卷生成参与链接'''
    if not TPOBJ: return ''
    retval = {
        "title": TPOBJ.SHARE_TITLE,
        "url": '',
        "description": TPOBJ.SHARE_DESC,
        "picurl": ''
    }
    if TPOBJ.get('IMG1_URL'):
        retval['picurl'] = '%s' % (TPOBJ.IMG1_URL)
    elif TPOBJ.get('SHARE_PICURL'):
        retval['picurl'] = '%s' % (TPOBJ.SHARE_PICURL)
    retval['url'] = mforweixin.get_mp_authurl("%s/newfromtp" % (HOST_NOS),
                                              TPOBJ.QN_ID)
    return retval
示例#6
0
def replyClickMC2(fromuser):
    '''我的调查币'''
    retval = ''
    mforweixin.get_fansinfo(fromuser)
    cacher_fsid_byopenid.delete(fromuser)
    FSOBJ = mdb.get_fans_byopenid(fromuser)
    fsid = FSOBJ.FS_ID if FSOBJ else ''
    if fsid:
        cacher_random_checker.popRandomValueForFSID(fsid)
        retval = {
            "title":
            "我的调查币",
            "url":
            mforweixin.get_mp_authurl("%s/pmc2" % (HOST_NOS)),
            "description":
            "当前调查币余额 %d\n用户等级 %s\n\n点击查看详情" %
            (FSOBJ.get('COIN_HOLD', 0), mdb.get_fans_level(FSOBJ))
        }
    return retval
示例#7
0
def replyClick12(fromuser):
    '''已答问卷'''
    # 回复一条图文消息。包含用户已答问卷的统计结果。点击图文消息进入用户自己的已答问卷浏览页面,查看已答过的问卷,参与时间,获得的参与号,等等。进而可看问卷基本信息,结果。
    retval = ''
    fsid = mdb.get_fsid_byopenid(fromuser)
    cacher_random_checker.popRandomValueForFSID(fsid)
    c0, c1, c2, c3 = mdb.count_answer(fsid)
    if c0 == 0 and c1 == 0 and c2 == 0 and c3 == 0:
        return '您还没参与过任何调查问卷。'
    else:
        retval = {
            "title":
            "已答问卷",
            "url":
            mforweixin.get_mp_authurl("%s/p12" % (HOST_NOS)),
            "description":
            "您参与过%d个普通问卷,%d个有奖问卷,%d个红包问卷,%d个互助问卷\n\n点击查看详情" % (c0, c1, c2, c3)
        }
    return retval
示例#8
0
def getQsArticleBody(QNOBJ, index=0, packauth=True):
    '''为问卷对象生成news图文消息格式。有奖问卷或红包问卷。index=0使用大图,否则使用小图'''
    if not QNOBJ: return ''
    retval = {
        "title": QNOBJ.SHARE_TITLE,
        "url": QNOBJ.SHARE_LINK,
        "description": QNOBJ.SHARE_DESC,
        "picurl": QNOBJ.SHARE_PICURL
    }
    if index == 0:
        retval['picurl'] = '%s' % (QNOBJ.IMG1_URL) if QNOBJ.get(
            'IMG1_URL') else retval['picurl']
    #图文消息url用微信网页授权封装
    if packauth:
        retval['url'] = mforweixin.get_mp_authurl("%s/link" % (HOST_NOS),
                                                  QNOBJ.QN_ID)
    else:
        retval['url'] = "%s/link?state=%s" % (HOST_NOS, QNOBJ.QN_ID)
    return retval
示例#9
0
def replyClickMB3(fromuser):
    '''从模板创建问卷'''
    tps = json.loads(web.config.app_configuration.get('sys:qstemplate', '[]'))
    retval = []
    for x in tps:
        TPOBJ = mdb.get_naire(x)
        art = {
            "title": TPOBJ.QN_TITLE,
            "url": '',
            "description": TPOBJ.QN_SUMMARY,
            "picurl": ''
        }
        if TPOBJ.get('IMG1_URL'):
            art['picurl'] = '%s' % (TPOBJ.IMG1_URL)
        elif TPOBJ.get('SHARE_PICURL'):
            art['picurl'] = '%s' % (TPOBJ.SHARE_PICURL)
        art['url'] = mforweixin.get_mp_authurl("%s/newfromtp" % (HOST_NOS),
                                               TPOBJ.QN_ID)
        retval.append(art)
    return retval
示例#10
0
def previewLottery(fromuser):
    '''预览抽奖'''
    import madmin, mforweixin
    retval = ''
    today = datetime.datetime.today().strftime("%Y%m%d")
    retval = '获取%s行情' % today
    cjje = mdb.catch_hq(today)
    if cjje.has_key('success'):
        cjje = cjje['success']
        retval += ':%ld' % cjje
    else:
        retval += ':' + cjje['error']
    prelott = madmin.list_prelotqs()
    retval += '\n可预览抽签问卷个数:%d' % len(prelott)
    retmsg = {
        "title": "预览抽奖",
        "url": mforweixin.get_mp_authurl("%s/admin/prelottery" % (HOST_NOS)),
        "description": retval
    }
    delaySendMessage(fromuser, retmsg, 0)
    return retval
示例#11
0
def replyClick13(fromuser):
    '''馅饼砸中,中奖和红包记录'''
    # 若用户未中过奖,回复一条文本消息。若已中过奖,回复一条图文消息,点击进入查看中奖详细情况:中奖清单,参与的是哪个问卷,其参与号汇总情况,摇号结果,等等。
    retval = ''
    fsid = mdb.get_fsid_byopenid(fromuser)
    cacher_random_checker.popRandomValueForFSID(fsid)
    count, hongbao = mdb.count_award(fsid)
    if count == 0 and hongbao == 0:
        return '您还没有中过奖,而且居然红包也没抢到过!'
    else:
        needsend, detail = mdb.get_hongbao_cache(fsid)
        retval = {
            "title":
            "中奖与红包记录",
            "url":
            mforweixin.get_mp_authurl("%s/p13" % (HOST_NOS)),
            "description":
            "您中过 %d 次奖,获得红包总金额 %.2f 元%s。点击查看详情" %
            (count, hongbao,
             (',等待发放 %.2f 元,累计达到1元时会自动发放' % needsend if needsend > 0 else ''))
        }
    return retval
示例#12
0
def replyClick23(fromuser):
    '''我发布的问卷'''
    # 若用户未发布过任何问卷,回复一条文本消息。
    # 若用户已发布过问卷,回复一条图文消息,包含所发问卷的统计结果。点击进入我发布的问卷查看页面,列表清单查阅所发布的所有问卷,每个问卷可进入问卷查看页面,除了像答卷人可看到的问卷详情外,还可查看状态、统计结果、奖品发放情况等等。
    # 选择自己寄送奖品的,在寄送奖品后,通过这里,可登记快递信息、可申请退保证金,等等。
    retval = ''
    fsid = mdb.get_fsid_byopenid(fromuser)
    cacher_random_checker.popRandomValueForFSID(fsid)
    retmsg, count = mdb.get_nocomplete(fsid, [-1, 0, 1, 2, 3])
    c0, c1, c2, c3 = mdb.count_aire(fsid)
    if c0 == 0 and c1 == 0 and c2 == 0 and c3 == 0 and count == 0:
        return '您还没发布过问卷。'
    else:
        retval = {
            "title":
            "我发布的问卷",
            "url":
            mforweixin.get_mp_authurl("%s/p23" % (HOST_NOS)),
            "description":
            "您发布过%d个普通问卷,%d个有奖问卷,%d个红包问卷,%d个互助问卷。有%d个正在编辑的问卷\n\n点击查看详情" %
            (c0, c1, c2, c3, count)
        }
    return retval
示例#13
0
def replyClick21(fromuser):
    '''创建红包问卷'''
    # 回复外链图文消息。用户点击图文消息打开创建有奖问卷页面,图文消息的url是带用户ID参数的
    retval = ''
    fsid = mdb.get_fsid_byopenid(fromuser)
    retmsg, count = mdb.get_nocomplete(fsid, [2])  #先检查该用户是否有未完成的有奖问卷,有就提示他
    delaySendMessage(fromuser, retmsg)
    cacher_random_checker.popRandomValueForFSID(fsid)
    limit = int(web.config.app_configuration.get('sys:limit_2', 10))
    if count < limit:
        count = mdb.count_today_aire(fsid)[2]
        if count >= limit:
            return '您今天已经创建了%d个红包问卷,请明天再来。' % limit
        else:
            retval = {
                "title":
                "创建红包问卷",
                "url":
                mforweixin.get_mp_authurl("%s/hong1" % (HOST_NOS)),
                "description":
                "您今天创建了%d个红包问卷,还可以创建%d个\n\n点击去创建" % (count, limit - count)
            }
        return retval
示例#14
0
def replyClickMA1(fromuser):
    '''答互助问卷'''
    retval = ''
    FSOBJ = mdb.get_fans_byopenid(fromuser)
    if FSOBJ:
        cacher_random_checker.popRandomValueForFSID(FSOBJ.FS_ID)
    #如果年龄为空,说明是新用户,返回图文消息,提示用户需要填写个人信息后再参与问卷
    if FSOBJ and not FSOBJ.P2_AGE:
        pushTask(mforweixin.get_fansinfo, fromuser)  #获取微信用户信息
        retval = {
            "title": "完善资料",
            "url": mforweixin.get_mp_authurl("%s/p31" % (HOST_NOS)),
            "description": "参与问卷前请先完善资料,所填写资料只用于调查问卷统计,不涉及隐私内容。"
        }
        return retval
    if FSOBJ:
        retval = mdb.list_cananswer(FSOBJ.FS_ID, 3)
        #问卷参与url:用微信网页授权并跳转
        retval = [getQsArticleBody(x, i) for i, x in enumerate(retval)]
        retval = [x for x in retval if x]
        if retval:
            return retval
    return '没有更多互助问卷了!'
示例#15
0
def replyTextMessage(fromuser, content):
    '''解析收到的文本消息。允许管理员用户通过文字指令进行管理操作'''
    retval = ''
    content = content.encode('utf8')  #收到的消息字符串是unicode类型
    fsid = mdb.get_fsid_byopenid(fromuser)
    #测试号上允许访问扒问卷星的页面
    if wxcode == 'test' and fsid in web.config.app_configuration[
            'run:selfman'] and content.find('sojump.com') >= 0:
        wjid = formatting.get_sojump_id(content)
        qnid = 'sojump_' + wjid
        qnid = hashlib.md5(qnid).hexdigest()
        if mdb.get_naire(qnid):
            retval = '编号为 %s 的问卷已经有了!' % wjid
        else:
            # url = '%s/admin/bawj?fsid=%s&r=%s&wjid=%s'%(HOST_NOS,fsid,cacher_random_checker.genRandomValueForFSID(fsid),wjid)
            url = mforweixin.get_mp_authurl("%s/admin/bawj" % (HOST_NOS), wjid)
            retval = {
                "title": "扒问卷",
                "url": url,
                "description": "要扒问卷星的问卷吗?点我继续",
                "picurl": ""
            }
    #管理人员指令
    import madmin
    if not retval and fsid in madmin.get_administrators():
        if content == '?' or content == '?':
            retval = '1.当日实时答卷数\n2.预览抽奖\n3.昨日统计数据\n33.昨日结算\n4.按日统计数据的走势图\n5.营销推广管理\n6.本周答卷王\nC.从系统模板创建问卷\nD.查看调试数据'
        elif content == '1':  #1.当日实时答卷数
            today = datetime.datetime.today().strftime("%Y%m%d")
            countans = web.listget(
                dbFrame.select(
                    "QN_ANSWERS",
                    what="COUNT(*) CNT",
                    vars=locals(),
                    where="DATE_FORMAT(INPUT_TIME,'%Y%m%d')=$today").list(), 0,
                {}).get('CNT', 0)
            return '今日实时答卷数:%d' % countans
        elif content == '2':  #2.预览抽奖
            pushTask(previewLottery, fromuser, 0)
        elif content == '33':  #33.昨日结算\n
            pushTask(dailyWork,
                     (fromuser, formatting.date_add(-1).strftime("%Y%m%d")), 0)
        elif content == '3':  #3.昨日统计数据
            import madmin
            retval = '\n'.join([
                '%s: %s' % (key, val)
                for key, val in madmin.get_lastday_stat()
            ])
        elif content == '4':  #4.数据趋势图
            retval = {
                "title":
                "按日统计数据的走势图",
                "url":
                mforweixin.get_mp_authurl("%s/admin/chartdaily" % (HOST_NOS)),
                "description":
                "按日统计数据的走势图",
                "picurl":
                ""
            }
        elif content == '5':  #5.营销推广管理
            retval = {
                "title": "营销推广管理",
                "url":
                mforweixin.get_mp_authurl("%s/admin/mngmarket" % (HOST_NOS)),
                "description": "查看营销推广数据,支付推广报酬",
                "picurl": ""
            }
        elif content == '6':  #6.本周答卷王
            retval = []
            for idx, x in enumerate(mdb.stat_thisweek_coin(), 1):
                retval.append('%d. %s  %s' %
                              (idx, formatting.unAscSafeString(
                                  x.NICKNAME).encode('utf8'), x.CHG_AMOUNT))
            if not retval:
                retval = '无数据'
            else:
                retval = '\n'.join(retval)
        elif content.lower() == 'c':
            pass
        elif content.lower() == 'd':  #D.查看调试数据
            retval = {
                "title": "查看调试数据",
                "url": mforweixin.get_mp_authurl("%s/debug" % (HOST_NOS)),
                "description": "查看调试数据。已重新加载了系统配置数据。",
                "picurl": ""
            }
        elif content.startswith('black'):
            fsid = content.replace('black', '')
            if 'run:blacklist' not in web.config.app_configuration:
                web.config.app_configuration['run:blacklist'] = []
            if fsid:
                for x in fsid.split(','):
                    web.config.app_configuration['run:blacklist'].append(x)
            web.config.app_configuration['run:blacklist'] = list(
                set(web.config.app_configuration['run:blacklist']))
            retval = formatting.json_string(
                web.config.app_configuration['run:blacklist'])
        elif content.startswith('white'):
            fsid = content.replace('white', '')
            if 'run:blacklist' not in web.config.app_configuration:
                web.config.app_configuration['run:blacklist'] = []
            if fsid:
                for x in fsid.split(','):
                    if x in web.config.app_configuration['run:blacklist']:
                        web.config.app_configuration['run:blacklist'].remove(x)
            web.config.app_configuration['run:blacklist'] = list(
                set(web.config.app_configuration['run:blacklist']))
            retval = formatting.json_string(
                web.config.app_configuration['run:blacklist'])
    else:
        retval = decodeReceiveMessage(fromuser, fsid, content)
        if retval:
            return retval
        #不能解析粉丝发来的消息,先把【发达消息】发给粉丝
        pushTask(mforweixin.sendTextMessage,
                 (fromuser,
                  '没有搜索到有关[%s]的问卷。客服也可能在偷懒╯﹏╰,看看下面几篇文章吧,或许对您有用' % content))
        if wxcode == 'test':
            pushTask(mforweixin.sendTextMessage,
                     (fromuser, 'cSpmz_6G_PBkj7hqA8EYpdAXzqi-wD19aL29_wPSPwQ'),
                     2000)
        else:
            pushTask(mforweixin.sendMPNews,
                     (fromuser, 'cSpmz_6G_PBkj7hqA8EYpdAXzqi-wD19aL29_wPSPwQ'),
                     2000)
        #将粉丝发发来的消息转给我自己
        pushTask(madmin.sendToMe, ('{0}:{1}'.format(fsid, content), ))
        #按要求返回特定格式数据,消息便会发到客服
        retval = mforweixin.replyCustomerService(wxaccount.ORIGINAL_ID,
                                                 fromuser)
    return retval