def showStore(self): try: page = int(self.POST.get('page')) limit = int(self.POST.get('limit')) name = change(self.POST.get('name')) price_min = 0 if self.POST.get( 'price_min') == '' else self.POST.get('price_min') price_max = 99999999999 if self.POST.get( 'price_max') == '' else self.POST.get('price_max') storeType = change(self.POST.get('type')) boss = change(self.POST.get('boss')) shopData = shop.objects.filter(name__contains=name, type__contains=storeType, boss__contains=boss, area__range=[price_min, price_max]) total = len(shopData) showData = shopData[limit * (page - 1):limit * page] data = list() for i in showData: content = dict() content['id'] = i.id content['name'] = i.name content['area'] = i.area content['boss'] = i.boss content['type'] = i.type data.append(content) return JsonResponse(returnMsg.Success(data=data, total=total)) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)))
def addEmployee(self): try: name = self.POST.get('name') age = self.POST.get('age') sex = self.POST.get('sex') createTime = self.POST.get('createTime') salary = self.POST.get('salary') shopId = self.POST.get('shopId') emp = employee.objects.create(name=name, age=age, sex=sex, createTime=createTime, salary=salary, shopId=shopId) emp.save() return JsonResponse(returnMsg.Success(msg='添加店员成功'), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))
def updateEmployee(self): try: empId = self.POST.get('id') name = self.POST.get('name') age = self.POST.get('age') sex = self.POST.get('sex') createTime = self.POST.get('updateTime') salary = self.POST.get('salary') shopId = self.POST.get('shopId') employee.objects.filter(id=empId).update(name=name, age=age, sex=sex, createTime=createTime, salary=salary, shopId=shopId) return JsonResponse(returnMsg.Success(msg='修改成功'), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))
def addGoods(self): try: name = self.POST.get('name') goodsType = self.POST.get('type') goodsSum = self.POST.get('sum') price = self.POST.get('price') per = self.POST.get('per') shopId = self.POST.get('shopId') go = goods.objects.create(name=name, type=goodsType, sum=goodsSum, price=price, per=per, shopId=shopId) go.save() return JsonResponse(returnMsg.Success(msg='添加成功'), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))
def updateGoods(self): try: goodsId = self.POST.get('id') name = self.POST.get('name') goodsType = self.POST.get('type') goodsSum = self.POST.get('sum') price = self.POST.get('price') per = self.POST.get('per') shopId = self.POST.get('shopId') # print(goodsId, name, goodsType, goodsSum, price, per, shopId) goods.objects.filter(id=goodsId).update(name=name, type=goodsType, sum=goodsSum, price=price, per=per, shopId=shopId) return JsonResponse(returnMsg.Success(msg='修改成功'), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))
def showGoods(self): try: name = change(self.POST.get('name')) goodsType = change(self.POST.get('type')) shopId = self.POST.get('shop') if shopId == '': allGoods = goods.objects.filter(name__contains=name, type__contains=goodsType) else: allGoods = goods.objects.filter(name__contains=name, type__contains=goodsType, shopId=shopId) total = len(allGoods) page = int(self.POST.get('page')) limit = int(self.POST.get('limit')) showGoods = allGoods[limit * (page - 1):limit * page] data = list() for go in showGoods: content = dict() content['id'] = go.id content['name'] = go.name content['type'] = go.type content['sum'] = go.sum content['price'] = go.price content['per'] = go.price content['shopId'] = go.shopId content['shopname'] = shop.objects.get(id=go.shopId).name data.append(content) return JsonResponse(returnMsg.Success(data=data, total=total), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Success(msg=str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))
def delEmployee(self): try: empId = self.POST.get('id') employee.objects.filter(id=empId).delete() return JsonResponse(returnMsg.Success(msg='删除成功'), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))
def delStore(self): try: shopId = self.POST.get('id') emp = employee.objects.filter(shopId=shopId) if len(emp) > 0: msg = '店铺含有员工不能删除' else: goods.objects.filter(shopId=shopId).delete() shop.objects.filter(id=shopId).delete() msg = '删除成功' return JsonResponse(returnMsg.Success(msg=msg), safe=False, json_dumps_params={'ensure_ascii': False}) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params={'ensure_ascii': False})
def aStore(self): try: name = self.POST.get('name') area = self.POST.get('area') boss = self.POST.get('boss') storeType = self.POST.get('type') shopStore = shop.objects.create(name=name, area=area, boss=boss, type=storeType) shopStore.save() return JsonResponse(returnMsg.Success(msg='添加成功'), safe=False, json_dumps_params={'ensure_ascii': False}) except Exception as e: print(e) return JsonResponse(returnMsg.Error())
def uLogin(self): if self.POST: username = self.POST.get('username') password = self.POST.get('password') # 进行登录认证, user = authenticate(username=username, password=password) # 判断用户是否存在 if user is not None: if user.is_superuser: # 这里的登录, 表示的是将用户信息添加到session中 login(self, user) return JsonResponse(returnMsg.Success(msg='登录成功')) else: return JsonResponse(returnMsg.Error(msg='抱歉您没有这个权限')) else: return JsonResponse(returnMsg.Error(msg='用户名或密码错误')) else: return render(self, 'login.html')
def showAllStore(self): try: allStore = shop.objects.all() data = list() for store in allStore: content = dict() content['id'] = store.id content['name'] = store.name data.append(content) return JsonResponse(returnMsg.Success(data=data), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params={'ensure_ascii': False})
def updateStore(self): print(self) try: shopId = self.POST.get('id') name = self.POST.get('name') area = self.POST.get('area') boss = self.POST.get('boss') storeType = self.POST.get('type') print(shopId, name, area, boss, storeType) shop.objects.filter(id=shopId).update(name=name, area=area, boss=boss, type=storeType) return JsonResponse(returnMsg.Success(msg='修改成功'), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params={'ensure_ascii': False})
def showEmployee(self): try: page = int(self.POST.get('page')) limit = int(self.POST.get('limit')) salary_min = 0 if self.POST.get( 'salary_min') == '' else self.POST.get('salary_min') salary_max = 9999999999999 if self.POST.get( 'salary_max') == '' else self.POST.get('salary_max') age_min = 0 if self.POST.get('age_min') == '' else self.POST.get( 'age_min') age_max = 9999999999999 if self.POST.get( 'age_max') == '' else self.POST.get('age_max') shopId = self.POST.get('shopId') createTime = self.POST.get('createTime') if createTime == '': createTime = '0001-1-1 至 9999-12-31' times = createTime.split('至') start_time = datetime.datetime(year=int(times[0].split('-')[0]), month=int(times[0].split('-')[1]), day=int(times[0].split('-')[2]), hour=0, minute=0, second=0) end_time = datetime.datetime(year=int(times[1].split('-')[0]), month=int(times[1].split('-')[1]), day=int(times[1].split('-')[2]), hour=0, minute=0, second=0) sex = change(self.POST.get('sex')) name = change(self.POST.get('name')) # print(name, sex, age_min, age_max, salary_min, salary_max, shopId, createTime) if shopId == '': allEmployee = employee.objects.filter( name__contains=name, sex__contains=sex, salary__range=[salary_min, salary_max], age__range=[age_min, age_max], createTime__range=[start_time, end_time]) else: allEmployee = employee.objects.filter( name__contains=name, sex__contains=sex, salary__range=[salary_min, salary_max], age__range=[age_min, age_max], createTime__range=[start_time, end_time], shopId=shopId) total = len(allEmployee) showEmployees = allEmployee[limit * (page - 1):limit * page] data = list() for emp in showEmployees: content = dict() content['id'] = emp.id content['name'] = emp.name content['age'] = emp.age content['sex'] = emp.sex content['createTime'] = emp.createTime.strftime('%Y-%m-%d') content['salary'] = emp.salary content['shopId'] = emp.shopId content['shop'] = shop.objects.get(id=emp.shopId).name data.append(content) return JsonResponse(returnMsg.Success(data=data, total=total), safe=False, json_dumps_params=({ 'ensure_ascii': False })) except Exception as e: return JsonResponse(returnMsg.Error(msg=str(e)), safe=False, json_dumps_params=({ 'ensure_ascii': False }))