コード例 #1
0
ファイル: vote.py プロジェクト: zhenchaozhu/starmachine
 def add(cls, vote_id, content):
     db = DbManager().db
     create_time = datetime.now()
     sql = 'insert into {table} (vote_id, content, create_time) values (%s, %s, %s)'.format(
         table=cls.table)
     option_id = db.execute(sql, vote_id, content, create_time)
     return option_id and cls.get(option_id)
コード例 #2
0
ファイル: lots.py プロジェクト: zhenchaozhu/starmachine
 def get_random_lots(cls):
     db = DbManager().db
     sql = 'select * from {table} as t1 join(select round(rand() * ((select max(id) from {table}) - ' \
           '(select min(id) from {table})) + (select min(id) from {table})) as id) as t2 where ' \
           't1.id >= t2.id ORDER BY t1.id LIMIT 1'.format(table=cls.table)
     rst = db.get(sql)
     return rst and cls(**rst)
コード例 #3
0
 def is_room_silent_user(cls, room_id, user_id):
     db = DbManager().db
     sql = 'select id from {table} where room_id=%s and user_id=%s and status=%s'.format(table=cls.table)
     try:
         return db.query(sql, room_id, user_id, ROOM_USER_SILENT)[0]
     except:
         return None
コード例 #4
0
 def daily_rob_welfare_integral_enough(cls, user_id):
     db = DbManager().db
     date = datetime.now()
     sql = 'select id from {table} where user_id=%s and source=%s and create_date=%s'.format(
         table=cls.table)
     rst = db.query(sql, user_id, USER_INTEGRAL_DAILY_ROB_WELFARE, date)
     return len(rst) >= 3
コード例 #5
0
 def add(cls, user_id, source, amount, integral, extra=None):
     db = DbManager().db
     now = datetime.now()
     date = now.date()
     sql = 'insert into {table} (user_id, source, amount, integral, create_date, create_time, extra) values ' \
     '(%s, %s, %s, %s, %s, %s)'.format(table=cls.table)
     db.execute(sql, user_id, source, amount, integral, date, now, extra)
コード例 #6
0
 def daily_send_reward_integral_enough(cls, user_id):
     db = DbManager().db
     date = datetime.now().date()
     sql = 'select id from {table} where user_id=%s and source=%s and create_date=%s'.format(
         table=cls.table)
     rst = db.query(sql, user_id, USER_INTEGRAL_DAILY_SEND_REWARD, date)
     return len(rst) >= 10
コード例 #7
0
 def add(cls, id, creator_id, group_id, object_name, channel_type, content,
         create_time):
     db = DbManager().db
     sql = 'insert into {table} (id, creator_id, group_id, object_name, channel_type, content, create_time) values ' \
         '(%s, %s, %s, %s, %s, %s, %s)'.format(table=cls.table)
     db.execute(sql, id, creator_id, group_id, object_name, channel_type,
                content, create_time)
コード例 #8
0
    def search_by_name_or_tag(cls, query):
        db = DbManager().db
        rooms = set()
        sql = 'select * from {table} where name like %s'.format(
            table=cls.table)
        query = "%%%s%%" % query
        rooms_info = db.query(sql, query)
        for room_info in rooms_info:
            rooms.add(cls(**room_info))
        # sql = 'select * from room a, room_tag b, tag c where a.id=b.room_id and b.tag_id=c.id and c.name like %s'
        # rooms_info = db.query(sql, query)
        # for room_info in rooms_info:
        #     rooms.add(cls(
        #         id=room_info.room_id,
        #         creator_id=room_info.creator_id,
        #         name=room_info.name,
        #         intro=room_info.intro,
        #         rent=room_info.rent,
        #         avatar=init_pic_url(room_info.avatar),
        #         limit_user_number=room_info.limit_user_number,
        #         status=room_info.status,
        #         create_time=room_info.create_time,
        #         update_time=room_info.update_time,
        #     ))

        return rooms
