示例#1
0
def get_sql_info(search, page_limit, field_id, request):
    L = []
    sql = "select IFNULL(field_options_txt,''),ifnull(para_cols,'') from menu_form_cols where id=%s" % (
        field_id)
    lT, iN = db.select(sql)
    if iN == 0:
        return L
    sql = lT[0][0]
    if sql == '':
        return L
    para_cols = lT[0][1]
    sql = sql.replace("{_self}", search)
    paras = para_cols.split(',')
    #print paras
    #print request.POST
    for e in paras:
        if e == '': break
        sql = sql.replace("{%s}" % e,
                          MySQLdb.escape_string(request.POST.get(e, '')))
    sql += " limit %s" % (page_limit)

    #print ToGBK(sql)
    lT, iN = db.select(sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, '', txt])
    return L
示例#2
0
def LinkToShajd(request):
    AccessToken = request.GET.get('AccessToken', '')
    wxcpt = WXBizMsgCrypt('szoworld', m_aesKey)
    ret, login_id, sTimeStamp = wxcpt.DecryptMsg(AccessToken)
    if (ret != 0):
        s = """
            {
            "errcode": -1,
            "errmsg": "验证信息有误,请重新登陆!",
            }        """
        return HttpResponseCORS(request, s)

    import base64, time
    import random
    random_no = '%s' % (random.randint(0, 999999))
    proj_id = request.GET.get('id', '')
    L = ['', '', '']
    team_uuid = 'e015c3bd59ba11e88a8d7cd30abeb520'

    sql = "select usr_id,login_id,usr_name,password,ifnull(mobil,'') from users where login_id='%s'" % (
        login_id)
    rows, iN = db.select(sql)
    names = 'usr_id login_id usr_name password phone'.split()
    data = dict(zip(names, rows[0]))

    sql = "select id,cname,gc_no from out_proj where id='%s'" % (proj_id)
    rows, iN = db.select(sql)
    names = 'proj_id proj_name proj_code'.split()
    data1 = dict(zip(names, rows[0]))

    L[0] = team_uuid
    L[1] = data
    L[2] = data1
    names = 'team_uuid user proj'.split()
    L = dict(zip(names, L))
    info = json.dumps(L, ensure_ascii=True)

    #print info
    sTimeStamp = str(time.time())
    wxcpt = WXBizMsgCrypt('szoworld', m_aesKey)

    ret, token = wxcpt.EncryptMsg(info, random_no, sTimeStamp)

    #wxcpt1=WXBizMsgCrypt('szoworld',m_aesKey)
    #ret,info1,sTimeStamp1 = wxcpt1.DecryptMsg(token)

    url = "https://www.shajd.cn/login_schedule.html?team_id=%s&token=%s" % (
        team_uuid, urllib.quote(token))
    return HttpResponseRedirect(url)
示例#3
0
def saveSelectedOptions(field_type, options_type, usr_id, sel_value):
    type = int(options_type)
    iN = 0
    if type == 21:
        L, iN = get_proj_info_selected(sel_value)
    elif type == 23:  #供应商
        L, iN = get_sup_info_selected(sel_value)
    #elif type==24:   #人员
    #    L,iN = get_addr_book_selected(sel_value)
    elif type == 26:
        L, iN = get_mat_info_selected(sel_value)
    if iN > 0:
        sql = "select id from user_options where usr_id=%s and option_type=%s and option_id=%s" % (
            usr_id, options_type, sel_value)
        lT, iN1 = db.select(sql)
        if iN1 > 0:
            sql = "update user_options set ctime=now(), hits = hits +1 where id=%s" % (
                lT[0][0])
        else:
            sql = """insert into `user_options` (`usr_id`,`option_type`,`option_id`,`option_value`,`option_level`,`option_parent_id`,`option_tips`,`ctime`,`hits`)
                     values (%s,%s,'%s','%s','%s','%s','%s',now(),1)
                  """ % (usr_id, options_type, L[0][0], L[0][1], L[0][2],
                         L[0][3], L[0][4])
        print ToGBK(sql)
        db.executesql(sql)
    return
示例#4
0
def get_options1(db_id):
    sql = "select db_host,port,db_name,user_name,passwd from db_info where id=%s" % (
        db_id)
    rows, iN = db.select(sql)
    db1 = MySQLdb.connect(host=rows[0][0],
                          port=rows[0][1],
                          user=rows[0][3],
                          passwd=rows[0][4],
                          db=rows[0][2],
                          charset="utf8")
    L = [['', '--请选择--', '1']]

    sql = '''select md.menu_id,mf.menu_name from menu_data_source md
                left join menu_func mf on md.menu_id=mf.menu_id
                where mf.status=1 and mf.menu_id!=0
                order by mf.sort
          '''
    lT, iN = sql_select(db1, sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, ''])
    db1.close()

    options = ['', False]
    names = 'value label checked'.split()
    if L == '' or L == None:
        return []
    data = [dict(zip(names, d)) for d in L]
    options[0] = data
    options[1] = False
    names = 'options include_other_option'.split()
    L1 = dict(zip(names, options))
    return L1
示例#5
0
def get_recently_data(type, page_limit, usr_id):
    L = []

    if type == 21:  #项目
        sql = """select option_id,concat('(',ifnull(op.gc_no,''),')',ifnull(op.cname,'')),concat('(',ifnull(op.gc_no,''),')',ifnull(op.cname,'')) from user_options o
               left join out_proj op on op.id = o.option_id
               where o.usr_id='%s' and o.option_type='%s' and ifnull(op.status,-1) != -1 order by o.ctime desc limit %s
            """ % (usr_id, type, page_limit)
    elif type == 19:  #费用
        sql = """select option_id,option_value,option_tips from user_options where usr_id='%s' and option_type='%s' order by o.ctime desc limit %s
            """ % (usr_id, type, page_limit)
    elif type == 23:  #供应商
        sql = """select option_id,ifnull(s.cname,''),s.cname from user_options o
               left join suppliers s on s.id = o.option_id
               where o.usr_id='%s' and o.option_type='%s' and ifnull(s.status,-1) != -1 order by o.ctime desc limit %s
            """ % (usr_id, type, page_limit)
    elif type == 24:  #员工
        sql = """select option_id,option_value,option_tips from user_options where usr_id='%s' and option_type='%s' order by o.ctime desc limit %s
            """ % (usr_id, type, page_limit)
    elif type == 25:  #项目经理
        sql = """select option_id,option_value,option_tips from user_options where usr_id='%s' and option_type='%s' order by o.ctime desc limit %s
            """ % (usr_id, type, page_limit)
    elif type == 26:  #材料
        sql = """select option_id,concat(number,'/',name),concat('规格:',ifnull(size,''),')') from user_options o
               left join _m504_clgl m on m.id = o.option_id
               where o.usr_id='%s' and o.option_type='%s' and m.id is not null and ifnull(m.status,-1) != -1 and (state = 1 or (state in (2,3)) and cid=%s)  order by o.ctime desc limit %s
            """ % (usr_id, type, usr_id, page_limit)
    else:
        return L
    #print sql
    lT, iN = db.select(sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, '', e[2]])
    return L
示例#6
0
def del_attach_file(request):
    fname = request.GET.get('fname', '')
    sql = "SELECT fname,YEAR(ctime),MONTH(ctime) FROM file_pic WHERE fname='%s'" % fname
    lT, iN = db.select(sql)
    if iN > 0:
        L = list(lT[0])
        ext = L[0].split('.')[-1]
        year = L[1]
        month = L[2]
        path = os.path.join(upload_path, '%s/%s' % (year, month))
        if fname != '':
            path1 = os.path.join(path, fname)
            try:
                os.remove(path1)
            except:
                pass
            path1 = os.path.join(path, "small_%s" % fname)
            try:
                os.remove(path1)
            except:
                pass
    sql = "delete from file_pic WHERE fname='%s'" % fname
    db.executesql(sql)
    s = """
        {
        "error": false
        }
        """
    return HttpResponseJsonCORS(request, s)
