176 lines
7.8 KiB
Plaintext
176 lines
7.8 KiB
Plaintext
async def productAdd(ns={}):
|
|
"""
|
|
add new product
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
if ns.get('sor'):
|
|
sor = ns.get('sor')
|
|
nss = {
|
|
'id': uuid(),
|
|
'providerid': ns.get('providerid') or '',
|
|
'providerpid': ns.get('providerpid') or '',
|
|
'name': ns.get('name') or '',
|
|
'description': ns.get('description') or '',
|
|
'ptype': ns.get('ptype') or '',
|
|
'state': ns.get('state') or '',
|
|
# 'effect_date': ns.get('start_date') or '',
|
|
# 'expire_date': ns.get('end_date') or '',
|
|
'salemode': ns.get('salemode') or '',
|
|
'product_code': ns.get('product_code') or '',
|
|
'spec_note': ns.get('spec_note') or '',
|
|
'product_area': ns.get('product_area') or '',
|
|
'specific_pattern': ns.get('specific_pattern') or '',
|
|
'reseller_orgid': ns.get('reseller_orgid') or '',
|
|
'classify': ns.get('classify'),
|
|
'productgroup': ns.get('productgroup'),
|
|
'label': ns.get('label')
|
|
}
|
|
nss_product_salemode = {
|
|
'id': uuid(),
|
|
'protocolid': ns.get('protocolid'),
|
|
'providerid': ns.get('providerid'),
|
|
'productid': nss['id'],
|
|
'discount': ns.get('discount'),
|
|
'price': ns.get('floorprice'),
|
|
'unit': ns.get('unit')
|
|
}
|
|
nss_product_salemode_copy = {
|
|
'id': uuid(),
|
|
'protocolid': ns.get('protocolid'),
|
|
'providerid': ns.get('providerid'),
|
|
'productid': '*',
|
|
'discount': ns.get('discount'),
|
|
'price': ns.get('floorprice'),
|
|
'unit': ns.get('unit')
|
|
}
|
|
# if not ns.get('effect_date'):
|
|
# return {
|
|
# "status": False,
|
|
# "message": "product effect date is empty"
|
|
# }
|
|
#
|
|
# if not ns.get('expire_date'):
|
|
# nss['expire_date'] = "9999-12-31"
|
|
try:
|
|
# 添加产品 如果有底价 触发插入底价表, 同时插入两条数据
|
|
# 1. 买方售方都设置则为底价 2.售方为本机构 买方为空则为售价
|
|
if ns.get('selling') and ns.get('floorprice'):
|
|
if int(ns.get('selling')) <= int(ns.get('floorprice')):
|
|
return {
|
|
'status': False,
|
|
'msg': '售价不能低于底价'
|
|
}
|
|
ns_floor = {
|
|
'id': uuid(),
|
|
'offer_orgid': ns.get('providerid'),
|
|
'bid_orgid': ns.get('reseller_orgid'),
|
|
'productid': nss.get('id'),
|
|
'price': ns.get('floorprice'),
|
|
'begin_date': ns.get('effect_date'),
|
|
'end_date': '9999-12-31'
|
|
}
|
|
ns_selling = {
|
|
'id': uuid(),
|
|
'offer_orgid': ns.get('reseller_orgid'),
|
|
'bid_orgid': '',
|
|
'productid': nss.get('id'),
|
|
'price': ns.get('selling'),
|
|
'begin_date': ns.get('effect_date'),
|
|
'end_date': '9999-12-31'
|
|
}
|
|
await sor.C('floorprice', ns_floor)
|
|
await sor.C('floorprice', ns_selling)
|
|
if ns.get('protocolid'):
|
|
# 获取供应商名称 用于筛选中金设置映射产品
|
|
provider_name_li = await sor.R('organization', {'id': ns.get('providerid')})
|
|
provider_name = provider_name_li[0]['orgname']
|
|
|
|
# 获取协议起始时间
|
|
time_line_li = await sor.R('saleprotocol', {'id': ns.get('protocolid'), 'del_flg': '0'})
|
|
start_time = time_line_li[0]['start_date']
|
|
end_time = time_line_li[0]['end_date']
|
|
nss['effect_date'] = start_time
|
|
nss['expire_date'] = end_time
|
|
nss['salemode'] = time_line_li[0]['salemode']
|
|
|
|
# 检查产品表是否已经存在
|
|
ns_exist = {
|
|
'providerid': ns.get('providerid'),
|
|
'name': ns.get('name'),
|
|
'del_flg': '0'
|
|
}
|
|
product_exist_li = await sor.R('product', ns_exist)
|
|
# 如果已经存在就更新
|
|
if product_exist_li:
|
|
product_table_exits_id = product_exist_li[0]['id']
|
|
nss['id'] = product_table_exits_id
|
|
await sor.U('product', nss)
|
|
# 此时默认协议子表已经存在并更新
|
|
# 查找协议子表id 用于更新
|
|
exists_zibiao = {
|
|
'protocolid': ns.get('protocolid'),
|
|
'providerid': ns.get('providerid'),
|
|
'productid': nss['id']
|
|
}
|
|
exists_zibiao_li = await sor.R('product_salemode', exists_zibiao)
|
|
if exists_zibiao_li:
|
|
zibiao_id = exists_zibiao_li[0]['id']
|
|
nss_product_salemode['id'] = zibiao_id
|
|
nss_product_salemode['productid'] = nss['id']
|
|
if provider_name == '中金超算':
|
|
await sor.U('product_salemode', nss_product_salemode_copy)
|
|
await sor.U('product_salemode', nss_product_salemode)
|
|
else:
|
|
await sor.C('product', nss)
|
|
# 如果时中金协议子表创建两个 一个productid正常用于展示 一个productid为*
|
|
if provider_name == '中金超算':
|
|
zj_offer_yezhu_bind_exist = {
|
|
'protocolid': ns.get('protocolid'),
|
|
'providerid': ns.get('providerid'),
|
|
'productid': '*',
|
|
'del_flg': '0'
|
|
}
|
|
# 如果中金offer bind业主机构 已经配置过* 更新
|
|
zj_exist_li = await sor.R('product_salemode', zj_offer_yezhu_bind_exist)
|
|
if zj_exist_li:
|
|
nss_product_salemode_copy['id'] = zj_exist_li[0]['id']
|
|
await sor.U('product_salemode', nss_product_salemode_copy)
|
|
else:
|
|
await sor.C('product_salemode', nss_product_salemode_copy)
|
|
await sor.C('product_salemode', nss_product_salemode)
|
|
|
|
# 如果是批量添加 salemode=1就是添加产品 不添加统一客户配置
|
|
if ns.get('batch'):
|
|
ns_batch_dic = {
|
|
'bid_orgid': nss['reseller_orgid'],
|
|
'providerid': nss['providerid'],
|
|
'productid': nss['id'],
|
|
'sor': sor
|
|
}
|
|
if ns.get('salemode') == '0':
|
|
ns_batch_dic['discount'] = ns.get('kehu_discount')
|
|
await discount_guanli_jia(ns_batch_dic)
|
|
elif ns.get('salemode') == '2':
|
|
ns_batch_dic['price'] = ns.get('kehu_price')
|
|
await price_guanli_jia(ns_batch_dic)
|
|
else:
|
|
if ns.get('classify') == 'E':
|
|
nss['hotshow'] = '0'
|
|
await sor.C('product',nss)
|
|
return {
|
|
"status": True,
|
|
"msg": "product add success",
|
|
}
|
|
except Exception as e:
|
|
raise ValueError('产品添加失败: %s' % e)
|
|
return {
|
|
"status": False,
|
|
"msg": "product add failed"
|
|
}
|
|
|
|
|
|
ret = await productAdd(params_kw)
|
|
return ret |