示例#1
0
    async def post(self):
        try:
            libs.validator.space_id(self.post_data.get("space_id"))
            libs.validator.account_id(self.post_data.get("account_id"))

        except libs.validator.ValidationError as e:
            self.send_to_client(-1, message=e.__str__())
            return

        growth_list_key = 'growth_list:{}'.format(
            zbase62.decode(self.post_data.get('space_id')))
        growth_list = rd.redis_get(growth_list_key)
        growth_list = json.loads(str(growth_list,
                                     encoding="utf-8")) if isinstance(
                                         growth_list, bytes) else growth_list
        if not growth_list:
            pb_growth_list = await RecordServer().get_growth_list(
                account_id=zbase62.decode(self.post_data.get("account_id")),
                space_id=zbase62.decode(self.post_data.get('space_id')),
                creator_id=self.current_user.account_id,
                request_id=self.request_id)
            if pb_growth_list:
                growth_list = []
                for growth in pb_growth_list.growth_list:
                    growth_list.append(GrowthDetail(growth).growth_detail)
                rd.redis_set(growth_list_key, json.dumps(growth_list),
                             Config().redis.get("expire_list"))

        if growth_list is not None:
            self.send_to_client(0, message='成功获取生长记录详情', response=growth_list)
            return

        raise HTTPError(500, "get growth list failed", reason="服务器出错,请联系客服解决")
示例#2
0
    async def post(self):
        mobile = self.post_data.get('mobile', '').strip()
        smscode = self.post_data.get('smscode', '').strip()

        errors = self._check_input({"mobile": mobile, "smscode": smscode})
        if errors:
            err = ''
            for item, er in errors.items():
                err = er
                break
            self.send_to_client(error_id=error.input_error.id,
                                message=err,
                                response=errors)
            return

        # Check smscode
        mobile_smscode = rd.redis_get('verify:{}'.format(mobile))

        if mobile_smscode:
            mobile_smscode = mobile_smscode.decode()

        if mobile_smscode != smscode:
            self.send_to_client(-1, '验证码错误')
            return

        try:
            mobile_new = pbaccount_pb2.Mobile(country_code="86", mobile=mobile)
            msg = pbaccount_pb2.AccountUpdateRequest(auth_token=self.token,
                                                     mobile_new=mobile_new,
                                                     app_id=self.app_id_int64)
            await MServer().call("account-server", "Update", msg,
                                 self.request_id)

            pb_userinfo = await AccountServer().get_userinfo(
                account_id=self.current_user.account_id,
                app_id=self.app_id_int64,
                request_id=self.request_id)
            if pb_userinfo:
                account = self.current_user
                await account.set_userinfo(pb_userinfo)
                self.send_to_client(0, message='修改成功', response=account.dump())
                return

            raise HTTPError(500, "get userinfo failed", reason="服务器出错,请联系客服解决")

        except grpc.RpcError as e:
            # except grpc._channel._Rendezvous as e:
            msg = "code: {}, details:{}".format(e.code(), e.details())
            if e.code().__dict__.get('_name_') == 'ALREADY_EXISTS':
                raise HTTPError(-1, "mobile already exists", reason="该手机号已存在!")
            raise HTTPError(500, msg, reason=str(e.details()))
示例#3
0
    async def post(self):
        # todo: 接种时间逻辑性校验
        try:
            libs.validator.space_id(self.post_data.get('space_id'))
        except libs.validator.ValidationError as e:
            self.send_to_client(-1, message=e.__str__())
            return
        injection_detail_key = 'injection_detail:{}'.format(zbase62.decode(self.post_data.get('space_id')))
        injection_detail = rd.redis_get(injection_detail_key)
        injection_detail = json.loads(str(injection_detail, encoding="utf-8")) if isinstance(injection_detail,
                                                                                             bytes) else injection_detail
        if not injection_detail:
            pb_space_detail = await SpaceServer().get_space_details(
                space_id=zbase62.decode(self.post_data.get('space_id')),
                request_id=self.request_id)
            if pb_space_detail:
                pb_detail_list = await VaccineServer().get_vaccine_detail_list(request_id=self.request_id)
                pb_injection_log = await VaccineServer().get_injection_details(account_id=pb_space_detail.owner_id,
                                                                               request_id=self.request_id,
                                                                               space_id=zbase62.decode(
                                                                                   self.post_data.get('space_id')),
                                                                               creator_id=self.current_user.account_id)

                inject_dict = {}
                if pb_injection_log:
                    for inject in pb_injection_log.inject_detail:
                        i = InjectDetail(inject).inject_detail
                        i["date_of_inoculation"] = time.strftime("%Y-%m-%d",
                                                                 time.localtime(inject.date_of_inoculation.seconds))
                        inject_dict[(i.get("vaccine_id"), i.get("injection_no"))] = i

                if pb_detail_list:
                    injection_detail = []
                    for vaccine in pb_detail_list.vaccines:
                        v = Vaccine(vaccine).vaccine
                        vd = inject_dict.get((v.get("vaccine_id"), v.get("injection_no")))
                        v['is_injected'] = vd.get("is_injected") if vd else None
                        v['date_of_inoculation'] = vd.get("date_of_inoculation") if vd else None
                        injection_detail.append(v)
                rd.redis_set(injection_detail_key, json.dumps(injection_detail), Config().redis.get("expire_list"))
        if injection_detail is not None:
            self.send_to_client(0, message='成功获取接种详情', response=injection_detail)
            return

        raise HTTPError(500, "get space failed", reason="服务器出错,请联系客服解决")