示例#7
0
def forgetpwd_origin(request):
    name =  request.POST.get('usrname','') or request.GET.get('usrname','')
    login_id =  request.POST.get('login_id','') or request.GET.get('login_id','')
    errCode = 0
    # s = ''
    msg = ''
    tel = ''

    # 判断账户填写是否错误
    sql = " select mobil from users where login_id='%s' and usr_name='%s' "%(login_id,name)
    rows,iN = db.select(sql)
    if iN:
        # 获取验证码
        tel = rows[0][-1]
        msg = 'sucess'
        errCode = 0
    else:
        # 登录名或用户名错误
        msg = '请填写正确的用户名和姓名!'
        errCode = -1
    s ="""
            {
            "errcode":"%s",
            "errmsg": "%s",
            "tel": "%s",
            }
        """%(errCode,msg,tel)
    return HttpResponseCORS(request,s)
示例#8
0
def menu_func(request):
    import base64, time
    import random
    random_no = '%s' % (random.randint(0, 999999))
    sql = """SELECT distinct WMF.menu,WMF.menu_id,WMF.menu_name,
                   WMF.sort,WMF.parent_id,WMF.status-1,WMF.url,WMF.icon
                   FROM menu_func WMF 
                   Left JOIN menu_func WMF1 on WMF.parent_id = WMF1.menu_id
                   WHERE WMF.status=2 and WMF.menu_id>0 and WMF1.status=2
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """
    #print sql
    rows, iN = db.select(sql)
    names = 'level menu_id menu_name sort parent_id status url icon'.split()
    data = [dict(zip(names, d)) for d in rows]
    s3 = json.dumps(data, ensure_ascii=False)

    s = """
        {
            "errcode": 0,
            "errmsg": "获取数据成功",
            "menu_data": %s
        }
        """ % (s3)
    return HttpResponseCORS(request, s)
示例#9
0
def del_attach_file(request):
    usr_id_gy = request.session.get('usr_id_gy', '') or testid
    if usr_id_gy == 0:
        s = """
        {
        "errcode": -1,
        "errmsg": "无权访问,请先关注"
        }        """
        return HttpResponseJsonCORS(s)
    fname = request.GET.get('fname', '')
    sql = "SELECT fname,YEAR(ctime),MONTH(ctime) FROM file_pic_gy WHERE fname='%s' and cid = %s" % (
        fname, usr_id_gy)
    lT, iN = db.select(sql)
    if iN > 0:
        L = list(lT[0])
        ext = L[0].split('.')[-1]
        year = L[1]
        month = L[2]
    path = os.path.join(upload_path, '%s/%s' % (year, month))
    if fname != '':
        path = os.path.join(path, fname)
        try:
            os.remove(path)
        except:
            pass
    sql = "delete from file_pic_gy WHERE fname='%s' and cid=%s" % (fname,
                                                                   usr_id)
    db.executesql(sql)
    s = """
        {
        "error": false
        }
        """
    return HttpResponseJsonCORS(s)
示例#10
0
def get_mat_info_selected(sDF):
    L = []

    sql = """select id,concat(number,'/',name,'/',size,'/',type,'/',unit,'/',brand),0,'',concat('(规格:',ifnull(size,''),')') from _m504_clgl where id='%s' order by id desc
            """ % sDF
    lT, iN = db.select(sql)

    return lT, iN
示例#11
0
def menu_func(request):
    import base64, time
    import random
    random_no = '%s' % (random.randint(0, 999999))

    lang_id = request.POST.get('lang_id') or request.GET.get('lang_id', '')
    usr_id = request.POST.get('usr_id', '') or request.GET.get('usr_id', '')
    if lang_id == '': lang_id = 1
    else: lang_id = int(lang_id)

    if m_muti_lang == 1 and lang_id > 1:
        if str(usr_id) in ['1', '2']:
            sql = """SELECT distinct WMF.menu,WMF.menu_id,case l.`name` when '' then WMF.menu_name else l.`name` end,
                   WMF.sort,WMF.parent_id,WMF.status,WMF.url,WMF.icon
                   FROM menu_func WMF 
                   Left JOIN menu_func WMF1 on WMF.parent_id = WMF1.menu_id
                   left join muti_lang_menu l on l.menu_id = WMF.menu_id and l.lang_id = %s
                   WHERE WMF.status=1 and WMF.menu_id>0 and WMF1.status=1
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """ % (lang_id)
        else:
            sql = """SELECT distinct WMF.menu,WMF.menu_id,case l.`name` when '' then WMF.menu_name else l.`name` end,
                   WMF.sort,WMF.parent_id,WMF.status,WMF.url,WMF.icon
                   FROM usr_role WUR JOIN (role_menu WRM JOIN menu_func WMF ON WRM.menu_id=WMF.menu_id) ON WUR.role_id=WRM.role_id
                   left join muti_lang_menu l on l.menu_id = WMF.menu_id and l.lang_id = %s
                   WHERE WUR.usr_id='%s' AND WMF.status=1 and WMF.menu_id>0 and WRM.can_view=1
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """ % (lang_id, usr_id)
    else:
        if str(usr_id) in ['1', '2']:
            sql = """SELECT distinct WMF.menu,WMF.menu_id,WMF.menu_name,
                   WMF.sort,WMF.parent_id,WMF.status,WMF.url,WMF.icon
                   FROM menu_func WMF 
                   Left JOIN menu_func WMF1 on WMF.parent_id = WMF1.menu_id
                   WHERE WMF.status=1 and WMF.menu_id>0 and WMF1.status=1
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """
        else:
            sql = """SELECT distinct WMF.menu,WMF.menu_id,WMF.menu_name,
                   WMF.sort,WMF.parent_id,WMF.status,WMF.url,WMF.icon
                   FROM usr_role WUR JOIN (role_menu WRM JOIN menu_func WMF ON WRM.menu_id=WMF.menu_id) ON WUR.role_id=WRM.role_id
                   WHERE WUR.usr_id='%s' AND WMF.status=1 and WMF.menu_id>0 and WRM.can_view=1
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """ % usr_id
    #print sql
    rows, iN = db.select(sql)
    names = 'level menu_id menu_name sort parent_id status url icon'.split()
    data = [dict(zip(names, d)) for d in rows]
    s3 = json.dumps(data, ensure_ascii=False)

    s = """
        {
            "errcode": 0,
            "errmsg": "获取数据成功",
            "menu_data": %s,
        }
        """ % (s3)
    return HttpResponseCORS(request, s)
示例#12
0
def file_list(request):
    menu_id = request.POST.get('menu_id', 0)
    if menu_id == '3000001': menu_id = 1501
    pk = request.POST.get('pk', '')
    random_no = request.POST.get('random_no', '')
    if pk != '':
        sql = "SELECT '',file_size,ifnull(title,''),'','','',fname,YEAR(ctime),MONTH(ctime),is_pic FROM file_pic WHERE menu_id=%s and gw_id=%s and source=0" % (
            menu_id, pk)
    else:
        sql = "SELECT '',file_size,ifnull(title,''),'','','',fname,YEAR(ctime),MONTH(ctime),is_pic FROM file_pic WHERE menu_id=%s and random_no='%s' and source=0" % (
            menu_id, random_no)
    print sql
    lT, iN = db.select(sql)
    if len(lT) == 0:
        s = """{"files":[]}
            """
        return HttpResponseJsonCORS(request, s)
    L = []
    for e in lT:
        L1 = list(e)
        fname = e[6]
        small_name = "small_%s" % (fname)
        year = e[7]
        month = e[8]
        L1[0] = False
        is_pic = e[9]
        L1[3] = ""
        if is_pic == 1:
            path = os.path.join(upload_path, str(year), str(month))
            if not os.path.exists(os.path.join(path, small_name)):
                print fname
                img = Image.open(os.path.join(path, fname))
                x, y = img.size
                x1 = 80
                y1 = 80 * y / x
                try:
                    img = img.resize((x1, y1), Image.ANTIALIAS)
                    img.save(os.path.join(path, small_name))
                    L1[3] = os.path.join(front_url, 'attach', str(year),
                                         str(month), small_name)
                except:
                    pass
            else:
                L1[3] = os.path.join(front_url, 'attach', str(year),
                                     str(month), small_name)
        #L1[4] = "%s/get_file/?fname=%s"%(data_url,fname)
        L1[4] = os.path.join(front_url, 'attach', str(year), str(month), fname)
        L1[5] = "%s/del_file/?fname=%s" % (data_url, fname)
        L.append(L1)
    names = 'error size name thumbnail_url url delete_url'.split()
    data = [dict(zip(names, d)) for d in L]
    fileList = json.dumps(data, ensure_ascii=False)

    s = """{"files":%s}
        """ % (fileList)
    #print ToGBK(s)
    return HttpResponseJsonCORS(request, s)
