Commits

Jindong Zhang  committed 0666f9c

f

  • Participants
  • Parent commits 4ff82c5
  • Branches bagua

Comments (0)

Files changed (9)

 import _handler
 from zweb._urlmap import urlmap
 from model.po import po_word_new, Po
+from model.po_pos import po_pos_set
 from model import reply
 from model.zsite import Zsite
 
         if po:
             can_admin = po.can_admin(current_user_id)
             can_view = po.can_view(current_user_id)
+            if can_view and current_user_id:
+                po_pos_set(current_user_id, id)
             return self.render(
                 po=po,
                 can_admin=can_admin,
         self.redirect(current_user.link)
 
     post = get
-

File model/buzz.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from time import time
+from _db import Model, McModel, McCache
+from cid import CID_BUZZ_SYS, CID_BUZZ_SHOW, CID_BUZZ_FOLLOW, CID_BUZZ_WALL, CID_BUZZ_PO_REPLY
+from cid import CID_USER
+from zsite import Zsite
+from state import STATE_ACTIVE
+from follow import Follow
+from po_pos import PoPos, STATE_BUZZ
+from zweb.orm import ormiter
+
+class Buzz(Model):
+    pass
+
+def buzz_new(from_id, to_id, cid, rid):
+    b = Buzz(from_id=from_id, to_id=to_id, cid=cid, rid=rid, create_time=int(time()))
+    b.save()
+    return b
+
+def buzz_sys_new(use_id, po_id):
+    buzz_new(0, user_id, CID_BUZZ_SYS, po_id)
+
+def buzz_sys_new_all(po_id):
+    for i in ormiter(Zsite, 'cid=%s and state>=%s' % (CID_USER, STATE_ACTIVE)):
+        buzz_sys_new(i.id, po_id)
+
+def buzz_show_new(user_id, show_id):
+    buzz_new(0, user_id, CID_BUZZ_SHOW, show_id)
+
+def buzz_show_new_all(show_id):
+    for i in ormiter(Zsite, 'cid=%s and state>=%s' % (CID_USER, STATE_ACTIVE)):
+        buzz_show_new(i.id, show_id)
+
+def buzz_new_to_follow(from_id, to_id, cid):
+    for i in ormiter(Follow, 'to_id=%s and from_id !=%s' % (from_id, to_id)):
+        buzz_new(from_id, i.from_id, cid, to_id)
+
+def buzz_follow_new(from_id, to_id):
+    buzz_new(from_id, to_id, CID_BUZZ_FOLLOW, to_id)
+    buzz_new_to_follow(from_id, to_id, CID_BUZZ_FOLLOW)
+
+def buzz_wall_new(from_id, to_id):
+    buzz_new_to_follow(from_id, to_id, CID_BUZZ_WALL)
+
+def buzz_po_reply_new(from_id, po_id):
+    follow_list = [i.from_id for i in ormiter(Follow, 'to_id=%s and from_id !=%s' % (from_id, to_id))]
+    buzz_list = [i.user_id for i in ormiter(PoPos, 'po_id=%s and state=%s' % (po_id, STATE_BUZZ))]
+    for user_id in set(follow_list) | set(buzz_list):
+        buzz_new(from_id, user_id, CID_BUZZ_PO_REPLY, po_id)
+
+def buzz_list(user_id, limit, offset):
+    pass

File model/cid.py

 #Follow
 CID_FOLLOW = 91
 
-#User_verify
+#User Verify
 CID_VERIFY_MAIL = 121
 CID_VERIFY_PASSWORD = 122
 CID_VERIFY_MONEY = 123
 
 #Pay Type
 CID_PAY_ALIPAY = 181
+
+#Buzz
+CID_BUZZ_SYS = 211
+CID_BUZZ_SHOW = 212
+CID_BUZZ_FOLLOW = 213
+CID_BUZZ_WALL = 214
+CID_BUZZ_PO_REPLY = 215

File model/follow.py

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
-from _db import Model, McModel, McCache, cursor_by_table, McCacheA
+from _db import Model, McModel, McCache, cursor_by_table, McCacheA, McLimitA
 from zsite import Zsite
 from cid import CID_FOLLOW
 from gid import gid
 from feed import feed_entry_rm, feed_entry_new, mc_feed_id_by_for_zsite_follow, mc_feed_entry_tuple
 
-mc_follow_id_list_by_from_id_cid = McCacheA("FollowIdListByFromIdCid:%s")
-mc_follow_id_list_by_from_id = McCacheA("FollowIdListByFromId:%s")
-mc_follow_get = McCache("FollowGet.%s")
+mc_follow_id_list_by_to_id = McLimitA('FollowIdListByToId.%s', 128)
+mc_follow_id_list_by_from_id_cid = McCacheA('FollowIdListByFromIdCid.%s')
+mc_follow_id_list_by_from_id = McCacheA('FollowIdListByFromId.%s')
+mc_follow_get = McCache('FollowGet.%s')
 
-follow_cursor = cursor_by_table("follow")
+class Follow(Model):
+    pass
 
+follow_cursor = cursor_by_table('follow')
+
+@mc_follow_id_list_by_to_id('{to_id}')
+def follow_id_list_by_to_id(to_id, limit, offset):
+    follow_cursor.execute('select from_id from follow where to_id=%s order by id desc limit %s offset %s', (to_id, limit, offset))
+    return [i for i, in follow_cursor]
 
 @mc_follow_id_list_by_from_id('{from_id}')
 def follow_id_list_by_from_id(from_id):
         follow_id_list_by_from_id_cid(from_id, cid)
     )
 
