Example #1
0
 def get(self, cid):
     """
     用户访问会员卡页面
     1. 如果已经有会员卡,返回信息
     2. 如果没有
         1. 如果会员卡允许自动创建,则自动创建
         2. 如果不允许自动创建,按照要求填写表单
     """
     card = self.card_manager.get_card_by_cid(cid)
     openid = self.get_argument('i', None)
     if not openid or not card:
         raise HTTPError(404)
     fans = self.fans_manager.get_fans_by_openid(openid)
     if not fans:
         pass
     account = self.account_manager.get_account_by_aid(card.aid)
     card_member = self.card_manager.get_user_card_info(cid, openid)
     rule = self.card_manager.get_account_card_rule(card.aid)
     if card_member:
         historys = self.card_manager.get_history_by_openid(card.aid, openid)
         self.render('front/card.html', member=card_member, card=card, account=account, rule=rule, historys=historys)
         return
     if card.register == 1:
         # 自动注册
         card_id = card.id
         num = key_util.generate_digits_starts_with(str(card_id), 7)
         num = str(card_id) + num
         self.card_manager.save_member(card.aid, cid, num, openid, '', '', '')
         card_member = self.card_manager.get_user_card_info(cid, openid)
         self.render('front/card.html', member=card_member, account=account, card=card)
         return
     else:
         # 返回注册卡片页面
         m = self.get_argument('m', None)
         self.render('front/card_reg.html', card=card, openid=openid, account=account, m=m)
Example #2
0
 def post(self, *args, **kwargs):
     """提交领取会员卡的表单"""
     result = {'r': 0}
     openid = self.get_argument('openid', None)
     mobile = self.get_argument('mobile', None)
     address = self.get_argument('address', None)
     sex = self.get_argument('sex', None)
     birthday = self.get_argument('birthday', None)
     name = self.get_argument('name', '')
     if not openid:
         result['error'] = '出了点错误,重新注册吧~'
         self.write(result)
         return
     card = self.card_manager.get_card_by_cid(args[0])
     if not card:
         result['error'] = '你来到了一个不存在的页面~'
         self.write(result)
         return
     if card.mobile and not mobile:
         result['error'] = '手机号一定要填哦~'
         self.write(result)
         return
     if card.address and not address:
         result['error'] = '地址一定要填哦~'
         self.write(result)
         return
     if card.sex and not sex:
         result['error'] = '性别一定要选哦~'
         self.write(result)
         return
     if card.birthday and not birthday:
         result['error'] = '生日一定要填哦~'
         self.write(result)
         return
     card_id = card.id
     num = key_util.generate_digits_starts_with(str(card_id), 7)
     num = str(card_id) + num
     self.card_manager.save_member(card.aid, card.cid, num, openid, name, mobile, address, sex, birthday)
     result['r'] = 1
     result['openid'] = openid
     self.write(result)
     return