コード例 #1
0
 def has_collect(cls, redpacket_id, open_id=None):
     redpacket_id = str2objectid(redpacket_id)
     rpl = RedPacketLog.objects.filter(
         redpacket_id=redpacket_id,
         open_id=open_id,
         status=RedPacketLog.STATUS_DONE).first() if open_id else None
     has_collect, value = (True, rpl.value) if rpl else (False, 0)
     return has_collect, value / 100.0
コード例 #2
0
 def collect_redpacket(cls, redpacket_id, open_id):
     redpacket_id = str2objectid(redpacket_id)
     rp = cls.objects.filter(
         _id=redpacket_id, left_count__gte=1).update_one(inc__left_count=-1)
     if not rp:
         return False,
     filters = dict(redpacket_id=redpacket_id,
                    status=RedPacketLog.STATUS_UN,
                    open_id__exists=False)
     rpl = RedPacketLog.objects.filter(**filters).first()
     if not rpl:
         return False,
     modify = {
         'status': RedPacketLog.STATUS_DONE,
         'open_id': open_id,
         'last_modify': datetime.datetime.now()
     }
     result = rpl.modify(query=filters, **modify)
     if not result:
         return False,
     return rpl.value, rpl.pk
コード例 #3
0
 def set_info(self,
              user_id,
              nickname=None,
              avatar=None,
              gender=None,
              province=None,
              city=None,
              intro=None):
     user_id = formatter.str2objectid(user_id)
     info = dict(nickname=nickname,
                 avatar=avatar,
                 gender=gender,
                 province=province,
                 city=city,
                 intro=intro)
     user = self.proto_cls.objects.filter(_id=user_id).first()
     if not user:
         logger.error(msg='set user info err:%s' % (user_id))
         return False
     r = user.modify({}, **info)
     return 1 if r else False
コード例 #4
0
 def get_packet_all(cls, redpacket_id):
     redpacket_id = str2objectid(redpacket_id)
     packet = cls.objects.filter(_id=redpacket_id).first()
     if not packet:
         return
     return packet
コード例 #5
0
 def get_packet(cls, redpacket_id):
     redpacket_id = str2objectid(redpacket_id)
     packet = cls.objects.filter(
         _id=redpacket_id,
         expire_time__gte=datetime.datetime.now()).first()
     return packet