-@mc_follow_get("{from_id}_{to_id}")
+@mc_follow_get('{from_id}_{to_id}')
 def follow_get(from_id, to_id):
     follow_cursor.execute(
-        "select id from follow where from_id=%s and to_id=%s",
+        'select id from follow where from_id=%s and to_id=%s',
         (from_id, to_id)
     )
     result = follow_cursor.fetchone()
     if not id:
         return
     follow_cursor.execute(
-        "delete from follow where id=%s", id
+        'delete from follow where id=%s', id
     )
     feed_entry_rm(id)
     to = Zsite.mc_get(to_id)
     cid = to.cid
     id = gid()
     follow_cursor.execute(
-        "insert into follow (id, from_id, to_id, cid) values (%s,%s,%s,%s)",
+        'insert into follow (id, from_id, to_id, cid) values (%s,%s,%s,%s)',
         (id, from_id, to_id, cid)
     )
     follow_cursor.connection.commit()
     feed_entry_new(id, from_id, CID_FOLLOW)
+    from buzz import buzz_follow_new
+    buzz_follow_new(from_id, to_id)
     mc_flush(from_id, to_id, cid)
 
 def mc_flush(from_id, to_id, cid):
     mc_feed_id_by_for_zsite_follow.delete(from_id)
-    mc_follow_get.delete( "%s_%s"%(from_id, to_id))
-    mc_follow_id_list_by_from_id_cid.delete("%s_%s"%(from_id, cid))
+    mc_follow_get.delete( '%s_%s'%(from_id, to_id))
+    mc_follow_id_list_by_from_id_cid.delete('%s_%s'%(from_id, cid))
     mc_follow_id_list_by_from_id.delete(from_id)
 
 
 @mc_feed_entry_tuple('{id}')
 def feed_tuple_follow(id):
     follow_cursor.execute(
-        "select to_id from follow where id=%s",
+        'select to_id from follow where id=%s',
         id
     )
     r = follow_cursor.fetchone()

File model/money.py

 from user_mail import mail_by_user_id
 from verify import verify_new, verifyed
 
-BANK_SYS = 0
-
 def read_cent(cent):
     return '%.2f' % (cent / 100.)
 
     assert price > 0
     cent = int(price * 100)
     tax = int(round(cent * CHARGE_TAX[cid]))
-    t = trade_new(cent-tax, tax, BANK_SYS, user_id, CID_TRADE_CHARDE, cid, TRADE_STATE_OPEN)
+    t = trade_new(cent-tax, tax, 0, user_id, CID_TRADE_CHARDE, cid, TRADE_STATE_OPEN)
     vid, ck = verify_new(user_id, CID_VERIFY_MONEY)
     return '%s_%s_%s' % (t.id, vid, ck)
 
     assert price > 0
     cent = int(price * 100)
     tax = int(round(cent * CHARGE_TAX[cid]))
-    return trade_new(cent, tax, user_id, BANK_SYS, CID_TRADE_WITHDRAW, cid, TRADE_STATE_OPEN)
+    return trade_new(cent, tax, user_id, 0, CID_TRADE_WITHDRAW, cid, TRADE_STATE_OPEN)
 
 def withdraw_fail(id, txt):
     t = Trade.get(id)
         trade_log.set(id, txt)
 
 def withdraw_open_count():