示例#13
0
def modify_pwd(request):
    import base64, time
    import random
    random_no = '%s' % (random.randint(0, 999999))
    #print request.POST
    login_id = request.POST.get('login_id', '')
    oldPwd = request.POST.get('oldPwd', '')
    newPwd = request.POST.get('newPwd', '')

    if login_id == '':
        errCode = 1
        msg = u'用户名不存在'
        s = """
            {
            "errcode": %s,
            "errmsg": "%s",
            "login_id": "%s",
            }
            """ % (errCode, msg, login_id)
        response = HttpResponseCORS(request, s)
        return response
    login_id = login_id.replace("'", "")
    if oldPwd != '':
        oldPwd = oldPwd.lower()

    s1 = ''
    sql = """SELECT U.usr_id,U.usr_name,ifnull(U.dept_id,0),ifnull(D.cname,''),IFNULL(U.pic,''),U.password
                   FROM users U LEFT JOIN dept D ON U.dept_id=D.id
                   WHERE U.login_id='%s' AND U.status=1 
                """ % (login_id)
    lT, iN = db.select(sql)
    if iN > 0:
        usr_id = lT[0][0]
        pwd1 = lT[0][5]
        m1 = md5.new()
        m1.update(lT[0][5])
        pwd = m1.hexdigest()
        if oldPwd != pwd:
            errCode = 2
            msg = u'密码错误'
        else:
            sql = "update users set password = '******' where usr_id =%s" % (
                newPwd, usr_id)
            db.executesql(sql)
            errCode = 0
            msg = u'修改成功'
    else:
        errCode = 1
        msg = u'用户名不存在'
    s = """
        {
            "errcode": %s,
            "errmsg": "%s",
            "login_id": "%s",
        }
        """ % (errCode, msg, login_id)
    return HttpResponseCORS(request, s)
示例#14
0
def get_sup_info_selected(sDF):
    L = []

    sql = """select id,ifnull(cname,''),0,'',ifnull(cname,'') from suppliers where id='%s' order by id desc
            """ % sDF
    print sql
    lT, iN = db.select(sql)

    return lT, iN
示例#15
0
def get_proj_info_selected(sDF):
    L = []

    sql = """select id,concat('(',ifnull(gc_no,''),')',ifnull(cname,'')),0,'',concat('(',ifnull(gc_no,''),')',ifnull(cname,'')) from out_proj where id='%s' order by id desc
            """ % sDF
    #print sql
    lT, iN = db.select(sql)

    return lT, iN
示例#16
0
def get_proj_info(search, page_limit):
    L = []

    sql = """select id,concat('(',ifnull(gc_no,''),')',ifnull(cname,'')) from out_proj where stage in (3,4,5) and ifnull(status,1)!=-1 and concat('(',ifnull(gc_no,''),')',ifnull(cname,'')) like '%%%s%%' order by id desc limit %s
            """ % (search, page_limit)
    print sql
    lT, iN = db.select(sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, '', txt])
    return L
示例#17
0
def get_sup_info(search, page_limit):
    L = []

    sql = """select id,ifnull(cname,'') from suppliers where ifnull(status,0)!=-1 and cname like '%%%s%%' order by id desc limit %s
            """ % (search, page_limit)
    print sql
    lT, iN = db.select(sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, '', e[1]])
    return L
示例#18
0
def get_mat_info(search, page_limit, usr_id):
    L = []

    sql = """select id,concat(number,'/',name,'/',size,'/',type,'/',unit,'/',brand),concat('(规格:',ifnull(size,''),')') from  `_m504_clgl`  
            where status != -1 and (state = 1 or (state in (2,3)) and cid=%s) and concat(number,'/',name) like '%%%s%%' order by id desc limit %s
            """ % (usr_id, search, page_limit)
    #print sql
    lT, iN = db.select(sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, '', e[2]])
    return L
示例#19
0
def getValidityResult(field_id, request):
    sql = "select ifnull(validity_sql,''),para_cols from menu_form_validity where field_id= '%s'" % (
        field_id)
    lT, iN = db.select(sql)
    if iN == 0:
        return 1
    sql = lT[0][0]
    para_cols = lT[0][1]
    paras = para_cols.split(',')
    print paras
    print request.POST
    for e in paras:
        if e == '': break
        sql = sql.replace("{%s}" % e,
                          MySQLdb.escape_string(request.POST.get(e, '')))

    print ToGBK(sql)
    lT, iN = db.select(sql)
    if iN == 0:
        return 1
    return lT[0][0]
示例#20
0
def getFormData187(pk, field_id, menu_id, usr_id, request):
    mode = request.GET.get('mode', 'view')
    if field_id == '187':
        db_id = request.POST.get('source_db', '')
        link_id = 189
    else:
        db_id = request.POST.get('dest_db', '')
        link_id = 3369

    sql = """SELECT mfc.col_name
                  ,mfc.label
                  ,ft.name,mfc.requireds,mfc.size,mfc.readonlys,IFNULL(mfc.default_value,'')
                  ,mfc.hides
                  ,IFNULL(mfc.max_length,'')
                  ,mfc.hint
                  ,''
                  ,''
                  ,'' 
                  ,btn_type
                  ,btn_color
                  ,url
                  ,IFNULL(field_col_name,'')
                  ,mfc.field_type
                  ,mfc.default_type
                  ,mfc.field_options_type
                  ,IFNULL(mfc.field_options_txt,'')
                  ,IFNULL(mfc.field_options_default,'')
                  ,IFNULL(mfc.linkfield1,'')
                  ,IFNULL(mfc.linkfield2,'')
                  ,mfc.url_target
                  ,ifnull(mfc.change_cols,'')
                  ,ifnull(mfc.para_cols,'')
                  ,mfc.id
                FROM menu_form_cols mfc
                LEFT join field_type ft on mfc.field_type = ft.id
                where mfc.id = '%s'""" % (link_id)
    sql += """     order by mfc.sort """
    #print sql
    names = 'cid label field_type required size readonly value hide max_length hint field_options table_col table_data btn_type btn_color url'.split(
    )
    rows1, iN1 = db.select(sql)

    L1 = []
    for i in range(0, iN1):
        e = list(rows1[i])
        e[10] = get_options1(db_id)

        L1.append(e)

    data = [dict(zip(names, d)) for d in L1]
    formData = json.dumps(data, ensure_ascii=False)
    return formData
示例#21
0
def file_down(request):
    fname = request.GET.get('fname', '')
    fid = request.GET.get('fid', '')

    if fname != '':
        sql = "SELECT fname,YEAR(ctime),MONTH(ctime),ifnull(title,'') FROM file_pic WHERE fname='%s'" % fname
        lT, iN = db.select(sql)
    elif fid != '':
        sql = "SELECT fname,YEAR(ctime),MONTH(ctime),ifnull(title,'') FROM file_pic WHERE id='%s'" % fid
        lT, iN = db.select(sql)
    else:
        lT = []
    if len(lT) == 0: return '找不到文件'
    L = lT[0]
    fname = L[0]
    year = L[1]
    month = L[2]
    title = L[3]
    path = os.path.join(upload_path, str(year), str(month), fname)

    showMode = 0
    if fname.split('.')[-1].upper() not in ('JPG', 'GIF', 'PNG', 'BMP'):
        showMode = 1
    return readImage(path, showMode, title)
