forked from sinowisaland/yinmore_wechat_pay
/
public_db.py
125 lines (105 loc) · 3.06 KB
/
public_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pg
import user_bz
import db_bz
#import time_bz
user_oper = user_bz.UserOper(pg)
def getPayInfo(openid=None, statuses=None, user_id=None, id=None):
sql = '''
select id, openid, card_number, stat_date, card_number, total_fee, status from pay
where 1=1
'''
if openid:
sql += " and openid='%s' " % openid
if statuses:
in_statuses = db_bz.formatToInSql(statuses)
sql += " and status in (%s) " % in_statuses
if user_id:
sql += " and user_id=%s " % user_id
if id:
sql += " and id=%s " % id
sql += " order by created_date desc "
return list(pg.query(sql))
def getLast(user_id):
if user_id is None:
return
result = list(pg.select('last', where="user_id=%s" % user_id))
if result:
return result[0]
def delNoName(type, name):
sql = '''
update user_info set %s=null where lower(%s)=lower('%s')
''' % (type, type, name)
pg.query(sql)
print 'del', type, name
def getOpenidsByName(type, name):
sql = '''
select w.openid from user_info u, follow_who f, user_info u2, wechat_user w
where lower(u.%s)=lower('%s')
and u.id = f.god_id
and u2.id = f.user_id
and w.user_name=u2.user_name
''' % (type, name)
return pg.query(sql)
def followedWho(user_id):
sql = '''
select god_id from follow_who where user_id=%s
''' % user_id
return pg.query(sql)
def getWechatUserByOpenid(openid):
'''
create by bigzhu at 15/04/04 12:48:58 根据 openid 来查询微信用户
'''
return list(pg.select('wechat_user', where="openid='%s'" % openid))
def getBindInfoByOpenid(openid):
sql = '''
select b.openid,
b.card_number,
b.car_number,
b.car_type, -- 车型
b.phone_number, -- 手机号
b.name, -- 姓名
b.id_number -- 身份证号
from bind_card_info b
where b.openid='%s'
''' % openid
return pg.query(sql)
def getCardinfos(openid=None, id=None):
sql = '''
select b.id,
b.openid,
b.card_number,
b.car_number,
b.car_type, -- 车型
b.phone_number, -- 手机号
b.name, -- 姓名
b.id_number -- 身份证号
from bind_card_info b
where is_delete=0
'''
if openid:
sql += " and b.openid='%s' " % openid
if id:
sql += " and b.id=%s " % id
return pg.query(sql)
def getWechatUserBindInfoByOpenid(openid):
'''
查出用户信息
'''
sql = '''
select w.openid,
w.id as wechat_user_id,
b.card_number,
b.car_number,
b.car_type, -- 车型
b.phone_number, -- 手机号
b.name, -- 姓名
b.id_number -- 身份证号
from wechat_user w left join bind_card_info b
on w.id = b.wechat_user_id
where w.openid='%s'
''' % openid
return pg.query(sql)
if __name__ == '__main__':
pass