-    return Trade.where(cid=CID_TRADE_WITHDRAW, to_id=BANK_SYS, state=TRADE_STATE_OPEN).count()
+    return Trade.where(cid=CID_TRADE_WITHDRAW, to_id=0, state=TRADE_STATE_OPEN).count()
 
 def withdraw_max():
-    c = Trade.raw_sql('select max(id) from trade where cid=%s and to_id=%s', CID_TRADE_WITHDRAW, BANK_SYS)
+    c = Trade.raw_sql('select max(id) from trade where cid=%s and to_id=%s', CID_TRADE_WITHDRAW, 0)
     return c.fetchone()[0] or 0
 
 def withdraw_list():
-    qs = Trade.where(cid=CID_TRADE_WITHDRAW, to_id=BANK_SYS, state=TRADE_STATE_OPEN).order_by('id desc')
+    qs = Trade.where(cid=CID_TRADE_WITHDRAW, to_id=0, state=TRADE_STATE_OPEN).order_by('id desc')
     for t in qs:
         i.account, i.name = pay_account_get(i.from_id, i.rid)
     return qs

File model/po_pos.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from time import time
+from _db import cursor_by_table, Model, McModel, McLimitA, McCache
+from po import Po
+
+STATE_BUZZ = 1
+STATE_MUTE = 0
+
+class PoPos(Model):
+    pass
+
+mc_po_pos = McCache('PoPos.%s')
+
+@mc_po_pos('{user_id}_{po_id}')
+def po_pos_get(user_id, po_id):
+    p = PoPos.get(user_id=user_id, po_id=po_id)
+    if p:
+        return p.pos
+    return -1
+
+mc_po_viewed_list = McLimitA('PoViewedList.%s', 128)
+
+@mc_po_viewed_list('{po_id}')
+def po_viewed_list(po_id, limit, offset):
+    qs = PoPos.where(po_id=po_id).order_by('id desc')
+    return [i.user_id for i in qs]
+
+def po_buzz_list(po_id):
+    qs = PoPos.where(po_id=po_id, state=STATE_BUZZ)
+    return [i.user_id for i in qs]
+
+def po_pos_set(user_id, po_id):
+    po = Po.mc_get(po_id)
+    pos = po.reply_id_last
+    pos_old = po_pos_get(user_id, po_id)
+    if pos > pos_old:
+        PoPos.raw_sql('insert delayed into po_pos (user_id, po_id, pos, state) values (%s, %s, %s, %s) on duplicate key update pos=values(pos)', user_id, po_id, pos, STATE_MUTE)
+        mc_po_pos.set('%s_%s' % (user_id, po_id), pos)
+    if pos_old == -1:
+        mc_po_viewed_list.delete(po_id)
+
+def po_pos_state(user_id, po_id, state):
+    pos = po_pos_get(user_id, po_id)
+    if pos >= 0:
+        p = PoPos.get(user_id=user_id, po_id=po_id)
+        if p:
+            p.state = state
+            p.save()
+
+if __name__ == '__main__':
+    pass

File model/reply.py

         )
         return [i for i, in cursor]
 
+    @property
+    def reply_id_last(self):
+        li = self.reply_id_list_reversed(1)
+        if li:
+            return li[0]
+        return 0
+
     @mc_reply_id_list_reversed("{self.cid}_{self.id}")
     def reply_id_list_reversed(self, limit=None, offset=None):
         return self._reply_id_list(limit, offset, "order by id desc")

File model/txt.py

 
 if __name__ == "__main__":
     pass
-
-

File model/wall.py

 CREATE TABLE `wall` (
   `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   `cid` TINYINT UNSIGNED NOT NULL ,
-  `from_id` INTEGER UNSIGNED NOT NULL, 
+  `from_id` INTEGER UNSIGNED NOT NULL,
   `to_id` INTEGER UNSIGNED NOT NULL ,
   PRIMARY KEY (`id`),
   KEY `from_id` (`from_id`),
     if reply1 is None and reply2 is None:
         wall = Wall(cid=self.cid, from_id=user_id, to_id=zsite_id)
         wall.save()
+        from buzz import buzz_wall_new
+        buzz_wall_new(user_id, zsite_id)
     else:
         if reply1:
             reply = reply1
 Zsite.reply_total = reply_total
 Zsite.reply_list_id_reversed = reply_list_id_reversed
 Zsite.reply_list_reversed = reply_list_reversed
-
-
-
-