Blame view

src/models/Daily.lua 1.3 KB
be9c9ca6   zhouahaihai   角色评论
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  -- 日常数据
  
  local Daily = class("Daily", require("shared.ModelBase"))
  
  function Daily:ctor(properties)
      Daily.super.ctor(self, properties)
  end
  
  Daily.schema = {
      key                 = {"string"},       -- redis key
      commentHero         = {"string", ""}, --单日评论食灵记录 type=1
  }
  
  Daily.fields = {
      commentHero = true,
  }
  
  function Daily:updateProperty(params)
      local type, default = table.unpack(self.schema[params.field])
  
      if params.delta then
          self:setProperty(params.field, self:getProperty(paramsfield) + params.delta)
          self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
          return true
      end
      if params.value then
          self:setProperty(params.field, params.value)
          self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
          return true
      end
      return false
  end
  
  function Daily:refreshDailyData(notify)
      for field, schema in pairs(self.schema) do
          if field ~= "key" then
              local typ, def = table.unpack(schema)
              self:setProperty(field, def)
          end
      end
      if notify then
          self.owner:notifyUpdateProperties(self:data())
      end
  end
  
  function Daily:data()
      return {
          -- dailyTaskStatus = self:getProperty("dailyTaskStatus"),
      }
  end
  
  return Daily