async def xiaoshou_gai_zhekou_dijia_detail(ns={}): """ 销售修改折扣底价 :return: """ productid = ns.get('productid') db = DBPools() async with db.sqlorContext('kboss') as sor: try: if not ns.get('providerid'): ns['providerid'] = (await sor.R('product', {'id': productid}))[0]['providerid'] # 折扣底价不能低于供应商 # 按产品倒查who is provider if ns.get('discount'): dp_salemode = '0' who_is_provider_sql = """SELECT offer_orgid FROM saleprotocol WHERE bid_orgid = '%s' AND salemode in ('0', '1') and del_flg = '0' and id in (SELECT protocolid FROM product_salemode WHERE providerid = '%s' and productid = '%s');""" % (ns.get('offer_orgid'), ns.get('providerid'), ns.get('productid')) elif ns.get('price'): dp_salemode = '2' who_is_provider_sql = """SELECT offer_orgid FROM saleprotocol WHERE bid_orgid = '%s' AND salemode = '2' and del_flg = '0' and id in (SELECT protocolid FROM product_salemode WHERE providerid = '%s' and productid = '%s');""" % (ns.get('offer_orgid'), ns.get('providerid'), ns.get('productid')) else: return { 'status': False, 'msg': '没有获取到折扣或者底价信息' } who_is_provider = (await sor.sqlExe(who_is_provider_sql, {}))[0]['offer_orgid'] # 查找供应商协议id ns_provider_discount = { 'offer_orgid': who_is_provider, 'bid_orgid': ns.get('offer_orgid'), 'salemode': dp_salemode, 'del_flg': '0' } provider_protocol_id_li = (await sor.R('saleprotocol', ns_provider_discount)) # 可能是回佣设置折扣 if provider_protocol_id_li: provider_protocol_id = provider_protocol_id_li[0]['id'] else: provider_protocol_id = 0 # 查找供应商给的 # if provider_protocol_id: # provider_dp_find = { # 'protocolid': provider_protocol_id, # 'providerid': ns.get('providerid'), # 'productid': ns.get('productid'), # 'del_flg': '0' # } # if ns.get('price'): # provider_price = (await sor.R('product_salemode', provider_dp_find))[0]['price'] # if not provider_price: # return { # 'status': False, # 'msg': '获取不到供应商的底价' # } # if float(provider_price) >= float(ns.get('price')): # return { # 'status': False, # 'msg': '客户售价不能低于供应商底价' # } # else: # provider_discount_li = await sor.R('product_salemode', provider_dp_find) # # 回佣产品添加折扣时 没有上级折扣 # if provider_discount_li: # provider_discount = provider_discount_li[0]['discount'] # if float(provider_discount) >= float(ns.get('discount')): # return { # 'status': False, # 'msg': '客户折扣不能低于供应商折扣' # } # 首先查找offer和bid是否已经存在 ns_offer_bid = { 'offer_orgid': ns.get('offer_orgid'), 'bid_orgid': ns.get('bid_orgid'), 'del_flg': '0' } if ns.get('discount'): ns_offer_bid['salemode'] = '0' elif ns.get('price'): ns_offer_bid['salemode'] = '2' else: ns_offer_bid['salemode'] = '1' res_offer_bid_li = await sor.R('saleprotocol', ns_offer_bid) # 如果给客户的单独配置已经存在 if res_offer_bid_li: protocolid = res_offer_bid_li[0]['id'] ns_zibiao = { 'protocolid': protocolid, 'del_flg': '0' } zibiao_cha_li = await sor.R('product_salemode', ns_zibiao) zibiao_ids = [item.get('productid') for item in zibiao_cha_li if item] if productid in zibiao_ids: for prd in zibiao_cha_li: prd_id = prd['productid'] if prd_id == productid: # 获取子表id更新 ns_zibiao_up = { 'id': prd['id'], # 'discount': ns.get('discount') } if ns.get('discount'): ns_zibiao_up['discount'] = ns.get('discount') elif ns.get('price'): ns_zibiao_up['price'] = ns.get('price') await sor.U('product_salemode', ns_zibiao_up) # if ns.get('end_date'): # ns_up_end_date = { # 'id': protocolid, # 'end_date': ns.get('end_date') # } # await sor.U('saleprotocol', ns_up_end_date) else: # 产品是以*的形式展示 ns_zibiao_c = { 'id': uuid(), 'protocolid': protocolid, 'providerid': ns.get('providerid'), 'productid': ns.get('productid'), # 'discount': ns.get('discount') } if ns.get('discount'): ns_zibiao_c['discount'] = ns.get('discount') elif ns.get('price'): ns_zibiao_c['price'] = ns.get('price') await sor.C('product_salemode', ns_zibiao_c) # if ns.get('end_date'): # ns_up_end_date = { # 'id': protocolid, # 'end_date': ns.get('end_date') # } # await sor.U('saleprotocol', ns_up_end_date) else: # 获取*的start_date和end_date ns_date_get = { 'offer_orgid': ns.get('offer_orgid'), 'bid_orgid': '*', # 'salemode': '0', 'del_flg': '0' } if ns.get('discount'): ns_date_get['salemode'] = '0' elif ns.get('price'): ns_date_get['salemode'] = '2' else: ns_date_get['salemode'] = '1' # res_date_li = await sor.R('saleprotocol', ns_date_get) # if res_date_li: # start_date, end_date = res_date_li[0]['start_date'], res_date_li[0]['end_date'] # else: start_date, end_date = time.strftime('%Y-%m-%d %H:%M:%S'), '2099-12-31' ns_new_saleprotocol = { 'id': uuid(), 'offer_orgid': ns.get('offer_orgid'), 'bid_orgid': ns.get('bid_orgid'), 'salemode': '0', 'start_date': start_date, 'end_date': end_date } if ns.get('discount'): ns_new_saleprotocol['salemode'] = '0' elif ns.get('price'): ns_new_saleprotocol['salemode'] = '2' else: ns_new_saleprotocol['salemode'] = '1' await sor.C('saleprotocol', ns_new_saleprotocol) ns_new_product_salemode = { 'id': uuid(), 'protocolid': ns_new_saleprotocol['id'], 'providerid': ns.get('providerid'), 'productid': ns.get('productid'), # 'discount': ns.get('discount') } if ns.get('discount'): ns_new_product_salemode['discount'] = ns.get('discount') elif ns.get('price'): ns_new_product_salemode['price'] = ns.get('price') await sor.C('product_salemode', ns_new_product_salemode) return { 'status': True, 'msg': '修改折扣底价信息成功' } except Exception as e: raise e return { 'status': False, 'msg': '修改折扣底价信息失败' } async def xiaoshou_gai_zhekou_dijia(ns={}): # 如果productid是列表 循环 productidss = ns.get('productid') productids = ns.get('productid') if ',' in productidss: productidss = productidss.replace('\"', '').split(',') else: productidss = [productidss.replace('\"', '')] for productid in productidss: nss = { "discount": ns.get('discount'), "price": ns.get('price'), "productid": productid.strip(), "bid_orgid": ns.get('bid_orgid'), "offer_orgid": ns.get('offer_orgid'), "providerid": '' } res = await xiaoshou_gai_zhekou_dijia_detail(nss) return res ret = await xiaoshou_gai_zhekou_dijia(params_kw) return ret