55 lines
1.6 KiB
Plaintext
55 lines
1.6 KiB
Plaintext
async def favorite_add(ns={}):
|
|
"""
|
|
添加用户收藏
|
|
:param ns: 包含userid, productid, favorite_type等参数
|
|
:return: 操作结果
|
|
"""
|
|
ns_dic = {
|
|
'id': uuid(), # 生成32位ID
|
|
'userid': ns.get('userid'),
|
|
'productid': ns.get('productid'),
|
|
'favorite_type': ns.get('favorite_type', '1'), # 默认为商品收藏
|
|
'tag': ns.get('tag') # 标签
|
|
}
|
|
|
|
# 处理userid
|
|
if ns.get('userid'):
|
|
userid = ns.get('userid')
|
|
else:
|
|
userid = None
|
|
if not userid:
|
|
server_error(401)
|
|
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
# 检查是否已收藏
|
|
check_sql = """
|
|
SELECT id FROM user_favorite
|
|
WHERE userid = '%s' AND productid = '%s' AND favorite_type = '%s' AND del_flg = '0' AND tag = '%s'
|
|
""" % (ns_dic['userid'], ns_dic['productid'], ns_dic['favorite_type'], ns_dic['tag'])
|
|
|
|
|
|
check_result = await sor.sqlExe(check_sql, {})
|
|
|
|
if check_result:
|
|
return {
|
|
'status': False,
|
|
'msg': '已收藏关注'
|
|
}
|
|
|
|
# 执行收藏操作
|
|
await sor.C('user_favorite', ns_dic)
|
|
return {
|
|
'status': True,
|
|
'msg': '关注收藏成功'
|
|
}
|
|
except Exception as e:
|
|
await sor.rollback()
|
|
return {
|
|
'status': False,
|
|
'msg': '关注收藏失败, %s' % str(e)
|
|
}
|
|
|
|
ret = await favorite_add(params_kw)
|
|
return ret |