Sfoglia il codice sorgente

add agent apply function

abiao 4 anni fa
parent
commit
5787695cd8

+ 83 - 0
go/gopath/src/fohow.com/apps/controllers/user_controller/agent_apply_controller.go

@@ -0,0 +1,83 @@
+package user_controller
+
+import (
+	"fohow.com/apps"
+	"fohow.com/apps/models/user_model"
+	"strconv"
+	"time"
+)
+
+//申请代理
+func (self *UserController) AgentApplication() {
+	mobile := self.GetString("mobile")
+	_id := self.Ctx.Input.Param(":wx_uid")
+	wxId, _ := strconv.ParseInt(_id, 10, 64)
+	introUserId := self.GetCurrentWxUserId()
+
+	/*	if len(mobile) != 11 {
+		self.ReturnError(404, apps.ParamsError, "", nil)
+	}*/
+
+	wxUser := user_model.GetWxUserById(wxId, false)
+	if wxUser == nil {
+		self.ReturnError(403, apps.WxUserNotExist, "", nil)
+	}
+	if wxUser.Rank >= user_model.WX_USER_RANK_ONE {
+		self.ReturnError(403, apps.AlreadyAgent, "", nil)
+	}
+
+	curWxUser := user_model.GetWxUserById(introUserId, true)
+	if curWxUser == nil {
+		self.ReturnError(403, apps.UserNeedLogin, "", nil)
+	}
+
+	record := user_model.GetAgentApplyByWxUId(wxUser.Id)
+	if record != nil {
+		self.ReturnError(403, apps.ShopNoRepit, "", nil)
+	}
+	hTime := time.Now().Unix()
+	record = new(user_model.AgentApply).Create(introUserId, wxUser.Id, hTime, wxUser.Depart, mobile, wxUser.Nickname)
+	if record == nil {
+		self.ReturnError(403, apps.CreateOrderFail, "", nil)
+	}
+
+	type Ret struct {
+		Result bool `json:"result"`
+	}
+	ret := &Ret{Result: true}
+	self.Data["json"] = ret
+	self.ServeJSON()
+}
+
+//审核申请代理
+func (self *UserController) ComAgentApplication() {
+	_id := self.Ctx.Input.Param(":apply_id")
+	applyId, _ := strconv.ParseInt(_id, 10, 64)
+	introUserId := self.GetCurrentWxUserId()
+
+	record := user_model.GetAgentApplyById(applyId)
+	if record == nil {
+		self.ReturnError(403, apps.NoExist, "", nil)
+	}
+
+	curWxUser := user_model.GetWxUserById(introUserId, true)
+	if curWxUser == nil {
+		self.ReturnError(403, apps.UserNeedLogin, "", nil)
+	}
+
+	if curWxUser.Rank < user_model.WX_USER_RANK_THERE && curWxUser.Depart != record.Depart {
+		self.ReturnError(403, apps.ComNotAllow, "", nil)
+
+	}
+	record.Status = true
+	record.ComTime = time.Now().Unix()
+	record.ComUser = introUserId
+	record.Save()
+
+	type Ret struct {
+		Result bool `json:"result"`
+	}
+	ret := &Ret{Result: true}
+	self.Data["json"] = ret
+	self.ServeJSON()
+}

+ 14 - 10
go/gopath/src/fohow.com/apps/init.go

@@ -27,18 +27,22 @@ const (
 
 var (
 	// 共用
-	BindFail              = []string{"bindFail", "迁移失败,请联系管理员"}
-	HasBind               = []string{"hasBind", "该会员编号已绑定会员"}
-	DailySignRepeat       = []string{"dailySignRepeat", "已经领取过啦"}
-	RedisError            = []string{"redisError", "redis初始化错误"}
-	RedisGetError         = []string{"redisGetError", "redisGet错误"}
-	RedisJsonError        = []string{"redisJsonError", "json转换错误"}
-	OrderRefundError      = []string{"orderRefundError", "退款失败"}
-	OtherSNotAllow        = []string{"othersNotAllow", "非店长无法在专区下单!"}
-	AlreadyShop           = []string{"alreadyShop", "您已经是店主,请勿重复申请"}
+	ComNotAllow = []string{"notAllow", "审核人权限不够,请联系管理员"}
+
+	BindFail         = []string{"bindFail", "迁移失败,请联系管理员"}
+	HasBind          = []string{"hasBind", "该会员编号已绑定会员"}
+	DailySignRepeat  = []string{"dailySignRepeat", "已经领取过啦"}
+	RedisError       = []string{"redisError", "redis初始化错误"}
+	RedisGetError    = []string{"redisGetError", "redisGet错误"}
+	RedisJsonError   = []string{"redisJsonError", "json转换错误"}
+	OrderRefundError = []string{"orderRefundError", "退款失败"}
+	OtherSNotAllow   = []string{"othersNotAllow", "非店长无法在专区下单!"}
+	AlreadyShop      = []string{"alreadyShop", "您已经是店主,请勿重复申请"}
+	AlreadyAgent     = []string{"alreadyShop", "该会员已是代理,请勿重复申请"}
+
 	ShopNoRepit           = []string{"shopNoRepit", "请勿重复申请"}
 	NoCart                = []string{"noCart", "请选择您需要结算的产品"}
-	NoExist               = []string{"noExist", "不存在"}
+	NoExist               = []string{"noExist", "该记录不存在"}
 	HasOver               = []string{"hasOver", "已结束"}
 	NoShopSale            = []string{"noShopSale", "该商品非专区商品"}
 	HasPaied              = []string{"hasPaied", "已支付"}

+ 126 - 0
go/gopath/src/fohow.com/apps/models/user_model/agent_application.go

@@ -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
+}

+ 3 - 2
go/gopath/src/fohow.com/apps/models/user_model/wx_user.go

@@ -21,8 +21,9 @@ const (
 	COPARTNER_STATE_YES  = 1
 	COPARTNER_STATE_ONCE = 2
 
-	WX_USER_RANK_ONE = int64(1)
-	WX_USER_RANK_TWO = int64(2)
+	WX_USER_RANK_ONE   = int64(1)
+	WX_USER_RANK_TWO   = int64(2)
+	WX_USER_RANK_THERE = int64(3)
 )
 
 type WxUser struct {