-
Notifications
You must be signed in to change notification settings - Fork 39
/
MODEL_DL.py
147 lines (110 loc) · 4.49 KB
/
MODEL_DL.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) wxmall.janedao.cn
# Author:QQ173782910
#QQ group:528289471
##############################################################################
"""admin/dl/MODEL_DL.py"""
#
# from imp import reload
# from basic.publicw import DEBUG
# if DEBUG == '1':
# import admin.dl.DL_BASE
# reload(admin.dl.DL_BASE)
from admin.dl.DL_BASE import cDL_BASE
import os
from wechatpy import WeChatClient
from wechatpy.client.api import WeChatWxa
class cMODEL_DL(cDL_BASE):
def myaddslashes(self, s):
if not s:
return s
d = {'"': '\\"', "'": "\\'", "\0": "\\\0", "\\": "\\\\"}
return ''.join(d.get(c, c) for c in s)
# 代替了self.REQUEST.get()
# key为参数名, default为默认值,type为是否需要过滤字符
def GPRQ(self, key, default=None, ctype=1):
value = self.REQUEST.get(key, default)
if ctype == 1 and value and isinstance(value, str):
self.myaddslashes(value.strip())
return value
def list_for_grid(self, List,iTotal_length, pageNo=1, select_size=10):
if iTotal_length % select_size == 0:
iTotal_Page = iTotal_length // select_size
else:
iTotal_Page = iTotal_length // select_size + 1
start, end = (int(pageNo) - 1) * select_size, pageNo * select_size
if end >= iTotal_length: end = iTotal_length
if iTotal_length == 0 or start > iTotal_length or start < 0:
return [], iTotal_length, iTotal_Page, pageNo, select_size
return List[start:end], iTotal_length, iTotal_Page, pageNo, select_size
def make_sub_path(self, sPATH):
"""检查os的最后一级子目录,如果不存在,生成之"""
if os.path.exists(sPATH) == 0:
os.makedirs(sPATH)
return 0
def pic_list(self):
L=[]
sql="select id,id from images where usr_id =%s"
l,t=self.db.select(sql,self.usr_id_p)
if t>0:
L=l
return L
def pic_dict(self):
D={}
sql="select id,pic from images where usr_id =%s"
l,t=self.db.select(sql,self.usr_id_p)
if t>0:
for i in l:
D[i[0]]=i[1]
return D
def list_for_grid_self(self, List,iTotal_length, pageNo=1, select_size=10):
if iTotal_length % select_size == 0:
iTotal_Page = iTotal_length // select_size
else:
iTotal_Page = iTotal_length // select_size + 1
start, end = (int(pageNo) - 1) * select_size, pageNo * select_size
if end >= iTotal_length: end = iTotal_length
if iTotal_length == 0 or start > iTotal_length or start < 0:
return [], iTotal_length, iTotal_Page, pageNo, select_size
return List, iTotal_length, iTotal_Page, pageNo, select_size
def print_log(self,cname,errors):
sql="insert into print_log(cname,errors,ctime)values(%s,%s,now())"
self.db.query(sql,[cname,errors])
return
def write_order_log(self,order_id,edit_name='',edit_memo='',edit_remark=''):
sql="""insert into wechat_mall_order_log(usr_id,order_id,edit_name,edit_memo,edit_remark,cid,ctime)
values(%s,%s,%s,%s,%s,%s,now())
"""
self.db.query(sql,[self.usr_id_p,order_id,edit_name,edit_memo,edit_remark,self.usr_id])
return
def user_log(self,uid,cname,memo):
sql="insert into user_log(usr_id,wechat_user_id,cname,memo,ctime)values(%s,%s,%s,%s,now())"
self.db.query(sql,[self.usr_id_p,uid,cname,memo])
return
def get_wecthpy(self):#微信小程序调用
mall=self.oMALL.get(self.usr_id_p)
if mall=={}:
return 0
appid=mall['appid']
secret =mall['secret']
client = WeChatClient(appid, secret)
wxa = WeChatWxa(client)
return wxa
def use_log(self,memo):
sql="insert into use_log(usr_id,viewid,memo,ctime)values(%s,%s,%s,now())"
self.db.query(sql,[self.usr_id,self.viewid,memo])
return
def get_QR_code_url(self,vtype):
if self.qr_ticket!='':
return self.qr_ticket
pdata = {'viewid': 'wxcode', 'part': 'Get_ticket',
'vtype': vtype
}
r = self._http.post('https://wxcode.yjyzj.cn/wxcode', data=pdata)
res = r.json()
if res.get('code', '') == '0':
url = res.get('url', '')
self.qr_ticket = url
return url
return ''