@login_required
def add_client(request):
if request.method == "POST":
name = request.POST.get("name")
telephone = request.POST.get("telephone")
address = request.POST.get("address")
client = Client.objects.filter(name=name).first()
if client:
return JsonResponse({
"code": -1,
"msg": "该客户已存在"
})
else:
client1 = Client.objects.filter(telephone=telephone).first()
if client1:
return JsonResponse({
"code": -1,
"msg": "手机号重复"
})
else:
Client.objects.create(name=name, telephone=telephone, address=address)
return JsonResponse({
"code": 0,
"msg": "添加成功"
})
else:
return JsonResponse({
"code": -1,
"msg": "只能进行post请求"
})
@login_required
def outbound(request):
if request.method == "POST":
gid = request.POST.get("gid")
num = request.POST.get("num")
cid = request.POST.get("cid")
goods = Goods.objects.filter(id=gid).first()
if goods:
if int(num) <= int(goods.num):
client = Client.objects.filter(id=cid).first()
if client:
goods.num = int(goods.num) - int(num)
goods.save()
if goods.num == 0:
goods.delete()
Orders.objects.create(cname_id=cid, gname_id=gid, num=num)
return JsonResponse({
"code": 0,
"msg": "出库成功"
})
else:
return JsonResponse({
"code": -1,
"msg": "客户不存在,请重试"
})
else:
return JsonResponse({
"code": -1,
"msg": "出库数量大于剩余数量"
})
else:
return JsonResponse({
"code": -1,
"msg": "商品不存在,请重试"
})
else:
return JsonResponse({
"code": -1,
"msg": "只能进行post请求"
})
@login_required
def update_client(request):
if request.user.level in ["超级会员", "钻石会员"]:
if request.method == "POST":
id = request.POST.get("id")
name = request.POST.get("name")
telephone = request.POST.get("telephone")
address = request.POST.get("address")
client = Client.objects.filter(id=id).first()
if client:
client.name = client.name if not name else name
client.telephone = client.telephone if not telephone else telephone
client.address = client.address if not address else address
client.save()
return JsonResponse({
"code": 0,
"msg": "修改成功"
})
else:
return JsonResponse({
"code": -1,
"msg": "该客户不存在"
})
else:
return JsonResponse({
"code": -1,
"msg": "只能进行post请求"
})
else:
return JsonResponse({
"code": -1,
"msg": "该功能需要开通钻石会员"
})
def find(request):
if request.user.level in ["钻石会员", "超级会员"]:
if request.method == "POST":
content = request.POST.get("content")
id = request.POST.get("id")
if content == "客户":
datas = Client.objects.filter(id=id).first()
if datas:
data = {"id": datas.id, "name": datas.name, "telephone": datas.telephone, "address": datas.address}
return JsonResponse({
"code": 0,
"msg": "查询成功",
"data": data,
})
else:
return JsonResponse({
"code": -1,
"msg": "没有该客户",
})
elif content == "订单":
datas = Orders.objects.filter(id=id).first()
if datas:
data = {"id": datas.id, "num": datas.num, "cid": datas.cname_id, "gid": datas.gname_id,
"time": datas.time.strftime("%Y-%m-%d %H:%M:%S")}
return JsonResponse({
"code": 0,
"msg": "查询成功",
"data": data,
})
else:
return JsonResponse({
"code": -1,
"msg": "没有该订单"
})
elif content == "商品":
datas = Goods.objects.filter(id=id).first()
if datas:
data = {"id": datas.id, "name": datas.name, "num": datas.num, "price": datas.price}
return JsonResponse({
"code": 0,
"msg": "查询成功",
"data": data,
})
else:
return JsonResponse({
"code": -1,
"msg": "没有该商品"
})
else:
return JsonResponse({
"code": -1,
"msg": "只能进行post请求"
})
else:
return JsonResponse({
"code": -1,
"msg": "该功能需要开通钻石会员"
})
@login_required
def update_goods(request):
if request.user.level in ["超级会员", "钻石会员"]:
if request.method == "POST":
id = request.POST.get("id")
name = request.POST.get("name")
price = request.POST.get("price")
goods = Goods.objects.filter(id=id).first()
if client:
goods.name = goods.name if not name else name
goods.price = goods.price if not price else price
goods.save()
return JsonResponse({
"code": 0,
"msg": "修改成功"
})
else:
return JsonResponse({
"code": -1,
"msg": "该客户不存在"
})
else:
return JsonResponse({
"code": -1,
"msg": "只能进行post请求"
})
else:
return JsonResponse({
"code": -1,
"msg": "该功能需要开通钻石会员"
})
def delete(request):
if request.user.level in ["超级会员", "钻石会员"]:
if request.method == "POST":
content = request.POST.get("content")
id = request.POST.get("id")
if content == "客户":
data = Client.objects.filter(id=id).first()
if data:
data.delete()
return JsonResponse({
"code": 0,
"msg": "删除成功",
})
else:
return JsonResponse({
"code": -1,
"msg": "没有该客户",
})
elif content == "订单记录":
data = Orders.objects.filter(id=id).first()
if data:
data.delete()
return JsonResponse({
"code": 0,
"msg": "删除成功",
})
else:
return JsonResponse({
"code": -1,
"msg": "没有该订单"
})
elif content == "商品":
data = Goods.objects.filter(id=id).first()
if data:
data.delete()
return JsonResponse({
"code": 0,
"msg": "删除成功",
})
else:
return JsonResponse({
"code": -1,
"msg": "没有该商品"
})
else:
return JsonResponse({
"code": -1,
"msg": "只能进行post请求"
})
else:
return JsonResponse({
"code": -1,
"msg": "该功能需要开通钻石会员"
})
简单的django项目仓库管理系统,可用作期末课程设计, 也可做毕业设计(可视化项目),有需要请私信,欢迎大家来打扰