示例#22
0
def setRecentlyProj(request):
    #ret,errmsg,d_value = mValidateUser(request,"view",104)
    #if ret!=0:
    #    return HttpResponseCORS(request,errmsg)
    usr_id = 2  #d_value[0]
    proj_id = request.POST.get('proj_id', '')
    if (usr_id == 0 or proj_id == ''):
        s = """
        {
        "errcode": -1,
        "errmsg": "参数错误"
        }        """
        return HttpResponseJsonCORS(request, s)

    sql = """select id,gc_no,cname from out_proj where id=%s
        """ % (proj_id)
    rows, iN = db.select(sql)
    proj_name = '(%s)%s' % (rows[0][1], rows[0][2])
    sql = "select id from user_options where usr_id=%s and option_type=21 and option_id=%s" % (
        usr_id, proj_id)
    rows, iN = db.select(sql)
    if iN > 0:
        sql = "update user_options set option_value='%s',option_tips='%s',ctime=now(),hits=hits+1 where id=%s" % (
            proj_name, proj_name, rows[0][0])
    else:
        sql = """insert into user_options (usr_id,option_type,option_id,option_value,option_tips,ctime,hits)
              values (%s,21,%s,'%s','%s',now(),1)""" % (usr_id, proj_id,
                                                        proj_name, proj_name)
    #print sql
    db.executesql(sql)
    s = """
        {
        "errcode": 0,
        "errmsg": "保存成功"
        }        """
    return HttpResponseJsonCORS(request, s)
示例#23
0
def get_sup_info(search, page_limit):
    L = []

    sql = """select su.id,ifnull(su.cname,''),'',ifnull(u.qty,0)
from suppliers su
left join (select count(1) as qty,ab.sup_id from addr_book ab 
left join users_gy u on ab.id = u.addr_id
where u.status = 1
group by ab.sup_id) u on u.sup_id = su.id
where ifnull(su.status,0)!=-1  and  su.cname like '%%%s%%' order by su.id desc limit %s
            """ % (search, page_limit)
    print sql
    lT, iN = db.select(sql)
    for e in lT:
        txt = e[1]
        L.append([e[0], txt, '', e[3]])
    return L
示例#24
0
def getRecentlyProj(request):
    #ret,errmsg,d_value = mValidateUser(request,"view",104)
    #if ret!=0:
    #    return HttpResponseCORS(request,errmsg)
    usr_id = 2  #d_value[0]
    sql = """select op.id,op.cname,op.gc_no from user_options u
           left join out_proj op on u.option_id = op.id
           where u.option_type = 21 and u.usr_id = %s
           order by u.ctime desc
           limit 10
        """ % (usr_id)
    rows, iN = db.select(sql)
    names = 'proj_id proj_name proj_no'.split()
    data = [dict(zip(names, d)) for d in rows]
    L = json.dumps(data, ensure_ascii=False, cls=ComplexEncoder)
    s = """
        {
        "errcode": 0,
        "errmsg": "获取数据成功",
        "data":%s
        }        """ % (L)
    # s=ToGBK(s)
    return HttpResponseJsonCORS(request, s)
示例#25
0
def getFormData107(pk, field_id, menu_id, usr_id, request):
    mode = request.GET.get('mode', 'view')

    sql = """SELECT mfc.col_name
                  ,mfc.label
                  ,ft.name,mfc.requireds,mfc.size,mfc.readonlys,IFNULL(mfc.default_value,'')
                  ,mfc.hides
                  ,IFNULL(mfc.max_length,'')
                  ,mfc.hint
                  ,''
                  ,''
                  ,'' 
                  ,btn_type
                  ,btn_color
                  ,url
                  ,IFNULL(field_col_name,'')
                  ,mfc.field_type
                  ,mfc.default_type
                  ,mfc.field_options_type
                  ,IFNULL(mfc.field_options_txt,'')
                  ,IFNULL(mfc.field_options_default,'')
                  ,IFNULL(mfc.linkfield1,'')
                  ,IFNULL(mfc.linkfield2,'')
                  ,mfc.url_target
                  ,ifnull(mfc.change_cols,'')
                  ,ifnull(mfc.para_cols,'')
                  ,mfc.id
                FROM menu_form_cols mfc
                LEFT join field_type ft on mfc.field_type = ft.id
                where mfc.id = '171'"""
    sql += """     order by mfc.sort """
    #print sql
    names = 'cid label field_type required size readonly value hide max_length hint field_options table_col table_data btn_type btn_color url'.split(
    )
    rows1, iN1 = db.select(sql)

    L1 = []
    for i in range(0, iN1):
        e = list(rows1[i])
        new_field = request.POST.get('new_field[]', '')
        new_field = handleMutilValue(new_field, 1)
        table_name = request.POST.get('table_name', '')
        col_name = request.POST.get('col_name', '')
        field_type = request.POST.get('field_type', '')
        field_col_name = request.POST.get('field_col_name', '')
        id = request.POST.get('id', '')
        sql = """select t.table_ab from menu_form_tables t 
                    left join menu_form_cols c on c.step_id = t.step_id
                 where c.id = %s  and t.`table_name` = '%s'""" % (id,
                                                                  table_name)
        rows, iN = db.select(sql)
        if iN == 0:
            table_ab = ''
        else:
            table_ab = '%s.' % rows[0][0]
        if str(new_field) == '1':
            col = '%s%s' % (table_ab, col_name)
        else:
            col = '%s%s' % (table_ab, field_col_name)
        if field_type in ['17', '22', '24']:
            e[6] = ''
        else:
            e[6] = col
        L1.append(e)

    data = [dict(zip(names, d)) for d in L1]
    #print data
    formData = json.dumps(data, ensure_ascii=False)
    return formData
