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['毛利'] + 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)
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':
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['平均采购价']
return orders