-
Notifications
You must be signed in to change notification settings - Fork 0
/
sugvalue.py
212 lines (118 loc) · 5.47 KB
/
sugvalue.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
# -*- coding: utf-8 -*-
'''
#=============================================================================
# FileName: sugvalue.py
# Desc: 配送相关
# Author: solomon
# Email: [email protected]
# HomePage:
# Version: 0.0.1
# LastChange: 2012-10-24 14:21:51
# History:
#=============================================================================
'''
import confsql,datetime,memcache
from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
from django.utils import simplejson
from mylog import log
from functions import trim_csv,verifyData
confsql=confsql.Confsql()
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
def insult_sugvalue(request):
''' 建议值查询界面 '''
result=[] #存放初始表头
if request.method=='POST':
jlist=simplejson.loads(request.POST["jsonlist"])
ty=request.POST["ty"]
if ty=="sub": #非聚集
if jlist['spcode']<>'' or jlist['spname']<>'' or jlist['mdcode']<>'' or jlist['mdname']<>'': #不全为空
sqlstr="select mdcode, mdname, spcode, spname, suggest, suggestcost from dhalldata where assortment is not null and status < '5' and suggest > 0 and shelf > '-1' and dhtag='T' and delivery = 'T' and "
for j in jlist:
if jlist[j]<>'':
li=jlist[j].split(",")
if len(li)==1:
sqlstr+=j+" like '%%"+jlist[j].strip()+"%%' and "
else:
sqlstr+="("
for l in li:
sqlstr+=j+" like '%%"+l.strip() +"%%' or "
sqlstr=sqlstr[0:-4]+") and "
sqlstr=sqlstr[0:-4] #去除最后多余的and
#sqlstr += " suggest>0 "
lines=confsql.runquery(sqlstr)
for rs in lines:
res={}
res['门店代码']=rs[0]
res['门店名称']=rs[1]
res['商品代码']=rs[2]
res['商品名称']=rs[3]
res['建议配货量']=rs[4]
res['配货总金额']=rs[5]
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
else:
#sqlstr='select * from sugvalue'
sqlstr= "select mdcode, mdname, spcode, spname, suggest, suggestcost from dhalldata where assortment is not null and status < '5' and suggest > 0 and shelf > '-1' and dhtag='T' and delivery = 'T'"
lines=confsql.runquery(sqlstr)
for rs in lines:
res={}
res['门店代码']=rs[0]
res['门店名称']=rs[1]
res['商品代码']=rs[2]
res['商品名称']=rs[3]
res['建议配货量']=rs[4]
res['配货总金额']=rs[5]
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
else: #聚集结果
if jlist['spcode']<>'' or jlist['spname']<>'' or jlist['mdcode']<>'' or jlist['mdname']<>'': #不全为空
items=""
dic={'spcode':'商品代码','spname':'商品名称','mdcode':'门店代码','mdname':'门店名称'}
for j in jlist:
if jlist[j]<>'':
items+=j+","
items=items[0:-1]
sqlstr="select "+items+", sum(suggest) as suggest,sum(suggestcost) as suggestcost from dhalldata where assortment is not null and status < '5' and suggest > 0 and shelf > '-1' and dhtag='T' and "
for j in jlist:
if jlist[j]<>'':
sqlstr+=j+" like '%%"+jlist[j].strip() +"%%' and "
sqlstr=sqlstr[0:-4] #去除最后多余的and
#sqlstr += " suggest>0 "
sqlstr+="group by "+items
lines=confsql.runquery(sqlstr)
for rs in lines:
i=0
res={}
for j in jlist:
if jlist[j]<>'':
res={}
res[dic[j]]=rs[i]
i+=1
res['建议配货量']=rs[i]
res['配货总金额']=rs[i+1]
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
else:
#sqlstr='select * from sugvalue'
sqlstr='select * from sugvalue where suggest>0 '
lines=confsql.runquery(sqlstr)
for rs in lines:
res={}
res['门店代码']=rs[0]
res['门店名称']=rs[1]
res['商品代码']=rs[2]
res['商品名称']=rs[3]
res['建议配货量']=rs[4]
res['配货总金额']=rs[5]
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
else:
t=get_template('mana1/insult_sugvalue.html')
html=t.render(Context({'result':result}))
return HttpResponse(html)