示例#26
0
def home_func(request):
    audit_data = ['','']
    ret,errmsg,d_value = mValidateUser(request,"view",'')
    if ret!=0:
        return HttpResponseCORS(request,errmsg)
    usr_id = d_value[0]
    dept_id = d_value[2]
    sql = "select cname,start_s,end_s,style from chkdatetime order by end_s"
    lT1,iN1 = db.select(sql)

    sql = """SELECT case source when 1 then ga.title 
                     else case ifnull(d.title,'') when '' then concat(op.gc_no,'/',op.cname)
                      else d.title
                     end
                    end,
                    case source when 1 then ga.type_name
                    else gfd.cname
                    end,
                    ga.cusrname,
                    date_format(ga.ctime,'%%Y-%%m-%%d %%T'),
                    d.menu_id,
                    d.id,
                    '',
                    ifnull(ga.url,''),
                    TIMESTAMPDIFF(SECOND,ga.ctime,now())/60,
                    datediff(now(),ga.ctime)
              FROM gw_audit ga
              left join gw_doc d on ga.gw_id= d.id
              left join gw_type gfd on ga.type_id= gfd.id
              left join out_proj op on op.id= d.proj_id
             where ga.usr_id= '%s' order by ga.ctime desc"""%(usr_id)
    #print sql
    lT,iN = db.select(sql)
    L = []
    iN2 = iN
    if iN2 > 10: iN2 = 10
    for i in range(0,iN2):
        e = list(lT[i])
        i = 0
        for a in lT1:
            if e[9]>30: e[8] = e[9]*1440
            if float(e[8]) < float(a[2]):
                if i < iN1:
                    e[3] = a[0]
                    e[6] = a[3]
                else:
                    e[3] = '1年前'
                break
            i+=1
        L.append(e)

    names = 'title gw_type usr_name ctime menu_id pk style url'.split()
    data = [dict(zip(names, d)) for d in L]
    audit_data[0] = data
    audit_data[1] = iN
    names = 'data count'.split()
    L1 = dict(zip(names, audit_data))
    audit = json.dumps(L1,ensure_ascii=False)
 
    sign_data = ['','']
    sql = """SELECT ifnull(ga.title, op.cname),
                    case source when 1 then ga.type_name
                    else gfd.cname
                    end,
                    ga.cusrname,
                    date_format(ga.ctime,'%%Y-%%m-%%d %%T'),
                    d.menu_id,
                    d.id,
                    '',
                    ifnull(ga.url,''),
                    TIMESTAMPDIFF(SECOND,ga.ctime,now())/60,
                    datediff(now(),ga.ctime)
              FROM gw_sign ga
              left join gw_doc d on ga.gw_id= d.id
              left join gw_type gfd on ga.type_id= gfd.id
              left join out_proj op on op.id= d.proj_id
             where ga.usr_id= %s order by ga.ctime desc """%(usr_id)
    lT,iN = db.select(sql)
    L = []
    iN2 = iN
    if iN2 > 10: iN2 = 10
    for i in range(0,iN2):
        e = list(lT[i])
        i = 0
        for a in lT1:
            if e[9]>30: e[8] = e[9]*1440
            if float(e[8]) < float(a[2]):
                if i < iN1:
                    e[3] = a[0]
                    e[6] = a[3]
                else:
                    e[3] = '1年前'
                break
            i+=1
        L.append(e)

    names = 'title gw_type usr_name ctime menu_id pk style url'.split()
    data = [dict(zip(names, d)) for d in L]
    sign_data[0] = data
    sign_data[1] = iN
    names = 'data count'.split()
    L1 = dict(zip(names, sign_data))
    sign = json.dumps(L1,ensure_ascii=False)

    sql = """SELECT 
                    WB.id
                    ,CASE ifnull(RLOG.bb_id,'0') WHEN '0' THEN '0' ELSE '1' END as r_flag
                    ,WB.title
                    ,date_format(WB.ref_date,'%%Y-%%m-%%d %%T')
                    ,WB.cusrname
                    ,NT.cname
                    ,ifnull(U.pic,'')
                    ,case when ifnull(MD.lytime,'')>ifnull(RLOG.read_time,'') then 1 else 0 end as l_flag
                    ,TIMESTAMPDIFF(SECOND,WB.ref_date,now())/60
                    ,''
                    ,datediff(now(),ifnull(WB.ref_date,now()))
               FROM bumph_bubbl WB
               LEFT JOIN users U ON WB.cid=U.usr_id
               LEFT JOIN (
                   select DISTINCT bb_id from bumph_bubbl_groups where group_id in (
                       select id from news_group where is_all=1 or find_in_set(%s,depts) or find_in_set(%s,users))
               ) G ON G.bb_id=WB.id
               LEFT JOIN (select bb_id,usr_id,MAX(read_time) as read_time from bumph_bubbl_read_log where usr_id = %s group by bb_id,usr_id) RLOG ON RLOG.bb_id=WB.id
               LEFT JOIN news_type NT ON NT.type_code=WB.gw_type
               LEFT JOIN (select bb_id,MAX(ctime) as lytime from bumph_bubbl_comment group by bb_id) MD on MD.bb_id = WB.id
               where (G.bb_id is not NULL or find_in_set(%s,recv_users)) and ifnull(audit,3) >= 2 and gw_type = 'A05'
               order by WB.ref_date desc limit 10"""%(dept_id,usr_id,usr_id,usr_id)
    #print sql
    lT,iN = db.select(sql)
    L = []
    for i in range(0,iN):
        e = list(lT[i])
        i = 0
        for a in lT1:
            if e[10]>30: e[8] = e[10]*1440
            if float(e[8]) < float(a[2]):
                if i < iN1:
                    e[8] = a[0]
                    e[9] = a[3]
                else:
                    e[8] = '1年前'
                break
            i+=1
        L.append(e)

    names = 'id r_flag title ref_date cusrname news_type pic l_flag timediff style'.split()
    data = [dict(zip(names, d)) for d in L]
    notice = json.dumps(data,ensure_ascii=False)
               

    sql = """SELECT 
                    WB.id
                    ,CASE ifnull(RLOG.bb_id,'0') WHEN '0' THEN '0' ELSE '1' END as r_flag
                    ,WB.title
                    ,date_format(WB.ref_date,'%%Y-%%m-%%d %%T')
                    ,WB.cusrname
                    ,NT.cname
                    ,ifnull(U.pic,'')
                    ,case when ifnull(MD.lytime,'')>ifnull(RLOG.read_time,'') then 1 else 0 end as l_flag
                    ,TIMESTAMPDIFF(SECOND,WB.ref_date,now())/60
                    ,''
                    ,datediff(now(),ifnull(WB.ref_date,now()))
               FROM bumph_bubbl WB
               LEFT JOIN users U ON WB.cid=U.usr_id
               LEFT JOIN (
                   select DISTINCT bb_id from bumph_bubbl_groups where group_id in (
                       select id from news_group where is_all=1 or find_in_set(%s,depts) or find_in_set(%s,users))
               ) G ON G.bb_id=WB.id
               LEFT JOIN (select bb_id,usr_id,MAX(read_time) as read_time from bumph_bubbl_read_log where usr_id = %s group by bb_id,usr_id) RLOG ON RLOG.bb_id=WB.id
               LEFT JOIN news_type NT ON NT.type_code=WB.gw_type
               LEFT JOIN (select bb_id,MAX(ctime) as lytime from bumph_bubbl_comment group by bb_id) MD on MD.bb_id = WB.id
               where (G.bb_id is not NULL or find_in_set(%s,recv_users)) and ifnull(audit,3) >= 2 and gw_type != 'A05'
               order by WB.ref_date desc limit 10"""%(dept_id,usr_id,usr_id,usr_id)
    #print sql
    lT,iN = db.select(sql)
    L = []
    for i in range(0,iN):
        e = list(lT[i])
        i = 0
        for a in lT1:
            if e[10]>30: e[8] = e[10]*1440
            if float(e[8]) < float(a[2]):
                if i < iN1:
                    e[8] = a[0]
                    e[9] = a[3]
                else:
                    e[8] = '1年前'
                break
            i+=1
        pic = e[6]
        if pic=='':
            e[6] = "%s/user_pic/default.jpg"%(fs_url)
        else:
            e[6] = "%s/user_pic/small_%s"%(fs_url,pic)
        L.append(e)

    names = 'id r_flag title ref_date cusrname news_type pic l_flag timediff style'.split()
    data = [dict(zip(names, d)) for d in L]
    recv_info = json.dumps(data,ensure_ascii=False)

    sql ="""SELECT  
                    WB.id
                    ,0
                    ,WB.title
                    ,left(WB.content,300)
                    ,date_format(WB.ctime,'%%Y-%%m-%%d %%T')
                    ,WB.cusrname
                    ,ifnull(WB.ifaud,0)
                    ,NT.cname
                    ,D.cname
                    ,ifnull(WB.must_reply,0)
                    ,ifnull(U.pic,'')
                    ,ifnull(WB.audit,3)
               FROM bumph_bubbl WB
               LEFT JOIN users U ON WB.cid=U.usr_id
               LEFT JOIN dept D ON D.id=U.dept_id
               LEFT JOIN news_type NT ON NT.type_code=WB.gw_type
               where WB.audusrid=%s and WB.audit in (1) order by WB.ctime desc limit 10
            """%(usr_id)
    names = 'seq r_flag title content ref_date usr_name needsh news_type dept must_reply pic audit'.split()
    rows,iN = db.select(sql)
    L = []
    for e in rows:
        L2 = list(e)
        pic = L2[10]
        if pic=='':
            L2[10] = "%s/user_pic/default.jpg"%(fs_url)
        else:
            L2[10] = "%s/user_pic/small_%s"%(fs_url,pic)

        L.append(L2)

    data = [dict(zip(names, d)) for d in L]
    waitAudit = json.dumps(data,ensure_ascii=False)

    sql = """SELECT 
                    WB.id
                    ,CASE ifnull(RLOG.bb_id,'0') WHEN '0' THEN '0' ELSE '1' END as r_flag
                    ,WB.title
                    ,date_format(WB.ref_date,'%%Y-%%m-%%d %%T')
                    ,WB.cusrname
                    ,NT.cname
                    ,ifnull(U.pic,'')
                    ,case when ifnull(MD.lytime,'')>ifnull(RLOG.read_time,'') then 1 else 0 end as l_flag
                    ,TIMESTAMPDIFF(SECOND,WB.ref_date,now())/60
                    ,''
                    ,datediff(now(),ifnull(WB.ref_date,now()))
               FROM bumph_bubbl WB
               LEFT JOIN users U ON WB.cid=U.usr_id
               LEFT JOIN (
                   select DISTINCT bb_id from bumph_bubbl_groups where group_id in (
                       select id from news_group where is_all=1 or find_in_set(%s,depts) or find_in_set(%s,users))
               ) G ON G.bb_id=WB.id
               LEFT JOIN (select bb_id,usr_id,MAX(read_time) as read_time from bumph_bubbl_read_log where usr_id = %s group by bb_id,usr_id) RLOG ON RLOG.bb_id=WB.id
               LEFT JOIN news_type NT ON NT.type_code=WB.gw_type
               LEFT JOIN (select bb_id,MAX(ctime) as lytime from bumph_bubbl_comment group by bb_id) MD on MD.bb_id = WB.id
               where (G.bb_id is not NULL or find_in_set(%s,recv_users)) and ifnull(audit,3) >= 2 and gw_type = 'A09'
               order by WB.ref_date desc limit 10"""%(dept_id,usr_id,usr_id,usr_id)
    #print sql
    lT,iN = db.select(sql)
    L = []
    for i in range(0,iN):
        e = list(lT[i])
        i = 0
        for a in lT1:
            if e[10]>30: e[8] = e[10]*1440
            if float(e[8]) < float(a[2]):
                if i < iN1:
                    e[8] = a[0]
                    e[9] = a[3]
                else:
                    e[8] = '1年前'
                break
            i+=1
        L.append(e)

    names = 'id r_flag title ref_date cusrname news_type pic l_flag timediff style'.split()
    data = [dict(zip(names, d)) for d in L]
    zhidu = json.dumps(data,ensure_ascii=False)

    s = """
        {
        "errcode": 0,
        "errmsg": "获取主页数据成功",
        "audit":%s,
        "sign":%s,
        "notice":%s,
        "zhidu":%s,
        "recv_info":%s,
        "audit_info":%s
        }        """%(audit,sign,notice,zhidu,recv_info,waitAudit)
    #print ToGBK(s)
    return HttpResponseCORS(request,s)