コード例 #9
0
ファイル: charge.py プロジェクト: zhenchaozhu/starmachine
 def gets_all(cls):
     db = DbManager().db
     sql = 'select * from {table}'.format(table=cls.table)
     charge_orders = db.query(sql)
     return charge_orders and [
         cls(**charge_order) for charge_order in charge_orders
     ]
コード例 #10
0
ファイル: withdraw.py プロジェクト: zhenchaozhu/starmachine
 def get_lists(cls, start, count):
     db = DbManager().db
     end = start * count - 1
     sql = 'select * from {table} order by id desc limit %s, %s'.format(
         table=cls.table)
     withdraws = db.query(sql, start, end)
     return withdraws and [cls(**withdraw) for withdraw in withdraws]
コード例 #11
0
 def daily_login_integral_enough(cls, user_id):
     db = DbManager().db
     date = datetime.now().date()
     sql = 'select id from {table} where user_id=%s and source=%s and create_date=%s'.format(
         table=cls.table)
     rst = db.get(sql, user_id, USER_INTEGRAL_DAILY_LOGIN, date)
     return bool(rst)
コード例 #12
0
 def update_device_token(self, device_token, os):
     db = DbManager().db
     update_time = datetime.now()
     sql = 'update {table} set device_token=%s, os=%s, update_time=%s where id=%s'.format(
         table=self.table)
     db.execute(sql, device_token, os, update_time, self.id)
     self.flush_device_info()
コード例 #13
0
 def add(cls, user_id, balance=0.00):
     db = DbManager().db
     sql = 'insert into {table} (user_id, balance) values (%s, %s)'.format(
         table=cls.table)
     account_id = db.execute(sql, user_id, balance)
     return account_id and cls(
         id=account_id, user_id=user_id, balance=balance)
コード例 #14
0
 def is_room_black_user(cls, room_id, user_id):
     db = DbManager().db
     sql = 'select id from {table} where room_id=%s and user_id=%s'.format(table=cls.table)
     try:
         return db.query(sql, room_id, user_id)[0]
     except:
         return None
コード例 #15
0
 def gets_all(cls):
     db = DbManager().db
     sql = 'select * from {table}'.format(table=cls.table)
     reward_orders = db.query(sql)
     return reward_orders and [
         cls(**reward_order) for reward_order in reward_orders
     ]
コード例 #16
0
 def daily_create_content_integral_enough(cls, user_id):
     db = DbManager().db
     date = datetime.now().date()
     sql = 'select id from {table} where user_id=%s and source=%s and create_date=%s'.format(
         table=cls.table)
     rst = db.query(sql, user_id, USER_INTEGRAL_DAILY_CREATE_CONTENT, date)
     return len(rst) >= 3
コード例 #17
0
 def exist_room(cls, name):
     db = DbManager().db
     sql = 'select id from {table} where name=%s'.format(table=cls.table)
     try:
         return db.query(sql, name)[0]
     except:
         return None
コード例 #18
0
 def add(cls, user_id, device_token, os):
     db = DbManager().db
     create_time = datetime.now()
     sql = 'insert into {table} (user_id, device_token, os, create_time) values (%s, %s, %s, %s)'.format(
         table=cls.table)
     device_id = db.execute(sql, user_id, device_token, os, create_time)
     return device_id and cls.get(device_id)
コード例 #19
0
 def update(self, **kwargs):
     db = DbManager().db
     params = ['%s="%s"' % (key, kwargs.get(key)) for key in kwargs]
     update_sql = ', '.join(params)
     sql = 'update {table} set %s where id=%s'.format(
         table=self.table) % (update_sql, self.id)
     r = db.execute(sql)
     return r
コード例 #20
0
 def gets_complete_order_by_activity(cls, activity_id):
     db = DbManager().db
     sql = 'select * from {table} where activity_id=%s and status=%s'.format(
         table=cls.table)
     orders_info = db.query(sql, activity_id, STATUS_COMPLETE)
     return orders_info and [
         cls(**order_info) for order_info in orders_info
     ]
