✨作者主页:IT研究室✨
个人简介:曾从事计算机专业培训教学,擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。
☑文末获取源码☑
精彩专栏推荐⬇⬇⬇
Java项目
Python项目
安卓项目
微信小程序项目
文章目录
- 一、前言
- 二、开发环境
- 三、系统界面展示
- 四、代码参考
- 五、论文参考
- 六、系统视频
- 结语
一、前言
随着互联网技术的普及和移动设备的广泛使用,网上产品商城已经成为消费者购物的重要渠道。在这样的背景下,研究和开发一个功能完善、易于使用且具有良好用户体验的网上产品商城具有重要的现实意义。课题的必要性在于满足消费者多样化的购物需求,同时为商家提供一个便捷的在线销售平台。
尽管现有的网上商城解决方案在一定程度上满足了用户和商家的需求,但仍然存在一些问题。例如,部分商城的用户界面不够友好,导致用户在购物过程中遇到困难;商品分类和信息管理不够清晰,影响用户的购物体验;订单处理功能不完善,可能导致用户在购物过程中产生不满。这些问题进一步强调了开发一个更加便捷的网上产品商城的必要性。
本课题旨在研究和开发一个集成用户管理、商品分类管理、商品信息管理、订单管理、公告管理等主要功能的网上产品商城。通过实现这些功能,我们希望能够为用户带来更加便捷、愉悦的购物体验,同时为商家提供一个便捷易用的在线销售和管理工具。本课题的研究目的在于提高网上产品商城的整体性能,满足用户和商家的需求。
本课题的研究意义主要体现在以下几个方面:首先,它有助于推动电子商务行业的发展,为消费者提供更好的购物体验;其次,通过解决现有解决方案中存在的问题,本课题有助于提高网上产品商城的竞争力;再次,本课题的研究成果将为相关领域的研究者提供有益的参考,进一步增进计算机科学与技术领域的发展。
二、开发环境
- 开发语言:Java/Python两个版本
- 数据库:MySQL
- 系统架构:B/S
- 后端:SSM/SpringBoot/Django三个版本
- 前端:Vue
三、系统界面展示
- 网上产品商城界面展示:
四、代码参考
- Python项目实战代码参考:
def add_order(request):
uid = request.session.get('uid')
cart_ids = request.POST.getlist('cart_id')
cart_list = []
cart_id_list_str = ''
# 购物车数据
for cart_id in cart_ids:
cart = CartInfo.objects.get(id=cart_id)
cart_list.append(cart)
cart_id_list_str += cart_id+','
# 收货地址信息
address_list = AddressInfo.objects.filter(uid=uid).order_by('-is_default')
context = {
'cart_list': cart_list,
'address_list': address_list,
'cart_id_list': cart_id_list_str,
'title': '提交订单',
'app_name': '提交订单'
}
return render(request, 'order/place_order.html', context)
@transaction.atomic()
def handle_order(request):
address_id = request.POST.get('address')
cart_id_list = request.POST.get('cart_id_list').split(',')
sp = transaction.savepoint()
try:
# 订单表
order = Order()
now_str = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
order.id = '%s%s' % (now_str, random_str())
order.user_id = request.session['uid']
order.address_id = address_id
order.save()
total_price = 0
# 订单详情表
cart_list = CartInfo.objects.filter(id__in=cart_id_list)
for cart in cart_list:
if cart.count <= cart.goods.store:
detail = OrderDetail()
detail.order = order
detail.goods = cart.goods
detail.count = cart.count
detail.price = cart.goods.price*detail.count
detail.save()
goods = cart.goods
goods.store -= cart.count
goods.save()
cart.delete()
total_price += detail.price
order.total_price = total_price
order.save()
transaction.savepoint_commit(sp)
return HttpResponseRedirect('/user/order/')
except Exception:
transaction.savepoint_rollback(sp)
return HttpResponseRedirect('/cart/')
def random_str(random_len=6):
str = ''
chars = '0123456789'
# 依据长度,随机chars中下标,依据随机下标获取数据
for i in range(random_len):
str += chars[random.randint(0, (len(chars) - 1))]
return str
def register(request):
"""
用户注册
:param request:
:return:
"""
if request.method == 'POST':
post = request.POST
username = post.get('username')
password = post.get('password')
email = post.get('email')
is_username_exist = UserInfo.objects.filter(username=username).count() == 0
is_email_exist = UserInfo.objects.filter(email=email).count() == 0
if is_email_exist and is_username_exist:
user = UserInfo()
user.username = username
user.email = email
user.password = sha1(password.encode('utf8')).hexdigest()
user.save()
# 发送验证邮件
token = uuid.uuid1()
redis = StrictRedis()
key = 'user_verify_email_key_' + str(user.id)
redis.set(key, token)
html_message = "<a href='http://127.0.0.1:8000/user/verify_email/?id=%d&token=%s'>激活邮箱</a>" % (user.id, token)
task.send_verify_email.delay('生鲜商城用户注册邮箱激活', user.email, html_message)
return render(request, 'tips.html', {'info': '请登录邮箱进行激活操作'})
else:
return render(request, 'user_center/register.html', {'error': '用户名或邮箱已经存在'})
else:
return render(request, 'user_center/register.html', {'title': '注册', 'hide_header': True})
def login(request):
"""登录处理"""
if request.method == 'POST':
# pre_url = request.session.get('pre_url') # 上次访问的URL
pre_url = request.session.get('pre_url', '/')
try:
post = request.POST
username = post.get('username')
password = post.get('password')
user = UserInfo.objects.get(username=username)
remember = post.get('remember')
if sha1(password.encode('utf8')).hexdigest() == user.password:
# 密码校验成功
# 邮箱激活校验
if user.verification is False:
code = 403
msg = '请您登录邮箱点击激活邮箱链接'
else:
code = 200
msg = '登录成功'
# 保存用户信息到session
request.session['uid'] = user.id
request.session['username'] = user.username
else:
# 密码校验失败
code = 401
msg = '密码错误'
except:
# 密码校验失败
code = 402
msg = '用户名错误'
# 返回数据
response = JsonResponse({'code': code, 'msg': msg, 'pre_url': pre_url})
if code == 200 and remember == '1':
# 登录成功设置cookies
now = datetime.datetime.now()
date = now + datetime.timedelta(days=7)
response.set_cookie('username', user.username, expires=date)
return response
else:
username = request.COOKIES.get('username', '')
from_url = request.GET.get('from', '')
context = {
'title': '登录',
'username': username,
'hide_header': True,
'from_url': from_url
}
return render(request, 'user_center/login.html', context)
def username_exist(request):
"""
检测用户名是否重名
:param request:
:return:
"""
username = request.GET.get('username')
num = UserInfo.objects.filter(username=username).count()
if num > 0:
return JsonResponse({'code': 400, 'msg': '该用户名已存在,请您更换用户名注册'})
else:
return JsonResponse({'code': 200, 'msg': '该用户名可以注册'})
def email_exist(request):
"""
检测邮箱是否重名
:param request:
:return:
"""
email = request.GET.get('email')
num = UserInfo.objects.filter(email=email).count()
if num > 0:
return JsonResponse({'code': 400, 'msg': '该邮箱已被占用,请您更换邮箱注册'})
else:
return JsonResponse({'code': 200, 'msg': '该邮箱可以注册'})
def verify_email(request):
try:
get = request.GET
uid = get.get('id')
key = 'user_verify_email_key_' + str(uid)
user_token = get.get('token')
redis = StrictRedis()
redis_token = redis.get(key)
verify_flag = False # 邮箱激活成功与否flag
if user_token == bytes.decode(redis_token):
user = UserInfo.objects.get(id=uid)
if user.verification is False:
user.verification = True
user.save()
verify_flag = True
# 激活成功后,删除token
redis.delete(key)
except:
pass
if verify_flag is True:
return HttpResponseRedirect('/user/login/')
else:
return render(request, 'tips.html', {'info': '邮箱验证失败,请您重试'})
def find_password(request):
"""
找回密码
:param request:
:return:
"""
if request.method == 'POST':
post = request.POST
username = post.get('username')
email = post.get('email')
try:
user = UserInfo.objects.get(username=username)
if user.email == email:
# 发送验证邮件
token = uuid.uuid1()
redis = StrictRedis()
key = 'user_verify_fpwd_email_key_' + str(user.id)
redis.set(key, token)
html_message = "<a href='http://127.0.0.1:8000/user/verify_fpwd_email/?id=%d&token=%s'>找回密码验证</a>" % (user.id, token)
task.send_verify_email.delay('生鲜商城用户找回密码邮箱验证', user.email, html_message)
code = 200
msg = '请您登录邮箱,点击邮件里的邮箱验证链接'
else:
code = 401
msg = '输入的邮箱不正确'
except:
code = 400
msg = '该用户名尚未注册'
return JsonResponse({'code': code, 'msg': msg})
else:
return render(request, 'user_center/find_password.html')
def reset_password(request):
try:
post = request.POST
uid = post.get('id')
key = 'user_verify_fpwd_email_key_' + str(uid)
user_token = post.get('token')
pwd = post.get('pwd')
cpwd = post.get('cpwd')
redis = StrictRedis()
redis_token = redis.get(key)
if user_token == bytes.decode(redis_token) and pwd == cpwd:
user = UserInfo.objects.get(id=uid)
user.password = sha1(pwd.encode('utf8')).hexdigest()
user.save()
redis.delete(key)
info = '密码重置成功'
else:
info = '密码重置失败'
except:
info = '密码重置失败'
return render(request, 'tips.html', {'info': info})
def verify_fpwd_email(request):
"""
验证找回密码邮箱链接
:param request:
:return:
"""
try:
get = request.GET
uid = get.get('id')
key = 'user_verify_fpwd_email_key_' + str(uid)
user_token = get.get('token')
redis = StrictRedis()
redis_token = redis.get(key)
verify_flag = False # 邮箱验证成功与否flag
if user_token == bytes.decode(redis_token):
verify_flag = True
# redis.delete(key)
except:
pass
if verify_flag is True:
return render(request, 'user_center/reset_password.html', {'title': '重置密码', 'id': uid, 'token':user_token})
else:
return render(request, 'tips.html', {'info': '邮箱验证失败,请您重试'})
def center(request):
"""
用戶中心
:param request:
:return:
"""
# 用户信息
user = UserInfo.objects.get(id=request.session.get('uid'))
# 浏览记录
view_goods = []
view_goods_str = request.COOKIES.get('view_goods', '')
view_goods_list = view_goods_str.split(',')
view_goods_list.pop()
if view_goods_str != '':
for goods_id in view_goods_list:
goods = GoodsInfo.objects.get(id=goods_id)
view_goods.append(goods)
context = {
'title': '用户中心',
'app_name': '用户中心',
'user': user,
'view_goods': view_goods
}
return render(request, 'user_center/user_center_info.html', context)
def logout(request):
"""
退出登录
:param request:
:return:
"""
request.session.flush()
return HttpResponseRedirect('/')
def address(request):
"""地址列表"""
uid = request.session.get('uid')
address_list = AddressInfo.objects.filter(uid=uid)
if len(address_list) > 0:
new_list = list()
for add in address_list:
province_name = AreaInfo.get_province_name(add.province_id)
city_name = AreaInfo.get_city_name(add.province_id, add.city_id)
district_name = AreaInfo.get_district_name(add.province_id, add.city_id, add.district_id)
data={
'area': province_name + city_name + district_name,
'address': add.address,
'realname': add.realname,
'phone': add.phone,
'is_default': add.is_default,
'id': add.id,
'app_name': '用户中心',
'title': '收货地址列表',
}
new_list.append(data)
return render(request, 'user_center/user_center_site.html', {'address_list': new_list})
else:
return HttpResponseRedirect('/user/add_address/')
def add_address(request):
"""添加或编辑收货地址"""
if request.method == 'POST':
uid = request.session.get('uid')
post = request.POST
address_id = post.get('address_id')
if address_id != '':
# 编辑
address = AddressInfo.objects.get(id=address_id)
else:
# 新增
address = AddressInfo()
address.uid = uid
address.realname = post.get('realname')
address.province_id = post.get('province')
address.city_id = post.get('city')
address.district_id = post.get('district')
address.address = post.get('detail')
address.phone = post.get('phone')
address.save()
return HttpResponseRedirect('/user/address/')
else:
# 查询全部省份
# province = AreaInfo.objects.filter(Q(city_id=0) & Q(district_id=0))
province = AreaInfo.objects.filter(city_id=0, district_id=0)
context = {
'app_name': '用户中心',
'title': '添加收货地址',
'province': province
}
return render(request, 'user_center/user_center_site_edit.html', context)
def get_address_city(request):
"""ajax获取一个省下的城市"""
province_id = request.GET.get('province_id')
city_list = AreaInfo.objects.filter(province_id=province_id, city_id__gt=0, district_id=0).values('city_id', 'name')
return JsonResponse({"city_list": list(city_list)})
def get_address_district(request):
"""ajax获取一个市下的县区"""
city_id = request.GET.get('city_id')
district_list = AreaInfo.objects.filter(city_id=city_id,district_id__gt=0).values('district_id', 'name')
return JsonResponse({'district_list': list(district_list)})
def edit_address(request, address_id):
"""编辑收货地址信息"""
province = AreaInfo.objects.filter(city_id=0, district_id=0)
address_info = AddressInfo.objects.get(id=address_id)
city = AreaInfo.objects.filter(province_id=address_info.province_id,city_id__gt=0, district_id=0)
district = AreaInfo.objects.filter(province_id=address_info.province_id, city_id=address_info.city_id, district_id__gt=0)
context = {
'province': province,
'address_info': address_info,
'city': city,
'district': district,
'app_name': '用户中心',
'title': '编辑收货地址',
}
return render(request, 'user_center/user_center_site_edit.html',context)
def del_address(request, address_id):
"""删除地址"""
try:
AddressInfo.objects.filter(id=address_id).delete()
return JsonResponse({'code': 200, 'msg': '删除成功'})
except Exception:
return JsonResponse({'code': 400, 'msg': '删除失败'})
@transaction.atomic
def set_default_address(request, address_id):
"""设置默认地址"""
address = AddressInfo.objects.get(id=address_id)
# 记录事务开始保存点
save_point = transaction.savepoint()
try:
# 设置(取消)默认地址
address.is_default = not address.is_default
address.save()
undefault_address_id = 0 # 记录被取消默认地址的id
if not address.is_default:
# 如果当前选中的不是默认地址
# 就要考虑有没有其他地址是默认地址
uid = request.session.get('uid')
address_list = AddressInfo.objects.filter(uid=uid, is_default=True)
# 如果有其他地址是已经被设置为默认地址,就把这个取消掉
if len(address_list) == 1:
address_list[0].is_default = False
undefault_address_id = address_list[0].id
address_list[0].save()
# 事务提交
transaction.savepoint_commit(save_point)
return JsonResponse({'code': 200, 'msg': '设置成功', 'undefault_address_id': undefault_address_id})
except Exception:
# 事务回滚
transaction.savepoint_rollback(save_point)
return JsonResponse({'code': 400, 'msg': '设置失败'})
def order(request):
"""用户订单列表"""
current_page = int(request.GET.get('page', '1'))
uid = request.session['uid']
order_list = Order.objects.filter(user_id=uid).order_by('-add_time')
paginator = Paginator(order_list, 1)
order_list = paginator.page(current_page)
context = {
'title': '用户中心',
'order_list': order_list
}
return render(request, 'user_center/user_center_order.html', context)
def del_view_goods(request):
"""删除浏览记录"""
try:
response = JsonResponse({'code': 200, 'msg': '删除成功'})
goods_id = request.POST.get('goods_id')
view_goods = request.COOKIES.get('view_goods').split(',')
# goods_id 为0 时,删除全部
# 不为0时,删除某一个
if goods_id != '0':
if goods_id in view_goods:
view_goods.remove(goods_id)
view_goods_str = ','.join(view_goods)
response.set_cookie('view_goods', view_goods_str, max_age=7 * 86400)
else:
response.set_cookie('view_goods', '', max_age=7 * 86400)
return response
except Exception:
return JsonResponse({'code': 400, 'msg': '删除失败'})
五、论文参考
- 计算机毕业设计选题推荐-网上产品商城论文参考:
六、系统视频
网上产品商城项目视频:
结语
计算机毕业设计选题推荐-网上产品商城-Python项目实战
大家可以帮忙点赞、收藏、关注、评论啦~
源码获取:⬇⬇⬇
精彩专栏推荐⬇⬇⬇
Java项目
Python项目
安卓项目
微信小程序项目