示例#27
0
def index_wx_func(request):
    import base64, time
    import random
    random_no = '%s' % (random.randint(0, 999999))
    source = 'wx'
    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
        ip = request.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = request.META['REMOTE_ADDR']
    print ip
    code = request.GET.get('code', '')
    func = request.GET.get('func', '')
    if func == '':
        func = request.GET.get('state', '')
    func = func.lower()
    if func in ['gwlist', 'gw_view', 'gw_audit', 'gw_sign']:
        agentname = '公文审批'
    elif func in [
            'info_send', 'info_list', 'info_upd', 'info_detail', 'info_audit'
    ]:
        agentname = '信息交换'
    elif func in ['myloglist', 'otherloglist', 'writelog', 'logdetail']:
        agentname = '工作日志'
    elif func in ['fa_code']:
        agentname = '固定资产管理'
    else:
        agentname = '通讯录'
    print func
    error_url = '%s/wx/mui/error.html' % front_url
    if func == 'FA_Code':
        FAcode = request.GET.get('facode', '')
        url = '%s/wx/mui/fixedAssetsInfo.html?code=%s' % (front_url, FAcode)
        return HttpResponseRedirect(url)

    url = ''
    if func == 'gwlist':
        type = request.GET.get('type', '')
        if str(type) in ['1', '2', '3']:
            url = '%s/wx/mui/examine.html?func=%s&type=%s' % (front_url, func,
                                                              type)
        else:
            url = '%s/wx/mui/myExamine.html?func=%s&type=%s' % (front_url,
                                                                func, type)
    elif func == 'gw_view':
        menu_id = request.GET.get('menu_id', '')
        pk = request.GET.get('pk', '')
        url = '%s/wx/examineDetail.html?menu_id=%s&pk=%s&mode=view&infotype=msg' % (
            front_url, menu_id, pk)
    elif func == 'gw_audit':
        menu_id = request.GET.get('menu_id', '')
        pk = request.GET.get('pk', '')
        url = '%s/wx/examineDetail.html?menu_id=%s&pk=%s&mode=audit&infotype=msg' % (
            front_url, menu_id, pk)
    elif func == 'gw_sign':
        menu_id = request.GET.get('menu_id', '')
        pk = request.GET.get('pk', '')
        url = '%s/wx/examineDetail.html?menu_id=%s&pk=%s&mode=sign&infotype=msg' % (
            front_url, menu_id, pk)
    elif func == 'info_send':
        url = '%s/wx/mui/infoExchange_index.html?id=2' % (front_url)
    elif func == 'info_list':
        id = request.GET.get('id', '')
        type = request.GET.get('type', '')
        url = '%s/wx/mui/infoExchange_index.html?id=%s&type=%s' % (front_url,
                                                                   id, type)
    elif func == 'info_audit':
        pk = request.GET.get('pk', '')
        must_reply = request.GET.get('must_reply', '')
        url = '%s/wx/mui/infoExamine.html?seq=%s&must_reply=%s&infotype=msg' % (
            front_url, pk, must_reply)
    elif func == 'info_detail':
        pk = request.GET.get('pk', '')
        must_reply = request.GET.get('must_reply', '')
        url = '%s/wx/mui/infoDetail.html?seq=%s&must_reply=%s&index=0&infotype=msg' % (
            front_url, pk, must_reply)
    elif func == 'info_upd':
        pk = request.GET.get('pk', '')
        url = '%s/wx/mui/changeInfo.html?seq=%s&infotype=msg' % (front_url, pk)
    elif func == 'fa_code':
        FAcode = request.GET.get('facode', '')
        url = '%s/wx/mui/fixedAssetsInfo.html?code=%s' % (front_url, FAcode)
    elif func == 'myloglist':
        url = '%s/wx/mui/myLogList.html?source=%s' % (front_url, source)
    elif func == 'otherloglist':
        url = '%s/wx/mui/otherLogList.html?source=%s' % (front_url, source)
    elif func == 'writelog':
        url = '%s/wx/mui/writeLog.html?source=%s' % (front_url, source)
    elif func == 'logdetail':
        id = request.GET.get('id', '')
        url = '%s/wx/mui/logDetail.html?id=%s' % (front_url, id)
    else:
        return HttpResponseRedirect(error_url)

    if request.session.has_key('login_data_wx'):
        d = request.session.get('login_data_wx', '')
        #userid = request.COOKIES.get('usr_wx_id','')
        userid = d[0]
        print "userid=%s" % (userid)
        sql = """select token,id from users_login where source='%s' and usr_id ='%s'  and time_to_sec(now()) - time_to_sec(refresh_time) < expire_time order by refresh_time desc limit 1 
                    """ % (source, userid)
        print sql
        lT, iN = db.select(sql)
        if iN > 0:
            token = lT[0][0]
            id = lT[0][1]
            sql = "update users_login set refresh_time=now() where id=%s" % (
                id)
            db.executesql(sql)
            url += "&AccessToken=%s" % token
            print url
            dt = datetime.datetime.now() + datetime.timedelta(hours=2)
            response = HttpResponseRedirect(url)
            response.set_cookie("usr_wx_id", userid, expires=dt)
            #sql = "select usr_id,usr_name,dept_id,login_id,d.cname from users  u left join dept d on d.id=u.dept_id where usr_id='%s' and status=1"%userid
            #lT,iN = db.select(sql)
            #if iN>0:
            #    value=[userid,lT[0][1],lT[0][2],lT[0][4],lT[0][3]]
            #    print value
            #    request.session['login_data_wx'] = value
            return response

    if code != '':
        ddata = getuserinfo(code, agentname)
        try:
            print ddata
            uName = ddata['UserId']
            DeviceId = ddata['DeviceId']
        except Exception, e:
            uName = ''
            DeviceId = ''
            return HttpResponseRedirect(error_url)

        sql = "select usr_id,usr_name,dept_id,login_id,d.cname from users  u left join dept d on d.id=u.dept_id where ifnull(wxqy_id,login_id)='%s' and status=1" % uName
        print sql
        lT, iN = db.select(sql)
        if iN > 0:
            userid = lT[0][0]
            usr_name = lT[0][1]
            dept_id = lT[0][2]
            dept_name = lT[0][4]
            login_id = lT[0][3]
            sTimeStamp = str(time.time())
            wxcpt = WXBizMsgCrypt('szoworld', m_aesKey)
            ret, token = wxcpt.EncryptMsg(login_id, random_no, sTimeStamp)

            sql = """insert into users_login (usr_id,source,token,login_ip,login_time,refresh_time,expire_time)
                     values (%s,'%s','%s','%s',now(),now(),%s) 
                    """ % (userid, source, token, ip, int(TIME_OUT) * 60)
            print ToGBK(sql)
            db.executesql(sql)
            token = urllib.quote(token)
            url += "&AccessToken=%s" % token
            dt = datetime.datetime.now() + datetime.timedelta(hours=2)
            response = HttpResponseRedirect(url)
            response.set_cookie("usr_wx_id", userid, expires=dt)

            value = [userid, usr_name, dept_id, dept_name, login_id]
            print value
            request.session['login_data_wx'] = value

            return response
        else:
            return HttpResponseRedirect(error_url)
