|
|
@@ -0,0 +1,126 @@
|
|
|
+package user_model
|
|
|
+
|
|
|
+import (
|
|
|
+ "api.com/apps/models/user_model"
|
|
|
+ "fohow.com/cache"
|
|
|
+
|
|
|
+ "fmt"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "github.com/astaxie/beego/orm"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ agent_applys_tablename = "agent_applys"
|
|
|
+)
|
|
|
+
|
|
|
+type AgentApply struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ HTime int64 `orm:"column(happen_time)" json:"happen_time"` // int(11)
|
|
|
+ IntroUserId int64 `orm:"column(intro_user_id)" json:"intro_user_id"`
|
|
|
+ WxUId int64 `orm:"column(wx_user_id)" json:"wx_uid"` // int(11)
|
|
|
+ NickName string `orm:"column(nickname)" json:"nickname"` // varchar(64)
|
|
|
+ Mobile string `orm:"column(mobile)" json:"mobile"` // int(11)
|
|
|
+ Depart int64 `orm:"column(depart)" json:"-"` // datetime
|
|
|
+ Status bool `orm:"column(status)" json:"status"`
|
|
|
+ ComUser int64 `orm:"column(com_user_id)" json:"com_user_id"` // int(11)
|
|
|
+ ComTime int64 `orm:"column(com_time)" json:"com_time"` // int(11)
|
|
|
+ Head string `orm:"-" json:"head"` // varchar(255)
|
|
|
+ CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
+ UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)" json:"-"` // datetime
|
|
|
+}
|
|
|
+
|
|
|
+func (self *AgentApply) TableName() string {
|
|
|
+ return agent_applys_tablename
|
|
|
+}
|
|
|
+
|
|
|
+func (self *AgentApply) Create(uId, wxUId, happenTime, depart int64, mobile, nickname string) *AgentApply {
|
|
|
+ item := &AgentApply{
|
|
|
+ IntroUserId: uId,
|
|
|
+ WxUId: wxUId,
|
|
|
+ NickName: nickname,
|
|
|
+ Mobile: mobile,
|
|
|
+ HTime: happenTime,
|
|
|
+ Depart: depart,
|
|
|
+ Status: false,
|
|
|
+ }
|
|
|
+ id, err := orm.NewOrm().Insert(item)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("insert AgentApply err=[%s]", err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ item.Id = id
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
+func (self *AgentApply) Save() error {
|
|
|
+ if _, err := orm.NewOrm().Update(self); err != nil {
|
|
|
+ beego.BeeLogger.Error("Save AgentApply id=[%d] .err=[%s]", self.Id, err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetAgentApplyByWxUId(wxUId int64) *AgentApply {
|
|
|
+ item := &AgentApply{}
|
|
|
+ if err := orm.NewOrm().QueryTable(item).
|
|
|
+ Filter("wx_user_id", wxUId).Limit(1).
|
|
|
+ One(item); err != nil {
|
|
|
+ beego.BeeLogger.Info("GetAgentApplyByWxUId(%d), err=%s",
|
|
|
+ wxUId, err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
+func GetAgentApplyById(id int64) *AgentApply {
|
|
|
+ item := &AgentApply{}
|
|
|
+ if err := orm.NewOrm().QueryTable(item).
|
|
|
+ Filter("id", id).Limit(1).
|
|
|
+ One(item); err != nil {
|
|
|
+ beego.BeeLogger.Info("GetAgentApplyById(%d), err=%s",
|
|
|
+ id, err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
+//获取区代所有代理申请记录
|
|
|
+func GetAllApplys(page, perPage, depart int64, useCache bool) (agent_apply []*AgentApply) {
|
|
|
+ k := fmt.Sprintf("user_model.GetAllApplys.page(%d).perPage(%d).depart(%d)", page, perPage, depart)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).([]*AgentApply); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
+ o := orm.NewOrm()
|
|
|
+ _, err := o.QueryTable(new(AgentApply)).Filter("depart", depart).
|
|
|
+ OrderBy("-created_at").Limit(perPage, (page-1)*perPage).All(&agent_apply)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Debug("GetLatest err=%s", err)
|
|
|
+ }
|
|
|
+ for _, ap := range agent_apply {
|
|
|
+ wxUser := user_model.GetWxUserById(ap.WxUId, true)
|
|
|
+ if wxUser != nil {
|
|
|
+ ap.Head = GetFullImgUrl(wxUser.Head)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cache.Cache.Put(k, agent_apply, 10*time.Minute)
|
|
|
+ return agent_apply
|
|
|
+}
|
|
|
+
|
|
|
+func GetAllApplyCount(depart int64, useCache bool) int64 {
|
|
|
+ k := fmt.Sprintf("user_model.GetAllApplyCount.depart(%d)", depart)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item := new(AgentApply)
|
|
|
+ o := orm.NewOrm()
|
|
|
+ count, _ := o.QueryTable(item).Filter("depart", depart).Count()
|
|
|
+
|
|
|
+ cache.Cache.Put(k, count, 10*time.Minute)
|
|
|
+ return count
|
|
|
+}
|