async def shangji_provider_product_search(ns={}): """ 本机构针对某个provider持有的产品 递归 :param ns: :return: """ providerid = ns.get('providerid') offer_orgid = ns.get('offer_orgid') product_list = [] db = DBPools() async with db.sqlorContext('kboss') as sor: sql_find_bid = """select * from saleprotocol where bid_orgid = '%s' and del_flg = '0' and CURRENT_DATE between start_date and end_date;""" % offer_orgid sql_find_bid_li = await sor.sqlExe(sql_find_bid, {}) sql_res = [item.get('offer_orgid') for item in sql_find_bid_li] # 首先判断是不是当前分销商的直属供应商 if providerid in sql_res: print('该供应商就是上级机构的供应商, 返回该供应商所有产品') provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % providerid provider_product_li = await sor.sqlExe(provider_product_sql, {}) product_list.extend(provider_product_li) return product_list else: # 如果不是直属供应商 就是上级某级机构的供应商 for sett in sql_find_bid_li: salemode = sett['salemode'] offer_orgid = sett['offer_orgid'] protocolid = sett['id'] # 首先在折扣表里找对应的provider if salemode == '0': # 查找子表 zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) exits_star = [(item.get('providerid'), item.get('productid')) for item in zi_table] exist_st = (providerid, '*') if exist_st in exits_star: await shangji_provider_product_search({'providerid': providerid, 'offer_orgid': offer_orgid}) else: for zic in zi_table: zic_provider = zic['providerid'] zic_productid = zic['productid'] if zic_provider == providerid: provider_product_sql = """select * from product WHERE id = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % zic_productid provider_product_li = await sor.sqlExe(provider_product_sql, {}) product_list.extend(provider_product_li) elif salemode == '2': # 查找子表 zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) for zic in zi_table: zic_provider = zic['providerid'] zic_productid = zic['productid'] if zic_provider == providerid: provider_product_sql = """select * from product WHERE id = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % zic_productid provider_product_li = await sor.sqlExe(provider_product_sql, {}) product_list.extend(provider_product_li) return product_list async def self_product_search(ns={}): """ 产品不落地 本机构所有产品查找 回佣>折扣>底价 本机构是业主机构 协议表所有bid是本机构 *就查找product表 provider所有产品 本质是往上找一层 本机构是某级分销商 协议表所有bid是本机构 *就查找 上级offer为bid *对应的provider 循环 直到不含有*/offer为provider类型为供应商为止 找N层 :param ns: :return: """ # ns = { # 'bid_orgid': '6woiJ-_5tDmZUHFnLLty_', # } bid_orgid = ns.get('bid_orgid') db = DBPools() async with db.sqlorContext('kboss') as sor: try: if ns.get('sor'): sor = ns.get('sor') all_product = [] ns['del_flg'] = '0' # 查找所有bid是本机构的协议表 sql_find_bid = """select * from saleprotocol where bid_orgid = '%s' and del_flg = '0' and CURRENT_DATE between start_date and end_date;""" % bid_orgid sql_find_bid_li = await sor.sqlExe(sql_find_bid, {}) # 判断是业主机构还是分销商 yezhu_li = await sor.R('organization', {'id': bid_orgid}) yezhu_judge = yezhu_li[0]['org_type'] # 如果是供应商 就返回所有产品 if yezhu_judge == '4': provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % bid_orgid provider_product_li = await sor.sqlExe(provider_product_sql, {}) return provider_product_li # 如果是业主机构 if yezhu_judge == '0': for sett in sql_find_bid_li: salemode = sett['salemode'] offer_orgid = sett['offer_orgid'] protocolid = sett['id'] # 如果salemode是1 就是供应商所有产品 if salemode == '1': provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % offer_orgid provider_product_li = await sor.sqlExe(provider_product_sql, {}) all_product.extend(provider_product_li) # 如果salemode是折扣 如果有* 就是供应商所有产品 如果salemode是底价就获取所有productid if salemode == '0' or salemode == '2': # 查找子表 zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) # 如果有* 就获取providerid所有产品 star_flg = [item.get('productid') for item in zi_table] if '*' in star_flg: provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % offer_orgid provider_product_li = await sor.sqlExe(provider_product_sql, {}) all_product.extend(provider_product_li) else: prd_single_ids = [item.get('productid') for item in zi_table] for prd_single in prd_single_ids: single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % prd_single single_res_li = await sor.sqlExe(single_sql, {}) single_res = single_res_li[0] if single_res_li else {} all_product.append(single_res) return all_product # 如果是分销商 if yezhu_judge == '1': for sett in sql_find_bid_li: salemode = sett['salemode'] offer_orgid = sett['offer_orgid'] protocolid = sett['id'] # 判断是业主机构还是分销商 yezhu_li = await sor.R('organization', {'id': offer_orgid}) yezhu_judge = yezhu_li[0]['org_type'] # 如果salemode是1 就是offer所有产品 if salemode == '1': prodcut_one = await self_product_search({'bid_orgid': offer_orgid}) all_product.extend(prodcut_one) # 如果salemode是折扣 如果有* 就是供应商所有产品 不是* 就获取所有productid if salemode == '0': # 如果上级机构是供应商就获取该供应商所有产品 if yezhu_judge == '4': provider_product_sql_ = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % offer_orgid provider_product_li = await sor.sqlExe(provider_product_sql_, {}) all_product.extend(provider_product_li) else: # 如果不是供应商就查找子表 zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) # 如果有* 就获取providerid所有产品 for zic in zi_table: providerid_ = zic['providerid'] productid_ = zic['productid'] if productid_ == '*': # 查找上级机构该providerid持有的产品 product_res = await shangji_provider_product_search({'providerid': providerid_, 'offer_orgid': offer_orgid}) all_product.extend(product_res) else: single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % productid_ single_res_li = await sor.sqlExe(single_sql, {}) single_res = single_res_li[0] if single_res_li else {} all_product.append(single_res) # 如果salemode是底价 就获取所有productid if salemode == '2': zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) # 如果有* 就获取providerid所有产品 for zic in zi_table: productid_ = zic['productid'] single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE between effect_date and expire_date;""" % productid_ single_res_li = await sor.sqlExe(single_sql, {}) single_res = single_res_li[0] if single_res_li else {} all_product.append(single_res) return all_product # return { # "status": True, # "msg": "product_salemode search success", # "data": all_product # } except Exception as e: raise e return { "status": False, "msg": "product_salemode search failed" } async def shoujia_guanli_cha(ns={}): """ 销售看售价 :return: """ # ns = { # 'bid_orgid': 'mIWUHBeeDM8mwAFPIQ8pS' # } db = DBPools() async with db.sqlorContext('kboss') as sor: try: ns_dijia = { 'bid_orgid': ns.get('bid_orgid'), 'salemode': '2', 'del_flg': '0' } ns_shoujia = { 'offer_orgid': ns.get('bid_orgid'), 'bid_orgid': '*', 'salemode': '2', 'del_flg': '0' } dijia_res_li = await sor.R('saleprotocol', ns_dijia) shoujia_res_li = await sor.R('saleprotocol', ns_shoujia) product_all = [] sj_zibiao_cha_li = [] for shoujia in shoujia_res_li: sj_protocolid = shoujia['id'] sj_zibiao_cha_li = await sor.R('product_salemode', {'protocolid': sj_protocolid, 'del_flg': '0'}) for floorprice in dijia_res_li: protocolid = floorprice['id'] zi_biao_cha_li = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) for zibiao in zi_biao_cha_li: product_detail = {} product_detail['gai_dijia_id'] = zibiao['id'] product_detail['productid'] = zibiao['productid'] product_detail['floorprice'] = zibiao['price'] product_table_li = await sor.R('product', {'id': product_detail['productid'], 'del_flg': '0'}) if product_table_li: product_detail.update(product_table_li[0]) for sj_zibiao_cha in sj_zibiao_cha_li: sj_productid = sj_zibiao_cha['productid'] if product_detail['productid'] == sj_productid: product_detail['gai_shoujia_id'] = sj_zibiao_cha['id'] product_detail['shoujia'] = sj_zibiao_cha['price'] product_all.append(product_detail) return { 'status': True, 'msg': '销售看售价成功', 'data': product_all } except Exception as e: return { 'status': False, 'msg': '销售看售价失败', 'err_msg': e } async def discount_guanli_cha(ns={}): """ 折扣管理查 :return: """ bid_orgid = ns.get('bid_orgid') db = DBPools() async with db.sqlorContext('kboss') as sor: try: ns_shangji_zhekou = { 'bid_orgid': ns.get('bid_orgid'), 'salemode': '0', 'del_flg': '0' } ns_kehu_zhekou = { 'offer_orgid': ns.get('bid_orgid'), 'bid_orgid': '*', 'salemode': '0', 'del_flg': '0' } # 查找所有bid是本机构的协议表 sql_find_bid = """select * from saleprotocol where bid_orgid = '%s' and (salemode='0' or salemode='1') and del_flg = '0';""" % bid_orgid sql_find_bid_li = await sor.sqlExe(sql_find_bid, {}) # 查找所有针对本机构salemode为折扣(和回佣)的所有产品并显示折扣 all_product = [] all_product_ids = [] # 判断是业主机构还是分销商 yezhu_li = await sor.R('organization', {'id': bid_orgid}) yezhu_judge = yezhu_li[0]['org_type'] # 如果是业主机构 if yezhu_judge == '0': for sett in sql_find_bid_li: salemode = sett['salemode'] offer_orgid = sett['offer_orgid'] protocolid = sett['id'] # 如果salemode是1 就是供应商所有产品 if salemode == '1': provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0';""" % offer_orgid provider_product_li = await sor.sqlExe(provider_product_sql, {}) all_product.extend(provider_product_li) # 如果salemode是折扣 如果有* 就是供应商所有产品 如果salemode是底价就获取所有productid if salemode == '0': # 查找子表 zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) zi_table = [zi_table_item for zi_table_item in zi_table if zi_table_item.get('productid')] xieyi_zibiao_cha_li_ = sorted(zi_table, key=lambda x: (x['productid'] == '*', x['productid'])) for xieyi_zibiao in xieyi_zibiao_cha_li_: product_id_ = xieyi_zibiao['productid'] product_discount_ = xieyi_zibiao['discount'] if product_id_ != '*': single_sql = """select * from product where id = '%s' and del_flg = '0';""" % product_id_ single_res_li = await sor.sqlExe(single_sql, {}) if single_res_li: single_res = single_res_li[0] single_res['shangji_discount'] = product_discount_ all_product_ids.append(product_id_) all_product.append(single_res) # else: # # 如果折扣设置为* 获取上级机构所有产品 # shangji_suoyou_chanpin = await self_product_search({'bid_orgid': bid_orgid}) # for shangji_suoyou in shangji_suoyou_chanpin: # shangji_prd_id = shangji_suoyou.get('id') # if shangji_prd_id not in all_product_ids: # shangji_suoyou['shangji_discount'] = product_discount_ # all_product_ids.append(shangji_prd_id) # all_product.append(shangji_suoyou) # 如果是分销商 if yezhu_judge == '1': for sett in sql_find_bid_li: salemode = sett['salemode'] offer_orgid = sett['offer_orgid'] protocolid = sett['id'] # 判断是业主机构0/供应商4/分销商1 (产品id取消* 不再做判断) # yezhu_li = await sor.R('organization', {'id': offer_orgid}) # yezhu_judge = yezhu_li[0]['org_type'] # 如果salemode是1 就是offer所有产品 (产品id取消* 不再做判断) # if salemode == '1': # prodcut_one = await self_product_search({'bid_orgid': offer_orgid}) # all_product.extend(prodcut_one) # 如果salemode是折扣 如果有* 就是供应商所有产品 不是* 就获取所有productid if salemode == '0' or salemode == '1': zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) # xieyi_zibiao_cha_li_ = sorted(zi_table, key=lambda x: (x['productid'] == '*', x['productid'])) # 如果有* 就获取providerid所有产品 for xieyi_zibiao in zi_table: product_id_ = xieyi_zibiao['productid'] product_discount_ = xieyi_zibiao['discount'] if product_id_ != '*': single_sql = """select * from product where id = '%s' and del_flg = '0'""" % product_id_ single_res_li = await sor.sqlExe(single_sql, {}) if single_res_li: single_res = single_res_li[0] single_res['shangji_discount'] = product_discount_ all_product_ids.append(product_id_) all_product.append(single_res) # else: # # 如果折扣设置为* 获取上级机构所有产品 # shangji_suoyou_chanpin = await self_product_search({'bid_orgid': bid_orgid}) # for shangji_suoyou in shangji_suoyou_chanpin: # shangji_prd_id = shangji_suoyou.get('id') # if shangji_prd_id not in all_product_ids: # shangji_suoyou['shangji_discount'] = product_discount_ # all_product_ids.append(product_id_) # all_product.append(shangji_suoyou) # 查找本机构对客户设置过的折扣 benjigou_kehu_zhekou_dic = { 'offer_orgid': bid_orgid, 'bid_orgid': '*', 'salemode': '0', 'del_flg': '0' } exist_yijing_peizhi = [] benjigou_kehu_zhekou_li = await sor.R('saleprotocol', benjigou_kehu_zhekou_dic) for benjigou_kehu_zhekou in benjigou_kehu_zhekou_li: benjigou_kehu_zhekou_protocolid = benjigou_kehu_zhekou.get('id') benjigou_kehu_zhekou_zibiao_li_ = await sor.R('product_salemode', {'protocolid': benjigou_kehu_zhekou_protocolid, 'del_flg': '0'}) benjigou_kehu_zhekou_zibiao_li = sorted(benjigou_kehu_zhekou_zibiao_li_, key=lambda x: (x['productid'] == '*', x['productid'])) for kehu_zhekou in benjigou_kehu_zhekou_zibiao_li: zi_biao_id = kehu_zhekou.get('id') prd_id = kehu_zhekou.get('productid') exist_yijing_peizhi.append(prd_id) prd_discount = kehu_zhekou.get('discount') # 数据覆盖 all_product_bck = [ites for ites in all_product] # 单独配置过的折扣产品 if prd_id != '*': for aa in all_product_bck: aaid = aa.get('id') if aaid == prd_id: all_product.remove(aa) aa['kehu_discount'] = prd_discount aa['zi_biao_id'] = zi_biao_id all_product.append(aa) # else: # # 配置为*的统一折扣产品 # for aa in all_product_bck: # if not aa.get('kehu_discount'): # all_product.remove(aa) # aa['kehu_discount'] = prd_discount # aa['zi_biao_id'] = zi_biao_id # all_product.append(aa) # 只有设置了客户折扣才会展示 # all_product = [itemm for itemm in all_product if itemm.get('kehu_discount')] # 查找供应商名称 赋值给每个产品 pro_name_li = await sor.R('organization', {'del_flg': '0'}) for aeo in all_product: for aoe_i in pro_name_li: if aeo['providerid'] == aoe_i['id']: aeo['providername'] = aoe_i['orgname'] # 获取供应商和ptype拼接 cc = {} bb = {} for item in all_product: providerid = item['providerid'] providername = item['providername'] ptype = item['ptype'] if providername in cc.keys(): ptypes = cc[providername]['ptype'] if not ptype in ptypes: ptypes.append(ptype) cc[providername]['ptype'] = ptypes else: bb[providername] = {'providerid': providerid, 'ptype': [ptype]} cc.update(bb) yugo_list = [] for yugo in cc.keys(): yugo_dic = {} yugo_dic['providername'] = yugo yugo_dic['providerid'] = cc[yugo]['providerid'] yugo_dic['ptype'] = [{'ptype': yg} for yg in cc[yugo]['ptype']] yugo_list.append(yugo_dic) # 指定供应商和供应商的所有产品 if ns.get('providerid'): ptypes = [] prid_res = [] # 找到对应供应商的ptype for daer in yugo_list: daer_providerid = daer['providerid'] if daer_providerid == ns.get('providerid'): ptypes = daer['ptype'] prid_res = [item for item in all_product if item['providerid'] == ns.get('providerid')] # 如果既有供应商id 又有ptype指定的类型 if ns.get('ptype'): prid_res = [item for item in all_product if item['providerid'] == ns.get('providerid') and item['ptype'] == ns.get('ptype')] return { 'status': True, 'msg': '获取供应商对应的产品成功', 'provider_info': ptypes, 'data': prid_res } if ns.get('ptype'): # ptype指定的类型 if ns.get('ptype'): prid_res = [item for item in all_product if item['ptype'] == ns.get('ptype')] return { 'status': True, 'msg': '获取供应商对应的产品成功', 'data': prid_res } if ns.get('keyword'): return { 'status': True, 'msg': '通过关键字查找产品成功', 'provider_info': yugo_list, 'data': [item for item in all_product if ns.get('keyword') in item['name']] } if ns.get('kv') == 'ptype': # 找所有ptype all_ptype = [] for juli in yugo_list: juli_ptype = juli['ptype'] all_ptype.extend(juli_ptype) filter_all_ptype = [] for item in all_ptype: if not item in filter_all_ptype: filter_all_ptype.append(item) return { 'status': True, 'msg': '获取所有产品类型成功', 'data': filter_all_ptype } return { 'status': True, 'msg': '销售看折扣成功', 'provider_info': yugo_list, 'data': all_product } except Exception as e: raise e return { 'status': False, 'msg': '销售看折扣失败', # 'err_msg': e } async def provider_info_cha(providerid=None): db = DBPools() async with db.sqlorContext('kboss') as sor: provider_org_info_li = await sor.R('organization', {'id': providerid}) provider_org_info = provider_org_info_li[0] return provider_org_info async def xiaoshou_kan_zhekou(ns={}): """ 销售看折扣 addition使用函数 shangji_provider_product_search.dspy self_product_search.dspy shoujia_guanli_cha.dspy discount_guanli_cha.dspy provider_info_cha.dspy :param ns: :return: """ db = DBPools() async with db.sqlorContext('kboss') as sor: try: # 配置产品id列表[] product_all_ids = [] product_all_infos = [] product_all_price_infos = [] # 通过salemanid查看客户所在机构 # user_org_id, orgid = await kehu_kan_xiaoshoujigou({'userid': await get_user(), 'sor': sor}) user_org_id = ns.get('customerid') org_li = await sor.R('organization', {'id': user_org_id, 'del_flg': '0'}) orgid = org_li[0]['parentid'] # 销售机构信息 org_name = await sor.R('organization', {'id': orgid, 'del_flg': '0'}) organization_name = org_name[0]['orgname'] # 获取本机构底价和折扣配置信息 shoujia_guanli_search = await shoujia_guanli_cha({'bid_orgid': orgid}) shoujia_guanli_li = shoujia_guanli_search['data'] discount_guanli_search = await discount_guanli_cha({'bid_orgid': orgid}) discount_guanli_li = discount_guanli_search['data'] # 优先查看bid为该用户的配置 xieyi_yonghu_cha_sql = """select * from saleprotocol where offer_orgid = '%s' and bid_orgid = '%s' and del_flg = '0' and CURRENT_DATE between start_date and end_date;""" % (orgid, user_org_id) xieyi_yonghu_cha_li = await sor.sqlExe(xieyi_yonghu_cha_sql, {}) for xieyi_yonghu_cha in xieyi_yonghu_cha_li: salemode_yonghu = xieyi_yonghu_cha['salemode'] protocolid_yonghu = xieyi_yonghu_cha['id'] xieyi_yonghu_start_time = xieyi_yonghu_cha['start_date'] xieyi_yonghu_end_time = xieyi_yonghu_cha['end_date'] # 查看子表 xieyi_zibiao_cha_li = await sor.R('product_salemode', {'protocolid': protocolid_yonghu, 'del_flg': '0'}) xieyi_zibiao_cha_li_ = sorted(xieyi_zibiao_cha_li, key=lambda x: (x['productid'] == '*', x['productid'])) if salemode_yonghu == '0' or salemode_yonghu == '2': for xieyi_zibiao in xieyi_zibiao_cha_li_: providerid_yonghu = xieyi_zibiao['providerid'] providername = (await provider_info_cha(providerid_yonghu))['orgname'] productid_yonghu = xieyi_zibiao['productid'] discount_yonghu = xieyi_zibiao['discount'] price_yonghu = xieyi_zibiao['price'] zibiao_id_yonghu = xieyi_zibiao['id'] if productid_yonghu in product_all_ids: # 产品id已经存在 continue # 折扣表中 产品id不为* 就展示对应的产品信息和折扣信息和折扣后的价格 底价表中展示对应产品信息和售价信息 if salemode_yonghu == '0': if productid_yonghu != '*': # 筛选id product_all_ids.append(productid_yonghu) product_info_sql = """select * from product where id = '%s' and del_flg = '0';""" % productid_yonghu product_info_li = await sor.sqlExe(product_info_sql, {}) product_info = product_info_li[0] if product_info_li else {} if product_info: for discount_guanli in discount_guanli_li: if productid_yonghu == discount_guanli.get('id'): product_info['shangji_discount'] = discount_guanli.get('shangji_discount') product_info['productid'] = product_info['id'] product_info['offer_orgid'] = orgid product_info['bid_orgid'] = user_org_id product_info['zibiao_id'] = zibiao_id_yonghu product_info['protocolid'] = protocolid_yonghu product_info['discount'] = discount_yonghu product_info['start_date'] = xieyi_yonghu_start_time product_info['end_date'] = xieyi_yonghu_end_time product_info['providername'] = providername # TODO 从供应商那里获取对应的产品价格 # product_info['price'] = round(random.random() * 100, 2) product_info['price'] = 200.2 product_info['discount_price'] = round(product_info['price'] * product_info['discount'], 2) # 追加产品信息 product_all_infos.append(product_info) # elif productid_yonghu == '*': # # 折扣表中 产品id为* 就向上级机构查找有对应providerid的多少产品 依次迭代 # shangji_chanpin_li = await shangji_provider_product_search({'providerid': providerid_yonghu, 'offer_orgid': orgid}) # for shangji_chanpin in shangji_chanpin_li: # for discount_guanli in discount_guanli_li: # if productid_yonghu == discount_guanli.get('productid'): # shangji_chanpin['shangji_discount'] = discount_guanli.get('shangji_discount') # shangji_chanpin_id = shangji_chanpin['id'] # # 筛选id # if shangji_chanpin_id in product_all_ids: # continue # product_all_ids.append(shangji_chanpin_id) # shangji_chanpin['productid'] = shangji_chanpin_id # shangji_chanpin['discount'] = discount_yonghu # shangji_chanpin['zibiao_id'] = '*' # shangji_chanpin['protocolid'] = protocolid_yonghu # shangji_chanpin['offer_orgid'] = orgid # shangji_chanpin['bid_orgid'] = user_org_id # shangji_chanpin['start_date'] = xieyi_yonghu_start_time # shangji_chanpin['end_date'] = xieyi_yonghu_end_time # # product_all_infos.append(shangji_chanpin) elif salemode_yonghu == '2': # 筛选id product_all_ids.append(productid_yonghu) product_info_sql = """select * from product where id = '%s' and del_flg = '0';""" % productid_yonghu product_info_li = await sor.sqlExe(product_info_sql, {}) product_info = product_info_li[0] if product_info_li else {} if product_info: for shoujia_guanli in shoujia_guanli_li: if productid_yonghu == shoujia_guanli.get('productid'): product_info['floorprice'] = shoujia_guanli.get('floorprice') product_info['productid'] = product_info['id'] product_info['price'] = price_yonghu product_info['zibiao_id'] = zibiao_id_yonghu product_info['protocolid'] = protocolid_yonghu product_info['offer_orgid'] = orgid product_info['bid_orgid'] = user_org_id product_info['start_date'] = xieyi_yonghu_start_time product_info['end_date'] = xieyi_yonghu_end_time product_info['providername'] = providername # 查看折扣不再追加产品信息 product_all_price_infos.append(product_info) # product_all_infos.append(product_info) # 查找offer对应的机构id bid为* 的所有配置 时间限制 xieyi_cha_sql = """select * from saleprotocol where offer_orgid = '%s' and bid_orgid = '*' and del_flg = '0' and CURRENT_DATE between start_date and end_date;""" % orgid xieyi_cha_res_li = await sor.sqlExe(xieyi_cha_sql, {}) for xieyi_cha in xieyi_cha_res_li: salemode = xieyi_cha['salemode'] protocolid = xieyi_cha['id'] xieyi_cha_start_ = xieyi_cha['start_date'] xieyi_cha_end_ = xieyi_cha['end_date'] # 查看子表 xieyi_zibiao_cha_li = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'}) xieyi_zibiao_cha_li_ = sorted(xieyi_zibiao_cha_li, key=lambda x: (x['productid'] == '*', x['productid'])) if salemode == '0' or salemode == '2': for xieyi_zibiao in xieyi_zibiao_cha_li_: providerid = xieyi_zibiao['providerid'] providername_s = (await provider_info_cha(providerid))['orgname'] productid = xieyi_zibiao['productid'] discount = xieyi_zibiao['discount'] price = xieyi_zibiao['price'] zibiao_id_ = xieyi_zibiao['id'] if productid in product_all_ids: # 产品id已经存在 continue # 折扣表中 产品id不为* 就展示对应的产品信息和折扣信息和折扣后的价格 底价表中展示对应产品信息和售价信息 if salemode == '0': if productid != '*': # 筛选id product_all_ids.append(productid) product_info_sql = """select * from product where id = '%s' and del_flg = '0';""" % productid product_info_li = await sor.sqlExe(product_info_sql, {}) product_info = product_info_li[0] if product_info_li else {} if product_info: for discount_guanli in discount_guanli_li: if productid == discount_guanli.get('productid'): product_info['shangji_discount'] = discount_guanli.get('shangji_discount') product_info['productid'] = product_info['id'] product_info['offer_orgid'] = orgid product_info['bid_orgid'] = user_org_id product_info['protocolid'] = protocolid product_info['zibiao_id'] = zibiao_id_ product_info['discount'] = discount product_info['start_date'] = xieyi_cha_start_ product_info['end_date'] = xieyi_cha_end_ product_info['providername'] = providername_s # TODO 从供应商那里获取对应的产品价格 product_info['price'] = 200.2 product_info['discount_price'] = round(product_info['price'] * product_info['discount'], 2) # 追加产品信息 product_all_infos.append(product_info) # elif productid == '*': # # 折扣表中 产品id为* 就向上级机构查找有对应providerid的多少产品 依次迭代 # shangji_chanpin_li = await shangji_provider_product_search({'providerid': providerid, 'offer_orgid': orgid}) # for shangji_chanpin in shangji_chanpin_li: # shangji_chanpin_id = shangji_chanpin['id'] # # 筛选id # if shangji_chanpin_id in product_all_ids: # continue # product_all_ids.append(shangji_chanpin_id) # for discount_guanli in discount_guanli_li: # if productid == discount_guanli.get('productid'): # shangji_chanpin['shangji_discount'] = discount_guanli.get('shangji_discount') # shangji_chanpin['productid'] = shangji_chanpin_id # shangji_chanpin['discount'] = discount # shangji_chanpin['zibiao_id'] = zibiao_id_ # shangji_chanpin['protocolid'] = protocolid # shangji_chanpin['offer_orgid'] = orgid # shangji_chanpin['bid_orgid'] = user_org_id # shangji_chanpin['start_date'] = xieyi_cha_start_ # shangji_chanpin['end_date'] = xieyi_cha_end_ # product_all_infos.append(shangji_chanpin) elif salemode == '2': # 筛选id product_all_ids.append(productid) product_info_sql = """select * from product where id = '%s' and del_flg = '0';""" % productid product_info_li = await sor.sqlExe(product_info_sql, {}) product_info = product_info_li[0] if product_info_li else {} if product_info: for shoujia_guanli in shoujia_guanli_li: if productid == shoujia_guanli.get('productid'): product_info['floorprice'] = shoujia_guanli.get('floorprice') product_info['productid'] = product_info['id'] product_info['offer_orgid'] = orgid product_info['bid_orgid'] = user_org_id product_info['price'] = price product_info['zibiao_id'] = zibiao_id_ product_info['protocolid'] = protocolid product_info['start_date'] = xieyi_cha_start_ product_info['end_date'] = xieyi_cha_end_ product_info['providername'] = providername_s # 查看折扣不再追加产品信息 product_all_price_infos.append(product_info) # product_all_infos.append(product_info) # 获取本机构所有的回佣产品 huiyong_cha_sql = """select * from saleprotocol where bid_orgid = '%s' and salemode = '1' and del_flg = '0' and CURRENT_DATE between start_date and end_date;""" % orgid hongyong_cha_li = await sor.sqlExe(huiyong_cha_sql, {}) for hongyong_cha in hongyong_cha_li: # 获取协议主表protocolid start_time = hongyong_cha['start_date'] end_time = hongyong_cha['end_date'] huiyong_protocolid = hongyong_cha['id'] # 获取协议子表productid hongyong_zibiao_cha_li = await sor.R('product_salemode', {'protocolid': huiyong_protocolid, 'del_flg': '0'}) for hongyong_zibiao in hongyong_zibiao_cha_li: hongyong_prdid = hongyong_zibiao['productid'] hongyong_zibiao_id = hongyong_zibiao['id'] huiyong_providerid = hongyong_zibiao['providerid'] huiyong_providername = (await provider_info_cha(huiyong_providerid))['orgname'] # 筛选id product_all_ids.append(hongyong_prdid) product_info_sql = """select * from product where id = '%s' and del_flg = '0';""" % hongyong_prdid product_info_li = await sor.sqlExe(product_info_sql, {}) product_info = product_info_li[0] if product_info_li else {} if product_info: product_info['productid'] = product_info['id'] product_info['offer_orgid'] = orgid product_info['bid_orgid'] = user_org_id product_info['protocolid'] = huiyong_protocolid product_info['zibiao_id'] = hongyong_zibiao_id product_info['start_date'] = start_time product_info['end_date'] = end_time product_info['providername'] = huiyong_providername # TODO 从供应商那里获取对应的产品价格 product_info['price'] = 200.2 # 追加产品信息 product_all_infos.append(product_info) # 获取本机构所有产品 provider_products = await self_product_search({'bid_orgid': orgid, 'sor': sor}) for prd in provider_products: prdid = prd.get('id') if prdid not in product_all_ids: prd['offer_orgid'] = orgid prd['bid_orgid'] = user_org_id prd['productid'] = prdid product_all_infos.append(prd) product_all_infos = [itemm for itemm in product_all_infos if itemm.get('productid')] if ns.get('kv') == 'price': product_all = product_all_price_infos else: product_all = product_all_infos provider_info = [] for i in product_all: provider_dic = {'providername': i.get('providername'), 'providerid': i.get('providerid')} if not provider_dic in provider_info: provider_info.append(provider_dic) if ns.get('productname'): product_all = [i for i in product_all if ns['productname'] in i['name']] if ns.get('start_discount') and ns.get('end_discount'): temp_list = [] for i in product_all: if i.get('discount'): if float(ns['start_discount']) <= float(i['discount']) <= float(ns['end_discount']): temp_list.append(i) product_all = temp_list if ns.get('providerid') and ns.get('ptype'): list3 = [] for i in product_all: if i['providerid'] == ns.get('providerid') and i['ptype'] == ns.get('ptype'): list3.append(i) product_all = list3 elif ns.get('providerid'): list2 = [] for i in product_all: if i['providerid'] == ns.get('providerid'): list2.append(i) product_all = list2 elif ns.get('ptype'): list1 = [] for i in product_all: if i['ptype'] == ns.get('ptype'): list1.append(i) product_all = list1 # 专属分类 classify_list_temp = list(set([i.get('classify') for i in product_all])) classify_list = [{'class_key': '未配置'} if x == None else {'class_key': x} for x in classify_list_temp] if ns.get('classify'): if ns['classify'] == '未配置': classify_filter = None else: classify_filter = ns['classify'] product_all = [i for i in product_all if i.get('classify') == classify_filter] if ns.get('kv') == 'price': return { 'status': True, 'classify_list': classify_list, 'provider_info': provider_info, 'msg': '销售获取商品底价信息成功', 'data': product_all } return { 'status': True, 'classify_list': classify_list, 'provider_info': provider_info, 'msg': '销售获取商品折扣信息成功', 'data': product_all } except Exception as e: return { 'status': False, 'msg': '销售获取商品折扣信息出错: %s' % e } ret = await xiaoshou_kan_zhekou(params_kw) return ret