update
This commit is contained in:
parent
31c8f26c44
commit
15d135e2f5
@ -24,12 +24,6 @@ async def get_user_role(ns={}):
|
|||||||
return role
|
return role
|
||||||
|
|
||||||
async def user_browse_history_add(ns={}):
|
async def user_browse_history_add(ns={}):
|
||||||
# ns = {
|
|
||||||
# 'userid': '9KVhsVCJsW_29q3hRhMAr', # 用户ID
|
|
||||||
# 'productid': 'p2s2YPPU7uquza3gGw9k2', # 产品ID
|
|
||||||
# 'ip_address': '192.168.1.1', # IP地址
|
|
||||||
# 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/98.0.4758.102' # 用户代理
|
|
||||||
# }
|
|
||||||
# 必要参数校验
|
# 必要参数校验
|
||||||
if not ns.get('userid') or not ns.get('productid'):
|
if not ns.get('userid') or not ns.get('productid'):
|
||||||
return {
|
return {
|
||||||
@ -42,6 +36,18 @@ async def user_browse_history_add(ns={}):
|
|||||||
try:
|
try:
|
||||||
# 根据timestamp时间字段:browse_time去重 查找10个小时内是否存在
|
# 根据timestamp时间字段:browse_time去重 查找10个小时内是否存在
|
||||||
# browse_time = datetime.datetime.now() - datetime.timedelta(hours=10)
|
# browse_time = datetime.datetime.now() - datetime.timedelta(hours=10)
|
||||||
|
|
||||||
|
# 检查产品的publish_type
|
||||||
|
product_sql = """
|
||||||
|
SELECT publish_type FROM user_publish_product
|
||||||
|
WHERE id = '%s' AND del_flg = '0';
|
||||||
|
""" % ns.get('productid')
|
||||||
|
product_result = await sor.sqlExe(product_sql, {})
|
||||||
|
if product_result:
|
||||||
|
publish_type = product_result[0]['publish_type']
|
||||||
|
else:
|
||||||
|
publish_type = 99
|
||||||
|
|
||||||
check_sql = """
|
check_sql = """
|
||||||
SELECT * FROM user_browse_history
|
SELECT * FROM user_browse_history
|
||||||
WHERE userid = '%s' AND productid = '%s' AND del_flg = '0';
|
WHERE userid = '%s' AND productid = '%s' AND del_flg = '0';
|
||||||
@ -63,13 +69,12 @@ async def user_browse_history_add(ns={}):
|
|||||||
|
|
||||||
# 生成记录ID
|
# 生成记录ID
|
||||||
record_id = uuid()
|
record_id = uuid()
|
||||||
# 插入浏览记录
|
|
||||||
insert_sql = """
|
insert_sql = """
|
||||||
INSERT INTO user_browse_history (
|
INSERT INTO user_browse_history (
|
||||||
id, userid, productid, ip_address, user_agent, del_flg, tag
|
id, userid, productid, ip_address, user_agent, del_flg, tag, publish_type
|
||||||
) VALUES ('%s', '%s', '%s', '%s', '%s', '0', '%s');
|
) VALUES ('%s', '%s', '%s', '%s', '%s', '0', '%s', '%s');
|
||||||
""" % (record_id, ns.get('userid'), ns.get('productid'),
|
""" % (record_id, ns.get('userid'), ns.get('productid'),
|
||||||
ns.get('ip_address', ''), ns.get('user_agent', ''), ns.get('tag'))
|
ns.get('ip_address', ''), ns.get('user_agent', ''), ns.get('tag', ''), publish_type)
|
||||||
await sor.sqlExe(insert_sql, {})
|
await sor.sqlExe(insert_sql, {})
|
||||||
return {
|
return {
|
||||||
'status': True,
|
'status': True,
|
||||||
@ -123,7 +128,7 @@ async def publish_product_search_detail(ns={}):
|
|||||||
|
|
||||||
# 保存浏览记录
|
# 保存浏览记录
|
||||||
if userid:
|
if userid:
|
||||||
await user_browse_history_add({'userid': userid, 'productid': ns.get('id'), 'tag': 'upp'})
|
res = await user_browse_history_add({'userid': userid, 'productid': ns.get('id'), 'tag': 'upp', 'publish_type': product_list[0]['publish_type']})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'status': True,
|
'status': True,
|
||||||
|
|||||||
@ -52,6 +52,7 @@ async def publish_product_search_first_page(ns={}):
|
|||||||
else:
|
else:
|
||||||
userid = await get_user()
|
userid = await get_user()
|
||||||
|
|
||||||
|
ns['userid'] = userid
|
||||||
publish_type = ns.get('publish_type')
|
publish_type = ns.get('publish_type')
|
||||||
page_size = int(ns['page_size']) if ns.get('page_size') else 8
|
page_size = int(ns['page_size']) if ns.get('page_size') else 8
|
||||||
current_page_param = int(ns['current_page']) if ns.get('current_page') else 1
|
current_page_param = int(ns['current_page']) if ns.get('current_page') else 1
|
||||||
|
|||||||
@ -14,21 +14,25 @@ async def favorite_add(ns={}):
|
|||||||
|
|
||||||
# 处理userid
|
# 处理userid
|
||||||
if ns.get('userid'):
|
if ns.get('userid'):
|
||||||
userid = ns.get('userid')
|
ns_dic['userid'] = ns.get('userid')
|
||||||
else:
|
else:
|
||||||
userid = None
|
ns_dic['userid'] = await get_user()
|
||||||
if not userid:
|
|
||||||
|
if not ns_dic.get('userid'):
|
||||||
server_error(401)
|
server_error(401)
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
async with db.sqlorContext('kboss') as sor:
|
||||||
try:
|
try:
|
||||||
# 检查是否已收藏
|
# 检查是否已收藏 处理tag是NULL的情况
|
||||||
check_sql = """
|
conditions = [
|
||||||
SELECT id FROM user_favorite
|
"userid = '%s'" % ns_dic['userid'],
|
||||||
WHERE userid = '%s' AND productid = '%s' AND favorite_type = '%s' AND del_flg = '0' AND tag = '%s'
|
"productid = '%s'" % ns_dic['productid'],
|
||||||
""" % (ns_dic['userid'], ns_dic['productid'], ns_dic['favorite_type'], ns_dic['tag'])
|
"favorite_type = '%s'" % ns_dic['favorite_type'] if ns_dic['favorite_type'] is not None else "favorite_type IS NULL",
|
||||||
|
"del_flg = '0'",
|
||||||
|
"tag = '%s'" % ns_dic['tag'] if ns_dic['tag'] is not None else "tag IS NULL"
|
||||||
|
]
|
||||||
|
check_sql = "SELECT id FROM user_favorite WHERE " + " AND ".join(conditions)
|
||||||
|
|
||||||
check_result = await sor.sqlExe(check_sql, {})
|
check_result = await sor.sqlExe(check_sql, {})
|
||||||
|
|
||||||
|
|||||||
@ -4,24 +4,25 @@ async def favorite_delete(ns={}):
|
|||||||
:param ns: 包含id或userid+productid+favorite_type参数
|
:param ns: 包含id或userid+productid+favorite_type参数
|
||||||
:return: 操作结果
|
:return: 操作结果
|
||||||
"""
|
"""
|
||||||
|
# 处理userid
|
||||||
|
if ns.get('userid'):
|
||||||
|
ns['userid'] = ns.get('userid')
|
||||||
|
else:
|
||||||
|
ns['userid'] = await get_user()
|
||||||
|
if not ns.get('userid'):
|
||||||
|
server_error(401)
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
async with db.sqlorContext('kboss') as sor:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if ns.get('id'):
|
if ns.get('id'):
|
||||||
# 根据收藏ID删除
|
# 根据收藏ID删除
|
||||||
update_dic = {
|
|
||||||
'id': ns.get('id'),
|
|
||||||
'del_flg': '1'
|
|
||||||
}
|
|
||||||
await sor.U('user_favorite', update_dic)
|
|
||||||
elif ns.get('userid') and ns.get('productid'):
|
|
||||||
# 根据用户ID和产品ID删除
|
|
||||||
update_sql = """
|
update_sql = """
|
||||||
UPDATE user_favorite
|
UPDATE user_favorite
|
||||||
SET del_flg = '1'
|
SET del_flg = '1'
|
||||||
WHERE userid = '%s' AND productid = '%s' AND favorite_type = '%s' AND del_flg = '0'
|
WHERE productid = '%s' AND userid = '%s'
|
||||||
""" % (ns.get('userid'), ns.get('productid'), ns.get('favorite_type', 'product'))
|
""" % (ns.get('id'), ns['userid'])
|
||||||
await sor.execute(update_sql)
|
await sor.sqlExe(update_sql, {})
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
'status': False,
|
'status': False,
|
||||||
|
|||||||
@ -6,10 +6,10 @@ async def favorite_search(ns={}):
|
|||||||
"""
|
"""
|
||||||
# 处理userid
|
# 处理userid
|
||||||
if ns.get('userid'):
|
if ns.get('userid'):
|
||||||
userid = ns.get('userid')
|
ns['userid'] = ns.get('userid')
|
||||||
else:
|
else:
|
||||||
userid = None
|
ns['userid'] = await get_user()
|
||||||
if not userid:
|
if not ns.get('userid'):
|
||||||
server_error(401)
|
server_error(401)
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|||||||
@ -1,17 +1,24 @@
|
|||||||
async def user_browse_history_search(ns={}):
|
async def user_browse_history_search(ns={}):
|
||||||
|
# 处理url_link转换成domain_name
|
||||||
|
if ns.get('url_link'):
|
||||||
|
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
|
||||||
|
else:
|
||||||
|
domain_name = None
|
||||||
|
|
||||||
# 处理userid
|
# 处理userid
|
||||||
if ns.get('userid'):
|
if ns.get('userid'):
|
||||||
userid = ns.get('userid')
|
userid = ns.get('userid')
|
||||||
else:
|
else:
|
||||||
userid = None
|
userid = await get_user()
|
||||||
if not userid:
|
if not userid:
|
||||||
server_error(401)
|
server_error(401)
|
||||||
|
|
||||||
# 参数处理
|
# 参数处理
|
||||||
productid = ns.get('productid')
|
productid = ns.get('productid')
|
||||||
|
publish_type = ns.get('publish_type')
|
||||||
start_time = ns.get('start_time')
|
start_time = ns.get('start_time')
|
||||||
end_time = ns.get('end_time')
|
end_time = ns.get('end_time')
|
||||||
page_size = int(ns.get('page_size', 1000))
|
page_size = int(ns.get('page_size', 10000))
|
||||||
current_page = int(ns.get('current_page', 1))
|
current_page = int(ns.get('current_page', 1))
|
||||||
offset = (current_page - 1) * page_size
|
offset = (current_page - 1) * page_size
|
||||||
|
|
||||||
@ -24,6 +31,8 @@ async def user_browse_history_search(ns={}):
|
|||||||
base_conditions.append(f"userid = '{userid}'")
|
base_conditions.append(f"userid = '{userid}'")
|
||||||
if productid:
|
if productid:
|
||||||
base_conditions.append(f"productid = '{productid}'")
|
base_conditions.append(f"productid = '{productid}'")
|
||||||
|
if publish_type:
|
||||||
|
base_conditions.append(f"publish_type = '{publish_type}'")
|
||||||
if start_time and end_time:
|
if start_time and end_time:
|
||||||
end_time += ' 23:59:59'
|
end_time += ' 23:59:59'
|
||||||
base_conditions.append(f"browse_time BETWEEN '{start_time}' AND '{end_time}'")
|
base_conditions.append(f"browse_time BETWEEN '{start_time}' AND '{end_time}'")
|
||||||
@ -59,9 +68,30 @@ async def user_browse_history_search(ns={}):
|
|||||||
product['product_info'] = product_info_li[0]
|
product['product_info'] = product_info_li[0]
|
||||||
if product['product_info'].get('phone_number'):
|
if product['product_info'].get('phone_number'):
|
||||||
product['product_info']['phone_number'] = '***************'
|
product['product_info']['phone_number'] = '***************'
|
||||||
|
if product['product_info'].get('img') and domain_name:
|
||||||
|
product['product_info']['img'] = 'https://' + domain_name + '/idfile?path=' + product['product_info']['img']
|
||||||
else:
|
else:
|
||||||
product['product_info'] = None
|
product['product_info'] = None
|
||||||
|
|
||||||
|
date_groups = {}
|
||||||
|
for item in result:
|
||||||
|
# 提取日期部分(如"2025-08-22 15:58:52" → "2025-08-22")
|
||||||
|
browse_date = datetime.datetime.strptime(item["browse_time"], "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
|
||||||
|
if browse_date not in date_groups:
|
||||||
|
date_groups[browse_date] = []
|
||||||
|
|
||||||
|
date_groups[browse_date].append(item)
|
||||||
|
|
||||||
|
# 按日期升序排序并添加序号
|
||||||
|
sorted_dates = sorted(date_groups.keys(), reverse=True) # 按日期升序排列
|
||||||
|
result = []
|
||||||
|
for idx, date in enumerate(sorted_dates, start=1):
|
||||||
|
result.append({
|
||||||
|
"id": str(idx), # 序号从1开始
|
||||||
|
"browse_date": date,
|
||||||
|
"products": date_groups[date] # 该日期下的所有浏览记录
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'status': True,
|
'status': True,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user