コード例 #21
0
ファイル: friendship.py プロジェクト: zhenchaozhu/starmachine
    def follow_each_other(cls, user_id, follow_id):
        db = DbManager().db
        sql = 'select follow_type from {table} where user_id=%s and follow_id=%s'
        rst = db.get(sql, user_id, follow_id)
        if rst:
            return rst.get('follow_type') == FOLLOW_BOTH_TYPE

        return False
コード例 #22
0
 def add(cls, trade_id, pay_method, notify):
     db = DbManager().db
     create_time = datetime.now()
     sql = 'insert into {table} (trade_id, pay_method, notify, create_time) values (%s, %s, %s, %s)'.format(
         table=cls.table)
     order_pay_notify_id = db.execute(sql, trade_id, pay_method, notify,
                                      create_time)
     return order_pay_notify_id
コード例 #23
0
ファイル: user.py プロジェクト: zhenchaozhu/starmachine
 def get_user_count(cls):
     db = DbManager().db
     sql = 'select count(id) from {table}'.format(table=cls.table)
     count = db.get(sql)
     if count and count.get('count(id)'):
         return count.get('count(id)')
     else:
         return 0
コード例 #24
0
ファイル: user.py プロジェクト: zhenchaozhu/starmachine
 def exists_user_by_telephone(cls, telephone):
     db = DbManager().db
     sql = 'select id from {table} where telephone=%s'.format(
         table=cls.table)
     try:
         return db.query(sql, telephone)[0]
     except:
         return None
コード例 #25
0
 def get_user_receive_reward_amount(cls, user_id):
     db = DbManager().db
     sql = 'select sum(amount) from {table} where status=%s and receiver_id=%s'.format(table=cls.table)
     rst = db.get(sql, STATUS_COMPLETE, user_id)
     if rst and rst.get('sum(amount)'):
         return float(rst.get('sum(amount)'))
     else:
         return 0
コード例 #26
0
 def has_get_first_reward_integral(cls, user_id, source):
     db = DbManager().db
     sql = 'select id from {table} where user_id=%s and source=%s'.format(
         table=cls.table)
     try:
         return db.query(sql, user_id, source)[0]
     except:
         return None
コード例 #27
0
ファイル: room_tag.py プロジェクト: zhenchaozhu/starmachine
 def get_tag_ids_by_room(cls, room_id):
     db = DbManager().db
     sql = 'select tag_id from {table} where room_id=%s'.format(
         table=cls.table)
     tag_ids_dict = db.query(sql, room_id)
     return tag_ids_dict and [
         tag_id_dict.get('tag_id') for tag_id_dict in tag_ids_dict
     ]
コード例 #28
0
 def add(cls, receiver_id, group_id, message_id, liked_amount, reward_type):
     db = DbManager().db
     sql = 'insert into {table} (receiver_id, group_id, message_id, liked_amount, reward_type) values (%s, %s, %s, %s, %s)'.format(
         table=cls.table)
     envelope_id = db.execute(sql, receiver_id, group_id, message_id,
                              liked_amount, reward_type)
     return cls(envelope_id, receiver_id, group_id, message_id,
                liked_amount, reward_type)
コード例 #29
0
 def get_hot_messages(cls, group_id, count):
     db = DbManager().db
     now = datetime.now()
     limit_time = now - timedelta(days=1)
     sql = 'select * from {table} where group_id=%s and create_time>%s and liked_amount>%s order by liked_amount desc limit ' \
     '0, %s'.format(table=cls.table)
     rst = db.query(sql, group_id, limit_time, 0, count)
     return rst and [cls(**d) for d in rst]
コード例 #30
0
 def exists_tag(cls, user_id, tag_id):
     db = DbManager().db
     sql = 'select id from {table} where user_id=%s and tag_id=%s'.format(
         table=cls.table)
     try:
         return db.query(sql, user_id, tag_id)[0]
     except:
         return False