kboss/b/product/publish_product_search_detail.dspy
2025-08-18 13:30:09 +08:00

71 lines
2.4 KiB
Plaintext

async def get_user_role(ns={}):
sor = ns['sor']
# get role
ns['del_flg'] = '0'
res_role = await sor.R('userrole', ns)
if res_role:
user_role = res_role[0]
else:
return {
"status": False,
"msg": "userrole table, user id can not find..."
}
roleid = user_role.get('roleid')
# get role name
role_name = await sor.R('role', {'id': roleid})
if role_name:
role = role_name[0].get('role')
else:
return {
"status": False,
"msg": "role table, can not get role name"
}
return role
async def publish_product_search_detail(ns={}):
"""
:param ns:
:return:
"""
if ns.get('userid'):
userid = ns.get('userid')
else:
userid = await get_user()
db = DBPools()
async with db.sqlorContext('kboss') as sor:
user_role = None
# 区分运营和普通客户
if userid:
user_list = await sor.R('users', {'id': userid})
orgid = user_list[0]['orgid']
user_role = await get_user_role({'userid': userid, 'sor': sor})
# 如果用户角色是运营并且from='b' product_list中的phone_number和email做加星号处理
product_list = await sor.R('user_publish_product', {'id': ns.get('id'), 'del_flg': '0'})
product_category = await sor.R('user_publish_product_category', {'id': product_list[0]['product_category'].split(',')[0]})
product_list[0]['product_category'] = product_category[0]['product_category']
if user_role == '运营' and ns.get('from') == 'b':
pass
elif orgid == product_list[0]['orgid']:
pass
else:
for product in product_list:
if product.get('phone_number'):
product['phone_number'] = product['phone_number'][:3] + '****' + product['phone_number'][7:]
else:
product['phone_number'] = '198****8601'
if product.get('email'):
product['email'] = product['email'][:2] + '****' + product['email'][6:]
else:
product['email'] = 'kawa@****.com'
return {
'status': True,
'msg': 'Product retrieved successfully',
'data': product_list[0]
}
ret = await publish_product_search_detail(params_kw)
return ret