def instant_order_deal(plat, special_product, clearance_goods, new_product_instant,orders):
"""
:param plat: 要计算的平台
:param special_product: 特定库龄产品,其他平台的,amazon的在下面单独读取
:param clearance_goods: 清仓产品
:param new_product: 新品
:param orders: 订单
:return:
"""
# 退款订单处理
orders['订单总金额(包含客户运费、平台补贴)'] = orders.apply(lambda x: 0 if (x['订单类型'] == 'refund') else x['订单总金额(包含客户运费、平台补贴)'], axis=1)
"中间特定sku处理毛利"
# orders['毛利'] = orders.apply(lambda x: (x['平均采购价']* 0.4 + x['毛利']) if (x['产品代码'] == 'S4338867210')| (x['产品代码']=='S2130010010') else x['毛利'],axis=1)
orders['毛利'] = orders.apply(lambda x: (x['毛利'] + 5) if (x['产品代码'] == 'S1416028410') | (x['产品代码'] == 'S1416028440') | (x['产品代码'] == 'S1416028470') else x['毛利'], axis=1)
"""折价商品毛利计算 + 额温枪"""
depreciate = read_data().read_depreciate()
orders['毛利'] = orders.apply(lambda x: (x['平均采购价'] * 0.4 * x['数量'] + x['毛利']) if (x['产品代码'] in depreciate) and x['订单类型'] == 'sale' else x['毛利'],axis=1)
orders['平均采购价'] = orders.apply(lambda x: 0 if (x['订单类型'] == 'resend') else x['平均采购价'], axis=1)
# 中英仓处理
orders['仓库分类'] = orders.apply(lambda x: '中仓' if (x['发运仓库'] =='SH [上海奉贤仓]') | (x['发运仓库'] =='WZC [温州仓]') | (x['发运仓库'] =='SZC [深圳仓]') else '海外仓', axis=1)
# 处理新品
# if plat == 'ebay' or plat == 'shopee' or plat == 'amazon' :
newproduct = read_data().read_newproduct()
orders['仓库分类'] = orders.apply(lambda x: '新品' if (x['产品代码'] in newproduct) else x['仓库分类'], axis=1)
#处理海运产品
shipping = read_data().read_shipping()
orders['仓库分类'] =orders.apply(lambda x: '海运产品' if(x['产品代码'] in shipping and x['仓库分类'] != '海外仓') else x['仓库分类'],axis=1)
# 当月转清仓处理
orders['仓库分类'] = orders.apply(lambda x: '特定库龄'if isClearance(x['付款时间'], x['产品代码'], clearance_goods) != None else x['仓库分类'], axis=1)
# 特定库龄处理
orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if (x['发运仓库'] == 'GSE [古斯美东仓]' and x['平台']!='ebay') else x['仓库分类'], axis=1)
if plat == 'amazon':
# amazon的特定库龄需要单独读取
special_product_a = read_data().read_special_product(plat)
special_product_as = read_data().read_special_product('amazon特殊')
orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if (x['产品代码'] in special_product_as) else x['仓库分类'], axis=1)
orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if ((x['发运仓库'] + x['产品代码']) in special_product_a) else x['仓库分类'], axis=1)
else:
special_product = read_data().read_special_product('其他平台')
orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if (x['产品代码'] in special_product) else x['仓库分类'], axis=1)
orders['仓库分类']=orders.apply(lambda x:'稳定期' if (x['仓库分类']=='中仓')| (x['仓库分类']=='海外仓' )else x['仓库分类'],axis=1 )
# 处理好仓库分类,接下来判断是否是开发新品
orders = pd.merge(orders, new_product_instant, on='产品代码', how='left')
orders['开发新品'] = orders['开发新品'].fillna('非开发新品')
# 然后处理货值
orders['货值'] = orders['数量'] * orders['平均采购价']
# orders = pd.merge(orders,mask_instant, on='产品代码', how='left')
# orders['口罩'] = orders['口罩'].fillna('非口罩')
return orders
Python-apply(lambda x: )使用
最新推荐文章于 2023-05-23 17:30:55 发布