def GET(self): if helper.logged(helper.PRIV_USER): render = helper.create_render() user_data = web.input(sku='') if user_data.sku == '': return render.info('错误的参数!') # 检查用户是否有此店权限 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2 == None: return render.info('未找到所属门店!') db_sku = db.sku_store.find_one({'_id': ObjectId(user_data.sku)}) if db_sku != None: base_sku = db.dereference(db_sku['base_sku']) return render.damage_sku( helper.get_session_uname(), helper.get_privilege_name(), db_sku, { 'name': base_sku['name'], 'original': base_sku['original'] }, helper.UNIT_TYPE, (str(db_shop2['_id']), db_shop2['name'], helper.SHOP_TYPE[db_shop2['type']]), helper.get_inventory(ObjectId(user_data.sku), db_shop['shop'])) else: return render.info('错误的参数!') else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'BATCH_JOB'): render = helper.create_render() user_data = web.input(tuan_id='', sheng='') # 查找shop db_shop = helper.get_shop_by_uid() shop_name = helper.get_shop(db_shop['shop']) # 统计线上订单 condition = { 'shop': db_shop['shop'], 'status': 'PAID', 'type': { '$in': ['TUAN', 'SINGLE'] }, # 目前只拼团用 'address.8': re.compile('^%s.*' % user_data.sheng.strip().encode('utf-8')) } db_sale2 = db.order_app.find( condition, { 'order_id': 1, 'paid_time': 1, 'cart': 1, 'type': 1, 'status': 1, 'address': 1, }).sort([('_id', 1)]) r = db.pt_store.find_one({'tuan_id': user_data['tuan_id']}, {'title': 1}) if r: title = r['title'] else: title = 'n/a' skus = [] count = 0 for i in db_sale2: if i['cart'][0]['tuan_id'] != user_data['tuan_id']: continue else: # 只记录知道活动的订单号 skus.append(i['order_id']) count += 1 if count == 100: # 一次只处理100个 break return render.batch_paid(helper.get_session_uname(), helper.get_privilege_name(), skus, len(skus), shop_name, user_data['tuan_id'], title, user_data['sheng']) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'BATCH_JOB'): render = helper.create_render() user_data = web.input(tuan_id='', status='', sheng='') # 查找shop db_shop = helper.get_shop_by_uid() shop_name = helper.get_shop(db_shop['shop']) # 统计线上订单 condition = { 'shop': db_shop['shop'], 'status': user_data['status'], 'type': { '$in': ['TUAN', 'SINGLE'] }, # 目前只拼团用 'address.8': re.compile('^%s.*' % user_data.sheng.strip().encode('utf-8')) } db_sale2 = db.order_app.find(condition, { 'order_id': 1, 'paid_time': 1, 'cart': 1, 'type': 1, 'status': 1 }) skus = [] title = '' for i in db_sale2: if i['cart'][0]['tuan_id'] != user_data['tuan_id']: continue else: # 只记录知道活动的订单号 skus.append(i['order_id']) title = i['cart'][0].get('title', 'n/a') return render.batch_list(helper.get_session_uname(), helper.get_privilege_name(), skus, len(skus), shop_name, user_data['tuan_id'], title, user_data['status'], user_data['sheng']) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'ONLINE_MAN'): render = helper.create_render() # 查找门店 db_shop = helper.get_shop_by_uid() shop_name = helper.get_shop(db_shop['shop']) if str(db_shop['shop']) in setting.PT_shop.values(): pt_shop = True else: pt_shop = False print 'pt_shop = ', pt_shop return render.online_man(helper.get_session_uname(), helper.get_privilege_name(), shop_name['name'], pt_shop) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'POS_PRINT_LABEL'): render = helper.create_render() #user_data=web.input(is_pack='1') # 查找 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2 == None: return render.info('未找到所属门店!') return render.pos_print_label(helper.get_session_uname(), helper.get_privilege_name(), db_shop2, helper.SHOP_TYPE) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER,'POS_POS'): render = helper.create_render(plain=True) #user_data=web.input(is_pack='1') # 查找 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2==None: return render.info('未找到所属门店!') #if db_shop2['type'] not in ['chain', 'store']: # render = helper.create_render() # return render.info('此站点不能线下销售!') return render.pos(helper.get_session_uname(), helper.get_privilege_name(), db_shop2, helper.SHOP_TYPE) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'POS_INVENTORY'): render = helper.create_render() user_data = web.input(product_id='') if user_data.product_id == '': return render.info('错误的参数!') # 查找shop db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2 == None: return render.info('未找到所属门店!') db_invent = db.inventory.find_one({ 'product_id': user_data.product_id, 'shop': db_shop2['_id'] }) if db_invent: db_sku = db.sku_store.find_one({'_id': db_invent['sku']}) if db_sku: base_sku = db.dereference(db_sku['base_sku']) return render.pos_invent_sku( helper.get_session_uname(), helper.get_privilege_name(), db_sku, db_invent, helper.UNIT_TYPE[db_sku['unit']], (base_sku['name'], base_sku['original'], base_sku['image'][0] if base_sku.has_key('image') and len(base_sku['image']) > 0 else ''), (str(db_shop2['_id']), db_shop2['name'], helper.SHOP_TYPE[db_shop2['type']]), user_data.product_id[0] == 'w', helper.CATEGORY) else: return render.info('未查到sku!') else: return render.info('未查到库存!') else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER): render = helper.create_render() # 查找 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2 == None: return render.info('未找到所属门店!') # 查找所属店铺库存 db_invent = db.inventory.find( { 'product_id': { '$not': re.compile('^w.*') }, 'shop': db_shop['shop'], }, { 'sku': 1, 'online': 1, 'price': 1, 'product_id': 1 }) invent = {} for s in db_invent: if s['product_id'][2] in ('1', '3'): # 只记录散进散出 continue invent[s['sku']] = (s['online'], s['price']) # 散装、有效的sku db_sku = db.sku_store.find( { '_id': { '$in': invent.keys() } }, { 'product_id': 1, 'base_sku': 1, 'note': 1, #'online' : 1, 'is_pack': 1, 'unit': 1, #'unit_num' : 1, #'ref_price' : 1, }).sort([('_id', 1)]) skus = [] for u in db_sku: base_sku = db.dereference(u['base_sku']) # 准备数据 skus.append(( u['_id'], base_sku['name'], u['note'], invent[u['_id']][0], base_sku['image'][0] if base_sku.has_key('image') and len(base_sku['image']) > 0 else '', '', helper.UNIT_TYPE[u['unit']], u['is_pack'], invent[u['_id']][1], u['product_id'], )) return render.weight(helper.get_session_uname(), helper.get_privilege_name(), skus, (str(db_shop2['_id']), db_shop2['name'], helper.SHOP_TYPE[db_shop2['type']])) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'POS_AUDIT'): render = helper.create_render() user_data = web.input(is_pack='k') is_pack = user_data['is_pack'] # 分3类: u-散称sku, k-包装sku,w-已称重sku if is_pack not in ('k', 'u', 'w'): return render.info('错误的参数!') # 查找 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2 == None: return render.info('未找到所属门店!') # 查找所属店铺库存 包装库存 # 模糊查询,以k开头 {'$regex':'k.*','$options': 'i'} condition = { 'shop': db_shop['shop'], 'product_id': { '$not': re.compile('^w.*') }, } # 称重sku忽略已售出的 num==0 if is_pack == 'w': condition['product_id'] = {'$regex': 'w.*', '$options': 'i'} condition['num'] = {'$ne': 0} # 查询db db_invent = db.inventory.find( condition, { 'sku': 1, 'online': 1, 'price': 1, 'weight': 1, 'total': 1, 'product_id': 1, 'num': 1, 'audit': 1, }).sort([('product_id', 1)]) invent = [] skus = [] for s in db_invent: skus.append(s['sku']) invent.append(( s['sku'], #0 s['online'], #1 s['price'], #2 s['weight'], #3 s['total'] if s.has_key('total') else '', #4 s['product_id'], #5 s['num'], #6 s['audit'], #7 )) # 包装的、有效的sku db_sku = db.sku_store.find( { '_id': { '$in': skus } }, { 'product_id': 1, 'base_sku': 1, #'note' : 1, #'online' : 1, 'is_pack': 1, 'unit': 1, 'app_title': 1, #'unit_num' : 1, 'ref_price': 1, }).sort([('_id', 1)]) skus = {} for u in db_sku: base_sku = db.dereference(u['base_sku']) skus[u['_id']] = ( base_sku['name'] if len(u['app_title'].strip()) == 0 else u['app_title'], #8 '', #9 helper.UNIT_TYPE[u['unit']], #10 u['is_pack'], #11 u['ref_price'], #12 ) data = [] for i in invent: # 准备数据 data.append(i + skus[i[0]]) return render.pos_audit_sku( helper.get_session_uname(), helper.get_privilege_name(), data, (str(db_shop2['_id']), db_shop2['name'], helper.SHOP_TYPE[db_shop2['type']]), is_pack) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER): render = helper.create_render() user_data=web.input() # 查找 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2==None: return render.info('未找到所属门店!') # 查找所属店铺库存 包装库存 # 模糊查询,以k开头 {'$regex':'k.*','$options': 'i'} condition = { 'shop' : db_shop['shop'], 'product_id' : { '$not': re.compile('^w.*') }, } db_invent = db.inventory.find(condition, { 'sku' : 1, 'online' : 1, #'price' : 1, #'cost_price' : 1, #'weight' : 1, #'total' : 1, 'product_id' : 1, 'num' : 1 }).sort([('product_id',1)]) invent = [] skus = [] for s in db_invent: skus.append(s['sku']) invent.append(( s['sku'], #0 s['online'], #1 #(s['price'], s['cost_price']), #s['weight'], #s['total'] if s.has_key('total') else '', s['product_id'], #2 s['num'], #3 )) # 包装的、有效的sku db_sku=db.sku_store.find({'_id':{'$in':skus}} ,{ 'product_id' : 1, 'base_sku' : 1, #'note' : 1, #'online' : 1, 'is_pack' : 1, 'unit' : 1, #'unit_num' : 1, #'ref_price' : 1, 'app_title' : 1, 'ref_cost' : 1 }).sort([('_id',1)]) skus = {} for u in db_sku: base_sku = db.dereference(u['base_sku']) skus[u['_id']]=( base_sku['name'] if len(u['app_title'].strip())==0 else u['app_title'], #4 #u['note'], # #base_sku['image'][0] if base_sku.has_key('image') and len(base_sku['image'])>0 else '', #'', # helper.UNIT_TYPE[u['unit']], #5 u['is_pack'], #6 u['ref_cost'], #7 base_sku['original'], #8 ) data = [] for i in invent: # 准备数据 data.append(i + skus[i[0]]) return render.pos_order_new2(helper.get_session_uname(), helper.get_privilege_name(), data, (str(db_shop2['_id']), db_shop2['name'], helper.SHOP_TYPE[db_shop2['type']])) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'BATCH_JOB'): render = helper.create_render() #user_data=web.input(start_date='', shop='__ALL__') # 查找shop db_shop = helper.get_shop_by_uid() shop_name = helper.get_shop(db_shop['shop']) # 统计线上订单 condition = { 'shop': db_shop['shop'], 'status': { '$in': ['PAID', 'DISPATCH', 'ONROAD'] }, 'type': { '$in': ['TUAN', 'SINGLE'] }, # 只拼团用 } db_sale2 = db.order_app.find( condition, { 'order_id': 1, 'paid_time': 1, 'cart': 1, 'type': 1, 'status': 1, 'address': 1, }) skus = {} for i in db_sale2: # 区分省份 sheng = i['address'][8].split(',')[0] if len( i['address']) >= 9 else u'未知' if skus.has_key(i['cart'][0]['tuan_id']): if skus[i['cart'][0]['tuan_id']].has_key(sheng): skus[i['cart'][0]['tuan_id']][sheng]['num'] += 1 skus[i['cart'][0]['tuan_id']][sheng]['paid'] += ( 1 if i['status'] == 'PAID' else 0) skus[i['cart'][0]['tuan_id']][sheng]['dispatch'] += ( 1 if i['status'] == 'DISPATCH' else 0) skus[i['cart'][0]['tuan_id']][sheng]['onroad'] += ( 1 if i['status'] == 'ONROAD' else 0) else: skus[i['cart'][0]['tuan_id']][sheng] = {} skus[i['cart'][0]['tuan_id']][sheng]['num'] = 1 skus[i['cart'][0]['tuan_id']][sheng]['paid'] = ( 1 if i['status'] == 'PAID' else 0) skus[i['cart'][0]['tuan_id']][sheng]['dispatch'] = ( 1 if i['status'] == 'DISPATCH' else 0) skus[i['cart'][0]['tuan_id']][sheng]['onroad'] = ( 1 if i['status'] == 'ONROAD' else 0) else: r = db.pt_store.find_one( {'tuan_id': i['cart'][0]['tuan_id']}, {'title': 1}) if r: title = r['title'] else: title = 'n/a' skus[i['cart'][0]['tuan_id']] = { 'name': title, 'tuan_id': i['cart'][0]['tuan_id'], } skus[i['cart'][0]['tuan_id']][sheng] = { 'num': 1, # 要包含送的 'paid': 1 if i['status'] == 'PAID' else 0, # 已付款,待拣货的, 拼团用 'dispatch': 1 if i['status'] == 'DISPATCH' else 0, # 已付款,待配送, 拼团用 'onroad': 1 if i['status'] == 'ONROAD' else 0, # 已付款,配送中, 拼团用 } total_sum = {} for i in skus.keys(): for j in skus[i].keys(): if j in ['name', 'tuan_id']: continue if total_sum.has_key(j): total_sum[j]['paid'] += skus[i][j]['paid'] total_sum[j]['dispatch'] += skus[i][j]['dispatch'] total_sum[j]['onroad'] += skus[i][j]['onroad'] else: total_sum[j] = {} total_sum[j]['paid'] = skus[i][j]['paid'] total_sum[j]['dispatch'] = skus[i][j]['dispatch'] total_sum[j]['onroad'] = skus[i][j]['onroad'] return render.batch_job(helper.get_session_uname(), helper.get_privilege_name(), skus, shop_name['name'], total_sum) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'REPORT_REPORT1'): render = helper.create_render() user_data = web.input(start_date='', shop='__ALL__', ret_type='table') if user_data['start_date'] == '': db_shop = db.base_shop.find( {'type': { '$in': ['chain', 'store', 'dark', 'counter'] }}, {'name': 1}) return render.report_report1(helper.get_session_uname(), helper.get_privilege_name(), db_shop) # 查找shop #db_shop = helper.get_shop_by_uid() # 起至时间 begin_date = '%s 00:00:00' % user_data['start_date'] end_date = '%s 23:59:59' % user_data['start_date'] #print begin_date, end_date, db_shop['_id'] condition = { 'status': { '$nin': [ 'CANCEL', 'TIMEOUT', 'DUE', 'FAIL', 'REFUND', 'CANCEL1', 'CANCEL2', 'CANCEL3', 'CANCEL4', 'CANCEL_TO_REFUND', 'FAIL_TO_REFUND' ] }, '$and': [{ 'paid_time': { '$gt': begin_date } }, { 'paid_time': { '$lt': end_date } }], } if user_data['shop'] != '__ALL__': condition['shop'] = ObjectId(user_data['shop']) db_shop = helper.get_shop(condition['shop']) shop_name = db_shop['name'] else: shop_name = '全部门店' # 统计线下订单 db_sale = db.order_app.find( condition, { 'order_id': 1, 'shop': 1, 'paid_time': 1, 'uname': 1, 'due': 1, 'address': 1, 'first_disc': 1 }) print db_sale.count() orders = [] app_cnt = 0 app_new = 0 app_money = 0.0 wx_cnt = 0 wx_new = 0 wx_money = 0.0 new_unames = {} for i in db_sale: db_shop = helper.get_shop(i['shop']) if not new_unames.has_key(i['uname']): db_user = db.app_user.find_one( { '$or': [ { 'uname': i['uname'] }, { 'openid': i['uname'] } # 2015-10-25 ] }, {'reg_time': 1}) if db_user != None and db_user[ 'reg_time'] >= begin_date and db_user[ 'reg_time'] <= end_date: new_unames[i['uname']] = 1 else: new_unames[i['uname']] = 0 else: print '命中缓存' new_user = new_unames[i['uname']] if len(i['uname']) > 15: wx_cnt += 1 wx_new += new_user wx_money += float(i['due']) else: app_cnt += 1 app_new += new_user app_money += float(i['due']) orders.append(( db_shop['name'], # 0 i['order_id'], # 1 i['paid_time'], # 2 u'微信' if len(i['uname']) > 15 else i['uname'], # 3 i['due'], # 4 i['address'][1], # 5 i['address'][2], # 6 i['address'][3], # 7 str(new_user), # 8 )) if user_data.ret_type == 'table': return render.report_report1_r(helper.get_session_uname(), helper.get_privilege_name(), orders, user_data.start_date, (app_cnt, wx_cnt), (app_new, wx_new), (app_money, wx_money), shop_name) else: # 返回csv格式文本 ret_txt = u'站点名称,订单编号,付款时间,下单手机号,付款金额,收货姓名,收货电话,收货地址,是否新客' + '\n' for i in orders: ret_txt = ret_txt + ','.join(i) + '\n' web.header('Content-Type', 'text/plain; charset=utf-8') web.header("Content-Description", "File Transfer") web.header('Content-Disposition', 'attachment; filename="report.csv"') web.header("Content-Transfer-Encoding", "binary") web.header("Content-Length", "%d" % len(ret_txt)) return ret_txt else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'POS_INVENTORY'): render = helper.create_render() user_data = web.input(is_pack='k', show='1') is_pack = user_data['is_pack'] # 分3类: u-散称sku, k-包装sku,w-已称重sku if is_pack not in ('k', 'u', 'w'): return render.info('错误的参数!') # 查找 db_shop = helper.get_shop_by_uid() # 查找店面信息 db_shop2 = helper.get_shop(db_shop['shop']) if db_shop2 == None: return render.info('未找到所属门店!') # 查找所属店铺库存 包装库存 # 模糊查询,以k开头 {'$regex':'k.*','$options': 'i'} condition = { 'shop': db_shop['shop'], 'product_id': { '$not': re.compile('^w.*') }, } if is_pack == 'w': condition['product_id'] = {'$regex': 'w.*', '$options': 'i'} if user_data.show == '1': # 显示有库存的 condition['num'] = {'$gt': 0} else: # 显示已售出的 condition['num'] = {'$lte': 0} db_invent = db.inventory.find( condition, { 'sku': 1, 'online': 1, 'list_in_app': 1, 'category': 1, 'price': 1, 'cost_price': 1, 'weight': 1, 'total': 1, 'product_id': 1, 'num': 1, 'pre_pay_num': 1, }).sort([('product_id', 1)]) invent = [] skus = [] for s in db_invent: skus.append(s['sku']) invent.append(( s['sku'], #0 (s['online'], s.get('list_in_app', 0), s.get('category', '001')), #1 (s['price'], s['cost_price']), #2 s['weight'], #3 s.get('total', ''), #4 s['product_id'], #5 (s['num'], s.get('pre_pay_num', 0)), #6 )) # 包装的、有效的sku db_sku = db.sku_store.find( { '_id': { '$in': skus } }, { 'product_id': 1, 'base_sku': 1, 'note': 1, #'online' : 1, 'is_pack': 1, 'unit': 1, #'unit_num' : 1, 'ref_price': 1, 'app_title': 1 }).sort([('_id', 1)]) skus = {} for u in db_sku: base_sku = db.dereference(u['base_sku']) skus[u['_id']] = ( base_sku['name'] if len( u['app_title'].strip()) == 0 else u['app_title'], #7 u['note'], #8 base_sku['image'][0] if base_sku.has_key('image') and len(base_sku['image']) > 0 else '', '', #10 helper.UNIT_TYPE[u['unit']], #11 u['is_pack'], #12 u['ref_price'], #13 base_sku['original'], #14 ) data = [] for i in invent: # 准备数据 data.append(i + skus[i[0]]) return render.pos_invent(helper.get_session_uname(), helper.get_privilege_name(), data, (str(db_shop2['_id']), db_shop2['name'], helper.SHOP_TYPE[db_shop2['type']]), is_pack, helper.CATEGORY, user_data.show) else: raise web.seeother('/')
def GET(self): if helper.logged(helper.PRIV_USER, 'REPORT_REPORT2'): render = helper.create_render() user_data = web.input(start_date='', shop='__ALL__') if user_data['start_date'] == '': db_shop = db.base_shop.find( {'type': { '$in': ['chain', 'store', 'dark', 'counter'] }}, {'name': 1}) return render.report_report2(helper.get_session_uname(), helper.get_privilege_name(), db_shop) # 查找shop #db_shop = helper.get_shop_by_uid() # 起至时间 begin_date = '%s 00:00:00' % user_data['start_date'] end_date = '%s 23:59:59' % user_data['start_date'] condition = { #'shop' : db_shop['shop'], 'status': 'PAID', #'type' : {'$nin': ['TUAN', 'SINGLE']}, '$and': [{ 'paid_time': { '$gt': begin_date } }, { 'paid_time': { '$lt': end_date } }], } if user_data['shop'] != '__ALL__': condition['shop'] = ObjectId(user_data['shop']) db_shop = helper.get_shop(condition['shop']) shop_name = db_shop['name'] else: shop_name = '全部门店' shop_type = {} db_shop_type = db.base_shop.find({}, {'type': 1}) for s in db_shop_type: shop_type[s['_id']] = s['type'] # 统计线下订单 db_sale = db.order_offline.find( condition, { 'order_id': 1, 'due': 1, 'pay': 1, 'change': 1, 'paid_time': 1, 'cart': 1, 'type': 1 }) skus = {} total = 0.0 count = 0 for i in db_sale: #ttt = 0.0 for j in i['cart']: #ttt += float(j['price']) if skus.has_key(j['product_id']): skus[j['product_id']]['offline']['cost'] += float( j['cost']) skus[j['product_id']]['offline']['price'] += float( j['price']) skus[j['product_id']]['offline']['num'] += float( j['num']) else: skus[j['product_id']] = { 'offline': { 'cost': float(j.get('cost', '0.00')), 'price': float(j['price']), 'num': float(j['num']), }, 'online': { 'cost': 0.0, 'price': 0.0, 'num': 0.0, 'paid': 0.0, }, 'name': j['name'], } #print i['due'], ttt total += float(i['due']) count += 1 # 统计线上订单 condition['status'] = { '$nin': [ 'CANCEL', 'TIMEOUT', 'DUE', 'FAIL', 'REFUND', 'CANCEL1', 'CANCEL2', 'CANCEL3', 'CANCEL4', 'FAIL_TO_REFUND', 'CANCEL_TO_REFUND', 'PAID_AND_WAIT' ] } db_sale2 = db.order_app.find( condition, { 'order_id': 1, 'due': 1, 'total': 1, 'pay': 1, 'paid_time': 1, 'cart': 1, 'shop': 1, 'type': 1, 'status': 1, 'delivery_fee': 1 }) total3_dark = 0.0 total4_dark = 0.0 count3_dark = 0 total3 = 0.0 total4 = 0.0 count3 = 0 for i in db_sale2: if i.get('type') in ['TUAN', 'SINGLE']: # 拼团订单 if skus.has_key(i['cart'][0]['tuan_id']): skus[i['cart'][0]['tuan_id']]['online']['cost'] = 0.0 skus[i['cart'][0] ['tuan_id']]['online']['price'] += float(i['due']) skus[i['cart'][0]['tuan_id']]['online']['num'] += 1 skus[i['cart'][0]['tuan_id']]['online']['paid'] += ( 1 if i['status'] == 'PAID' else 0) skus[i['cart'][0] ['tuan_id']]['online']['dispatch'] += ( 1 if i['status'] == 'DISPATCH' else 0) skus[i['cart'][0]['tuan_id']]['online']['onroad'] += ( 1 if i['status'] == 'ONROAD' else 0) else: skus[i['cart'][0]['tuan_id']] = { 'online': { 'cost': 0.0, 'price': float(i['due']), 'num': 1, # 要包含送的 'paid': 1 if i['status'] == 'PAID' else 0, # 已付款,待拣货的, 拼团用 'dispatch': 1 if i['status'] == 'DISPATCH' else 0, # 已付款,待配送, 拼团用 'onroad': 1 if i['status'] == 'ONROAD' else 0, # 已付款,配送中, 拼团用 }, 'offline': { 'cost': 0.0, 'price': 0.0, 'num': 0.0, }, 'name': i['cart'][0].get('title', 'n/a'), } else: # 普通订单 for j in i['cart']: if skus.has_key(j['product_id']): skus[j['product_id']]['online']['cost'] += float( j.get('cost', '0.00')) skus[j['product_id']]['online']['price'] += float( j['price']) # 要包含送的 skus[j['product_id']]['online']['num'] += ( float(j['num2']) + float(j.get('numyy', '0.00'))) else: skus[j['product_id']] = { 'online': { 'cost': float(j.get('cost', '0.00')), 'price': float(j['price']), 'num': float(j['num2']) + float(j.get('numyy', '0.00')), # 要包含送的 'paid': 0, # 普通订单不用这字段 'dispatch': 0, # 普通订单不用这字段 'onroad': 0, # 普通订单不用这字段 }, 'offline': { 'cost': 0.0, 'price': 0.0, 'num': 0.0, }, 'name': j['title'], } if shop_type[i['shop']] == 'dark': # 暗店 total3_dark += float(i['due']) total4_dark += (float(i['total']) + float(i['delivery_fee'])) count3_dark += 1 else: # 明店 total3 += float(i['due']) total4 += float(i['total']) count3 += 1 # 统计退货 condition2 = { #'shop' : db_shop['shop'], '$and': [{ 'return_time': { '$gt': begin_date } }, { 'return_time': { '$lt': end_date } }], } if condition.has_key('shop'): condition2['shop'] = condition['shop'] db_return = db.order_return.find(condition2, { 'product_id': 1, 'total': 1, 'return_time': 1 }) # 退货单流水 total2 = 0.0 count2 = 0 for i in db_return: count2 += 1 total2 += float(i['total']) #print 'test', total3_dark, total4_dark return render.report_report2_r( helper.get_session_uname(), helper.get_privilege_name(), skus, len(skus), ( '%.2f' % total4_dark, '%.2f' % (total4_dark - total3_dark), '%.2f' % total3_dark, # 线上暗店 '%.2f' % total4, '%.2f' % (total4 - total3), '%.2f' % total3), # 线上明店 ('%.2f' % total, '%.2f' % total2, '%.2f' % (total - total2)), # 线下 (count3, count, count2, count3_dark), user_data.start_date, shop_name, user_data['shop'] in setting.PT_shop.values()) else: raise web.seeother('/')