def is_user(self, request): """ 查询是否为本单位会员 """ data = request.data name = data['name'] phone = data['phone'] id = data['id'] try: s = MbrCommon.objects.get(mbse_name=name, mbr_phone=phone, mbr_id_num=id) if s.mbse_status == '2006' and s.mbse_user.identity != '1000': return FormatResponse(code=200, msg="您是本协会的会员", data="", status=status.HTTP_200_OK) else: return FormatResponse(code=400, msg="未查询到符合条件的信息或申请正在审核中", data="", status=status.HTTP_400_BAD_REQUEST) except Exception as e: return FormatResponse(code=400, msg="未查询到符合条件的信息或申请正在审核中", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def create(self, request): """ 新建会员申请 """ rawdata = request.data try: s = MbrCommonSerializers(data=rawdata, context={'request': request}) if s.is_valid(): s.validated_data.mbse_user = request.user.id s.save() return FormatResponse(code=201, msg="提交成功", data=s.data, status=status.HTTP_201_CREATED) else: return FormatResponse(code=400, msg="错误", data=str(s.errors), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return FormatResponse(code=400, msg="提交失败", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def update(self, request, pk): """ 编辑理事单位申请 """ try: s = MbrInc.objects.get(id=pk) if s.mbse_status == '2002': s.mbse_status = "2001" s.save() ser = MbrIncSerializers(instance=s, data=request.data, context={'request': request}) if ser.is_valid(): ser.save() return FormatResponse(code=201, msg="修改成功", data=ser.data, status=status.HTTP_201_CREATED) else: return FormatResponse(code=400, msg="错误", data=str(ser.errors), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def update(self, request, pk): """ 更新订单 """ try: s = Order.objects.get(id=pk) print(request.data['status']) if request.data['status'] == "3002" or request.data[ 'status'] == "3003": return FormatResponse(code=400, msg="错误", data="权限不足", status=status.HTTP_400_BAD_REQUEST) ser = OrderSerializers(instance=s, data=request.data, context={'request': request}) if ser.is_valid(): ser.save() return FormatResponse(code=201, msg="修改成功", data=ser.data, status=status.HTTP_201_CREATED) else: return FormatResponse(code=400, msg="错误", data=str(ser.errors), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def list(self, request, *args, **kwargs): try: response = super().list(request, *args, **kwargs) return FormatResponse(code=200, msg="获取成功", data=response.data, status=status.HTTP_200_OK) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def IncJudgeDeny(self, request, pk): try: s = MbrInc.objects.get(id=pk) s.mbse_status = '2002' s.save() return FormatResponse(code=200, msg="成功", data="", status=status.HTTP_200_OK) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def MbrJudgePass(self, request, pk): try: s = Order.objects.get(id=pk) s.status = '3003' s.save() return FormatResponse(code=200, msg="成功", data="", status=status.HTTP_200_OK) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def post(self, request): try: data = request.data new_pwd = data["password"] usr = CustomUser.objects.get(id=request.user.id) usr.set_password(new_pwd) usr.save() return FormatResponse(data=data, msg="修改成功", code=200, status=status.HTTP_200_OK) except Exception as e: return FormatResponse(data=e, msg="修改失败", code=400, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk): """ 删除申请,此处的id为关联活动id """ try: s = Audit.objects.get(relate_activity__id=pk, audit_user=request.user) s.delete() return FormatResponse(code=200, msg="删除成功", data="", status=status.HTTP_200_OK) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def get(self, request): usr = CustomUser.objects.get(id=request.user.id) s = CustomUserSerializers(instance=usr) data = s.data data["password"] = "" return FormatResponse(data=data, msg="获取成功", code=200, status=status.HTTP_200_OK)
def uploadImg(self, request, pk): try: s = MbrCommon.objects.get(id=pk) ser = MbrAvatarSerializers(instance=s, data=request.data) if ser.is_valid(): ser.save() return FormatResponse(code=200, msg="成功", data=ser.data, status=status.HTTP_200_OK) else: return FormatResponse(code=400, msg="错误", data=str(s.errors), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)
def get(self, request, *args, **kwargs): # try: m = MbrCommon.objects.get(mbse_user=request.user) u = request.user year = m.mbr_cert_date.split("-")[0] mouth = m.mbr_cert_date.split("-")[1] day = m.mbr_cert_date.split("-")[2] print(m.mbr_job) print(m.mbr_avatar) base64img = generateCert(request, u.get_identity_display(), m.mbse_code, m.mbse_name, m.mbr_job, m.mbr_edu, m.mbr_graduate, m.mbr_cert, m.mbr_title,year,mouth,day,avatar=m.mbr_avatar) return FormatResponse(code=200, msg="成功", data={"base64img": base64img}, status=status.HTTP_200_OK)
def post(self, request, *args, **kwargs): data = request.data u = request.user try: # print(data) type = data["type"] code = data["code"] name = data["name"] gender = data["gender"] unit = data["unit"] grade = data["grade"] title = data["title"] avai_year = data["avai_year"] avai_mouth = data["avai_mouth"] avai_day = data["avai_day"] avatar = data["avatar"] base64img = generateCert(request, type, code, name, gender, unit, grade, title, avai_year, avai_mouth, avai_day, u, avatar, b64=True) return FormatResponse(code=200, msg="成功", data={"base64img": base64img}, status=status.HTTP_200_OK) except Exception as e: return FormatResponse(code=400, msg="错误", data=str(e), status=status.HTTP_400_BAD_REQUEST)