-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_gl_packetqty_rules.py
222 lines (208 loc) · 8.59 KB
/
product_gl_packetqty_rules.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!coding:utf8
from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
import confsql
from mylog import log
from django.utils import simplejson
from functions import trim_csv,verifyData
confsql=confsql.Confsql()
def import_product_gl_packetqty_rules(request):
'商品配送规则导入'
if request.method=='POST':
value=request.POST['value']
rs1=trim_csv(value,itemlenth=4)
rs2,rs1=verifyData(rs1,length=4,required=[0,2,3],psrules=1)
temp=[]
for rs in rs1:
excode=rs[2]
if rs[2]==u'商品代码':
excode='sp'
if rs[2]==u'小类代码':
excode='xl'
if rs[2]==u'中类代码':
excode='zl'
if rs[2]==u'大类代码':
excode='dl'
'重复项覆盖'
sqlstr="select * from product_gl_packetqty_rules where xcode='"+rs[0]+"' and excode='"+excode+"'"
if confsql.checkExist(sqlstr)==1: #检查xcode,excode,packetqty 数据库是否已存在
rs.append(u'数据库已存在!')
temp.append(rs)
rs2.append(rs)
if len(temp)>0:
for rs in temp:
rs1.remove(rs)
html=u"<table width='800'><tr><th>代码</th><th>名称</th><th>代码说明</th><th>配货单位</th></tr>"
if len(rs2)>0:
for rs in rs2:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td style='background-color:yellow;'>" + rs[4] + "</td>"
html+="</tr>"
if len(rs1)>0:
for rs in rs1:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td></td>"
html+="</tr>"
html+="</table>"
return HttpResponse(html)
else:
t=get_template('mana1/import_product_gl_packetqty_rules.html')
html=t.render(Context())
return HttpResponse(html)
def save_product_gl_packetqty_rules(request):
'保存商品配货单位规则'
rs1=[]
result=[]
myjson=simplejson.loads(request.POST["myjson"])
rs1=trim_csv(myjson["table"])
#sp, xl, zl, dl, null
for rs in rs1:
excode=rs[2]
if rs[2]==u'商品代码':
excode='sp'
if rs[2]==u'小类代码':
excode='xl'
if rs[2]==u'中类代码':
excode='zl'
if rs[2]==u'大类代码':
excode='dl'
if rs[4]<>'':
if rs[4]==u'数据库已存在!':
try:
sqlstr="delete from product_gl_packetqty_rules where xcode='"+rs[0]+"' and excode='" + excode + "'"
confsql.runSql(sqlstr)
sqlstr="insert into product_gl_packetqty_rules (xcode,excode,packetqty1) values('"+rs[0]+"','"+excode+"','"+rs[3]+"')"
confsql.runSql(sqlstr)
rs[4]='插入成功!'
except:
rs[4]='插入失败!'
res={}
res['xcode']=rs[0]
res['name']=rs[1]
res['excode']=rs[2]
res['packetqty1']=rs[3]
res['info']=rs[4]
result.append(res)
else:
res={}
res['xcode']=rs[0]
res['name']=rs[1]
res['excode']=rs[2]
res['packetqty1']=rs[3]
res['info']=rs[4]
result.append(res)
else:
try:
sqlstr="insert into product_gl_packetqty_rules (xcode,excode,packetqty1) values('"+rs[0]+"','"+excode+"','"+rs[3]+"')"
confsql.runSql(sqlstr)
rs[4]='插入成功!'
except:
rs[4]='插入失败!'
res={}
res['xcode']=rs[0]
res['name']=rs[1]
res['excode']=rs[2]
res['packetqty1']=rs[3]
res['info']=rs[4]
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
def insult_product_gl_packetqty_rules(request):
'查询商品配送单位规则'
t=get_template('mana1/insult_product_gl_packetqty_rules.html')
sqlstr="select t1.xcode,t2.proname,'商品代码',round(t1.packetqty1) from product_gl_packetqty_rules t1,product_all t2 where t1.xcode=t2.proid and excode='sp' group by t1.xcode,t2.proname,t1.packetqty1 union all "
sqlstr+="select t1.xcode,t2.proxl,'小类代码',round(t1.packetqty1) from product_gl_packetqty_rules t1,product_all t2 where t1.xcode=t2.proxl_id and excode='xl' group by t1.xcode,t2.proxl,t1.packetqty1 union all "
sqlstr+="select t1.xcode,t2.prozl,'中类代码',round(t1.packetqty1) from product_gl_packetqty_rules t1,product_all t2 where t1.xcode=t2.prozl_id and excode='zl' group by t1.xcode,t2.prozl,t1.packetqty1 union all "
sqlstr+="select t1.xcode,t2.prodl,'大类代码',round(t1.packetqty1) from product_gl_packetqty_rules t1,product_all t2 where t1.xcode=t2.prodl_id and excode='dl' group by t1.xcode,t2.prodl,t1.packetqty1 "
result=confsql.runquery(sqlstr)
html=t.render(Context({'result':result}))
return HttpResponse(html)
def delete_product_gl_packetqty_rules(request):
'删除配货规则'
if request.method=='POST':
value=request.POST['value']
rs1=trim_csv(value,itemlenth=4)
rs2,rs1=verifyData(rs1,length=4,required=[0,2,3],psrules=1)
html=u"<table width='800'><tr><th>代码</th><th>名称</th><th>代码说明</th><th>配货单位</th></tr>"
if len(rs2)>0:
for rs in rs2:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td style='background-color:yellow;'>" + rs[4] + "</td>"
html+="</tr>"
if len(rs1)>0:
for rs in rs1:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td></td>"
html+="</tr>"
html+="</table>"
return HttpResponse(html)
else:
t=get_template('mana1/delete_product_gl_packetqty_rules.html')
html=t.render(Context())
return HttpResponse(html)
def deleteData_product_gl_packetqty_rules(request):
'删除数据'
result=[]
myjson=simplejson.loads(request.POST["myjson"])
rs1=trim_csv(myjson["table"])
#log(rs1)
if len(rs1)>0:
for rs in rs1:
if rs[4]<>'': #出错信息的保留
res={}
res['xcode']=rs[0]
res['name']=rs[1]
res['excode']=rs[2]
res['packetqty1']=rs[3]
res['info']=rs[4]
result.append(res)
else:
try:
#sp, xl, zl, dl, null
excode=rs[2]
if rs[2]==u'商品代码':
excode='sp'
if rs[2]==u'小类代码':
excode='xl'
if rs[2]==u'中类代码':
excode=u'zl'
if rs[2]=='大类代码':
excode=u'dl'
#log("delete from product_gl_packetqty_rules where xcode='"+rs[0]+"' and excode='"+excode+"'")
confsql.runSql("delete from product_gl_packetqty_rules where xcode='"+rs[0]+"' and excode='"+excode+"'")
res={}
res['xcode']=rs[0]
res['name']=rs[1]
res['excode']=rs[2]
res['packetqty1']=rs[3]
res['info']=u'删除成功!'
result.append(res)
except:
res={}
res['xcode']=rs[0]
res['name']=rs[1]
res['excode']=rs[2]
res['packetqty1']=rs[3]
res['info']=u'删除失败!'
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
if __name__=='__main__':
import_product_gl_packetqty_rules()