示例#4
0
    async def post(self):
        try:
            libs.validator.vaccine_id(self.post_data.get('vaccine_id'))
        except libs.validator.ValidationError as e:
            self.send_to_client(-1, message=e.__str__())
            return
        vaccine_detail_key = 'vaccine_detail:{}'.format(self.post_data.get('vaccine_id'))
        vaccine_detail = rd.redis_get(vaccine_detail_key)
        vaccine_detail = json.loads(str(vaccine_detail, encoding="utf-8")) if isinstance(vaccine_detail,
                                                                                         bytes) else vaccine_detail
        if not vaccine_detail:
            pb_detail = await VaccineServer().search_vaccine(vaccine_id=self.post_data.get("vaccine_id"),
                                                             request_id=self.request_id)
            vaccine_detail = InjectDetail(pb_detail).inject_detail
            rd.redis_set(vaccine_detail_key, json.dumps(vaccine_detail), Config().redis.get("expire_list"))
        if vaccine_detail is not None:
            self.send_to_client(0, message='查找成功', response=vaccine_detail)
            return

        raise HTTPError(500, "search vaccine failed", reason="服务器出错,请联系客服解决")
示例#5
0
    async def post(self):
        mobile = self.post_data.get('mobile', '')
        smscode = self.post_data.get('smscode', '')

        errors = self._check_input({"mobile": mobile, "smscode": smscode})
        if errors:
            err = ''
            for item, er in errors.items():
                err = er
                break
            self.send_to_client(error_id=error.input_error.id, message=err)
            return

        # Check smscode
        mobile_smscode = rd.redis_get('verify:{}'.format(mobile))

        if mobile_smscode:
            mobile_smscode = mobile_smscode.decode()

        if mobile_smscode != smscode:
            self.send_to_client(-1, '登陆验证码错误')
            return

        # Exists Mobile
        exists_account_already = False
        try:
            exists_account_already = await AccountServer(
            ).exists_account_by_mobile(mobile, request_id=self.request_id)
        except grpc.RpcError as e:
            self.send_to_client(error_id=500, message='服务器内部错误,请联系管理员确认')
            return

        pb_account = None
        if not exists_account_already:
            # not exists, create account
            pb_account = await AccountServer().create_account(
                mobile=mobile,
                country_code="86",
                app_id=self.app_id_int64,
                request_id=self.request_id)
            # 分配空间
            result = await MembershipServer().set_total_storage_change(
                account_id=pb_account.account_id,
                changed_value=Config().membership.get("register_default_size"),
                title=Config().membership.get("register_default_title"),
                details=Config().membership.get("register_default_details"),
                request_id=self.request_id)

        else:
            # exists, get the account
            pb_account = await AccountServer().get_account_by_mobile(
                mobile=mobile,
                country_code="86",
                app_id=self.app_id_int64,
                request_id=self.request_id)

        # make Account Model
        if pb_account is None:
            self.send_to_client(error_id=500, message='服务器内部错误,请联系管理员确认')
            return
        account = Account(pb_account)

        # get account userinfo
        if account.status == pbaccount_pb2.STATUS_ACTIVATED:
            rd.redis_del('verify:{}'.format(mobile))
            pb_userinfo = await AccountServer().get_userinfo(
                account.account_id,
                app_id=self.app_id_int64,
                request_id=self.request_id)
            await account.set_userinfo(pb_userinfo)
            self.send_to_client(0, message='登陆成功', response=account.dump())
            return

        status_error = {0: "未知状态的账号", 2: "未激活账号", 3: "锁定并暂停账号或封号", 4: "账号已注销"}
        self.send_to_client(-1, message=status_error.get(account.status))