示例#28
0
def login_wx_func(request):
    import base64, time
    import random
    random_no = '%s' % (random.randint(0, 999999))
    usr_id, usr_name, dept_id, dept_name = '', '', '', ''
    source = 'wx'
    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
        ip = request.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = request.META['REMOTE_ADDR']

    code = request.GET.get('code', '')
    login_id = getLoginID(code)
    if login_id == '':
        errCode = 1
        msg = u'用户名不存在'
        s = """
            {
            "errcode": %s,
            "errmsg": "%s",
            "login_id": "%s",
            }
            """ % (errCode, msg, login_id)
        return s

    login_id = login_id.replace("'", "")

    s1 = ''
    sql = """SELECT U.usr_id,U.usr_name,U.dept_id,D.cname,IFNULL(U.pic,''),U.password,U.login_id
                   FROM users U LEFT JOIN dept D ON U.dept_id=D.id
                   WHERE ifnull(U.wxqy_id,U.login_id)='%s' AND U.status=1 
                """ % (login_id)
    lT, iN = db.select(sql)
    if iN > 0:
        usr_id = lT[0][0]
        login_id = lT[0][6]
        #求得用户的权限
        dActiveUser[usr_id] = {}
        dActiveUser[usr_id]['roles'] = {}  #用户角色
        dActiveUser[usr_id]['access_dept_data'] = [
        ]  #访问部门内所有人员数据的权限,格式:['部门ID1','部门ID2',...]
        dActiveUser[usr_id]['access_person_data'] = [
        ]  #访问人员数据的权限,格式:['人员ID1','人员ID2',...]
        dActiveUser[usr_id]['login_time'] = time.time()  #登入时间
        dActiveUser[usr_id]['usr_name'] = lT[0][1]  #用户名
        dActiveUser[usr_id]['login_id'] = login_id
        dActiveUser[usr_id]['usr_dept'] = lT[0][2], lT[0][3]  #用户部门
        dActiveUser[usr_id]['pic'] = lT[0][4]

        #用户角色/访问部门内所有人员数据的权限
        sql = """SELECT WUR.role_id,WR.role_name,WR.sort,WR.dept_id
                       FROM usr_role WUR LEFT JOIN roles WR ON WUR.role_id=WR.role_id
                       WHERE WUR.usr_id=%s
            """ % usr_id
        lT1, iN1 = db.select(sql)
        if iN1 > 0:
            for e in lT1:
                #用户角色
                dActiveUser[usr_id]['roles'][e[0]] = e[1:]

        request.session['usr_id'] = usr_id
        request.session['usr_name'] = dActiveUser[usr_id]['usr_name']
        request.session['dept_id'] = lT[0][2]
        request.session['dept_name'] = lT[0][3]
        request.session['dActiveUser'] = dActiveUser
        d_value = ['', '', '', '', '']
        d_value[0] = usr_id
        d_value[1] = dActiveUser[usr_id]['usr_name']
        d_value[2] = lT[0][2]
        d_value[3] = lT[0][3]
        d_value[4] = 0
        g_data.set_value(d_value)
        errCode = 0
        msg = 'OK'
        pic = lT[0][4]
        if pic == '':
            pic_url = "%s/user_pic/default.jpg" % fs_url
        else:
            pic_url = "%s/user_pic/small_" % fs_url + pic
        sTimeStamp = str(time.time())
        wxcpt = WXBizMsgCrypt('szoworld', m_aesKey)
        ret, token = wxcpt.EncryptMsg(login_id, random_no, sTimeStamp)

        if usr_id in [1, 2]:
            sql = """SELECT distinct WMF.menu,WMF.menu_id,WMF.menu_name,
                   WMF.sort,WMF.parent_id,WMF.status,WMF.url,WMF.icon
                   FROM menu_func WMF 
                   Left JOIN menu_func WMF1 on WMF.parent_id = WMF1.menu_id
                   WHERE WMF.status=1 and WMF.menu_id>0 and WMF1.status=1
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """
        else:
            sql = """SELECT distinct WMF.menu,WMF.menu_id,WMF.menu_name,
                   WMF.sort,WMF.parent_id,WMF.status,WMF.url,WMF.icon
                   FROM usr_role WUR JOIN (role_menu WRM JOIN menu_func WMF ON WRM.menu_id=WMF.menu_id) ON WUR.role_id=WRM.role_id
                   WHERE WUR.usr_id='%s' AND WMF.status=1 and WMF.menu_id>0 and WRM.can_view=1
                   ORDER BY WMF.parent_id,WMF.menu,WMF.sort,WMF.menu_id
                """ % usr_id
        #print sql
        rows, iN = db.select(sql)
        L1 = [2]
        L2 = []
        #L = formatData(rows,L1,L2)
        names = 'level menu_id menu_name sort parent_id status url icon'.split(
        )
        data = [dict(zip(names, d)) for d in rows]

        s3 = json.dumps(data, ensure_ascii=False)

        s1 = """"userid":%s,
                "username":"******",
                "dept_id":%s,
                "dept_name":"%s",
                "pic_url":"%s",
                "AccessToken":"%s",
                "menu_data":%s,""" % (lT[0][0], (lT[0][1]), lT[0][2],
                                      (lT[0][3]), pic_url, token, s3)
        sql = """insert into users_login (usr_id,source,token,login_ip,login_time,refresh_time,expire_time)
                 values (%s,'%s','%s','%s',now(),now(),%s) 
                """ % (lT[0][0], source, token, ip, int(TIME_OUT) * 60)
        #print ToGBK(sql)

        db.executesql(sql)
    else:
        errCode = 1
        msg = u'用户名不存在'
    s = """
        {
            "errcode": %s,
            "errmsg": "%s",
            "login_id": "%s",
            %s
        }
        """ % (errCode, msg, login_id, s1)
    #print ToGBK(s)
    response = HttpResponseCORS(request, s)
    return response
示例#29
0
def getFormData1518(pk, field_id, menu_id, usr_id, request):
    mode = request.GET.get('mode', 'view')

    sql = """SELECT mfc.col_name
                  ,mfc.label
                  ,ft.name,mfc.requireds,mfc.size,mfc.readonlys,IFNULL(mfc.default_value,'')
                  ,mfc.hides
                  ,IFNULL(mfc.max_length,'')
                  ,mfc.hint
                  ,''
                  ,''
                  ,'' 
                  ,btn_type
                  ,btn_color
                  ,url
                  ,IFNULL(field_col_name,'')
                  ,mfc.field_type
                  ,mfc.default_type
                  ,mfc.field_options_type
                  ,IFNULL(mfc.field_options_txt,'')
                  ,IFNULL(mfc.field_options_default,'')
                  ,IFNULL(mfc.linkfield1,'')
                  ,IFNULL(mfc.linkfield2,'')
                  ,mfc.url_target
                  ,ifnull(mfc.change_cols,'')
                  ,ifnull(mfc.para_cols,'')
                  ,mfc.id
                FROM menu_form_cols mfc
                LEFT join field_type ft on mfc.field_type = ft.id
                where mfc.id = '1519'"""
    sql += """     order by mfc.sort """
    #print sql
    names = 'cid label field_type required size readonly value hide max_length hint field_options table_col table_data btn_type btn_color url'.split(
    )
    rows1, iN1 = db.select(sql)

    L1 = []
    for i in range(0, iN1):
        e = list(rows1[i])
        table_name = request.POST.get('table_name', '')
        col_name = request.POST.get('col_name', '')
        field_type = request.POST.get('field_type', '')
        id = request.POST.get('id', '')
        menu_id = request.POST.get('menu_id', '')
        field_options_type = request.POST.get('field_options_type', '')
        new_field = request.POST.get('new_field[]', '')
        new_field = handleMutilValue(new_field, 1)
        field_col_name = request.POST.get('field_col_name', '')
        #field_type = request.POST.get('field_type','')
        sql = """select t.table_ab from menu_list_tables t 
                 where t.menu_id =%s  and t.`table_name` = '%s'""" % (
            menu_id, table_name)
        rows, iN = db.select(sql)
        if iN == 0:
            table_ab = ''
            col = col_name
        else:
            table_ab = rows[0][0]
            col = '%s.%s' % (table_ab, col_name)
        if str(new_field) == '1':
            field_col_name = col_name

        if field_type in ['17', '22', '24']:
            e[6] = ''
        elif str(field_type) in ['3', '5', '6', '18', '26', '32']:
            type = int(field_options_type)
            if type == 1:
                pass
            elif type == 2:
                pass
            elif type == 3:
                pass
            elif type == 4:
                pass
            elif type == 5:
                pass
            elif type == 6:
                pass
            elif type == 7:
                pass
            elif type == 10:
                pass
            elif type == 8:
                pass
            elif type == 9:
                pass
            elif type == 11:
                pass
            elif type == 12:
                pass
            elif type == 13:
                pass
            elif type == 14:
                pass
            elif type == 15:
                pass
            elif type == 16:
                pass
            elif type == 17:
                pass
            elif type == 18:
                pass
            elif type == 19:
                pass
            elif type == 20:
                pass
            elif type == 21:
                tn = 'out_proj'
                tb = 'OP'
                tid = 'id'
                e[6] = "concat('(',ifnull(OP.gc_no,''),')',ifnull(OP.cname,''))"
            elif type == 22:
                tn = 'contract_sg_file'
                tb = 'SG'
                tid = 'id'
                e[6] = "ifnull(SG.code,'')"
            elif type == 23:
                tn = 'suppliers'
                tb = 'su'
                tid = 'id'
                e[6] = "ifnull(su.cname,'')"
            sql = "select id,page_name,ifnull(where_sql,'') from menu_list_pages where menu_id=%s" % (
                menu_id)
            rows1, iN1 = db.select(sql)
            for e1 in rows1:
                sql = "select id from menu_list_tables where page_id = %s and table_name='%s'" % (
                    e1[0], tn)
                #print sql
                rows2, iN2 = db.select(sql)
                if iN2 == 0:
                    sql = """insert into menu_list_tables 
                                 (menu_id,page_id,join_type,table_name,table_ab,index_name,link_table,link_ab,link_index,sort)
                                 values (%s,%s,'LEFT JOIN','%s','%s','%s','%s','%s','%s',%s)
                              """ % (menu_id, e1[0], tn, tb, tid, table_name,
                                     table_ab, field_col_name, 99)
                    db.executesql(sql)
                    sql = "select join_type,table_name,table_ab,index_name,link_ab,link_index,ifnull(table_sql,'') from menu_list_tables where page_id = %s  order by sort" % (
                        e1[0])
                    #print sql
                    rows, iN = db.select(sql)
                    table_sql = encode_table_sql(rows)
                    table_sql = '%s %s' % (table_sql, e1[2])
                    sql = """update menu_list_pages set table_sql="%s" where id=%s
                          """ % (table_sql, e1[0])
                    #print sql
                    db.executesql(sql)

        else:
            e[6] = col
        L1.append(e)

    data = [dict(zip(names, d)) for d in L1]
    #print data
    formData = json.dumps(data, ensure_ascii=False)
    return formData
示例#30
0
def getFormData2076(pk, field_id, menu_id, usr_id, request):
    mode = request.GET.get('mode', 'view')
    sql = "SELECT change_cols,para_cols,is_grid from menu_form_cols where id=%s" % field_id
    rows, iN = db.select(sql)
    if iN > 0:
        refresh_field = rows[0][0]
        para_cols = rows[0][1] or ''
        is_grid = rows[0][2]
    sql = "SELECT form_table,has_audit from menu_data_source where menu_id=%s" % pk
    rows, iN = db.select(sql)
    if iN > 0:
        form_table = rows[0][0].lower()
        has_audit = rows[0][1] or 0

    sql = """SELECT mfc.col_name
                  ,mfc.label
                  ,ft.name,mfc.required,mfc.size,mfc.readonly,IFNULL(mfc.default_value,'')
                  ,mfc.hide
                  ,IFNULL(mfc.max_length,'')
                  ,mfc.hint
                  ,''
                  ,''
                  ,'' 
                  ,btn_type
                  ,btn_color
                  ,url
                  ,IFNULL(field_col_name,'')
                  ,mfc.field_type
                  ,mfc.default_type
                  ,mfc.field_options_type
                  ,IFNULL(mfc.field_options_txt,'')
                  ,IFNULL(mfc.field_options_default,'')
                  ,IFNULL(mfc.linkfield1,'')
                  ,IFNULL(mfc.linkfield2,'')
                  ,mfc.url_target
                  ,ifnull(mfc.change_cols,'')
                  ,ifnull(mfc.para_cols,'')
                  ,mfc.id
                FROM menu_form_cols mfc
                LEFT join field_type ft on mfc.field_type = ft.id
                where mfc.id in (2073,2079)"""
    sql += """     order by mfc.sort """
    #print sql
    names = 'cid label field_type required size readonly value hide max_length hint field_options table_col table_data btn_type btn_color url'.split(
    )
    rows1, iN1 = db.select(sql)
    #print request.POST
    L1 = []
    for i in range(0, iN1):
        e = list(rows1[i])
        is_new = request.POST.get('is_new[]', '')
        if e[-1] == 2079 and str(is_new) == '1':
            e[6] = form_table + "_list"
        if e[-1] == 2073 and str(is_new) == '1':
            if has_audit == 1:
                link = 'gw_id'
            else:
                link = 'm_id'
            e[6] = "select id from %s_list where %s = {pk}" % (form_table,
                                                               link)
        L1.append(e)

    data = [dict(zip(names, d)) for d in L1]
    #print data
    formData = json.dumps(data, ensure_ascii=False)
    return formData