Browse Source

用户勾选推送赛道接口

xingzai 2 years ago
parent
commit
f2ab3c241d

+ 43 - 18
controllers/user.go

@@ -4,6 +4,8 @@ import (
 	"encoding/json"
 	"hongze/hongze_cygxzs/models"
 	"hongze/hongze_cygxzs/utils"
+	"strconv"
+	"strings"
 	"time"
 )
 
@@ -32,9 +34,11 @@ func (this *UserController) ChooseDetail() {
 		br.Ret = 408
 		return
 	}
+	resp := new(models.CygxXzsChooseSendResp)
 	mobile := user.Mobile
 	mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
 	mapFllow := make(map[int]int)
+	ampCheckList := make(map[int][]int, 0)
 	fllowList, err := models.GetCygxIndustryFllowList(mobile)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取信息失败"
@@ -53,6 +57,8 @@ func (this *UserController) ChooseDetail() {
 	for _, v := range industrialList {
 		if mapFllow[v.IndustrialManagementId] > 0 {
 			v.IsFllow = true
+			//添加所关注的行业赛道
+			ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId)
 		}
 		mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
 	}
@@ -64,6 +70,12 @@ func (this *UserController) ChooseDetail() {
 	}
 	for k, v := range permissionList {
 		permissionList[k].List = mapIndustrial[v.ChartPermissionId]
+		if len(ampCheckList[v.ChartPermissionId]) == 0 {
+			permissionList[k].CheckList = make([]int, 0)
+		} else {
+			permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
+		}
+		permissionList[k].AllTracks = "全部赛道"
 	}
 	count, err := models.GetXzsChooseSendCountByMobile(mobile)
 	if err != nil {
@@ -71,7 +83,7 @@ func (this *UserController) ChooseDetail() {
 		br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
 		return
 	}
-	resp := new(models.CygxXzsChooseSendResp)
+
 	if count == 0 {
 		resp.IsObjective = 1
 		resp.IsSubjective = 1
@@ -85,7 +97,7 @@ func (this *UserController) ChooseDetail() {
 
 // @Title 提交用户的选择详情
 // @Description 提交用户的选择详情接口
-// @Param	request	body models.ActivityIdRep true "type json string"
+// @Param	request	body models.SubmitChooseSendResp true "type json string"
 // @Success 200 {object}  models.CygxXzsChooseSendResp
 // @router /choose/submit [post]
 func (this *UserController) ChooseSubmit() {
@@ -101,7 +113,11 @@ func (this *UserController) ChooseSubmit() {
 		br.Ret = 408
 		return
 	}
-
+	if user.Mobile == "" {
+		br.Msg = "提交失败!"
+		br.ErrMsg = "提交失败,手机号不能为空"
+		return
+	}
 	var req models.SubmitChooseSendResp
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -109,6 +125,27 @@ func (this *UserController) ChooseSubmit() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+	industrialManagementIds := req.IndustrialManagementIds
+	sliceIndustrial := strings.Split(industrialManagementIds, ",")
+
+	var itemsFllow []*models.CygxIndustryFllow
+	for _, v := range sliceIndustrial {
+		item := new(models.CygxIndustryFllow)
+		industrialManagementId, _ := strconv.Atoi(v)
+		item.IndustrialManagementId = industrialManagementId
+		item.UserId = user.UserId
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.RealName = user.RealName
+		item.Type = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.Source = 2
+		itemsFllow = append(itemsFllow, item)
+	}
+
 	mobile := user.Mobile
 	item := new(models.CygxXzsChooseSend)
 	item.UserId = user.UserId
@@ -128,23 +165,11 @@ func (this *UserController) ChooseSubmit() {
 		br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
 		return
 	}
+	//如果有记录就新增,没有记录就修改
 	if count == 0 {
-		err = models.AddCygxXzsChooseSend(item)
+		err = models.AddCygxXzsChooseSend(item, itemsFllow)
 	} else {
-		updateParams := make(map[string]interface{})
-		updateParams["UserId"] = item.UserId
-		updateParams["Mobile"] = item.Mobile
-		updateParams["Email"] = item.Email
-		updateParams["CompanyId"] = item.CompanyId
-		updateParams["CompanyName"] = item.CompanyName
-		updateParams["RealName"] = item.RealName
-		updateParams["ModifyTime"] = time.Now()
-		updateParams["IsRefuse"] = item.IsRefuse
-		updateParams["IsSubjective"] = item.IsSubjective
-		updateParams["IsObjective"] = item.IsObjective
-
-		whereParam := map[string]interface{}{"mobile": item.Mobile}
-		err = models.UpdateByExpr(models.CygxXzsChooseSend{}, whereParam, updateParams)
+		err = models.UpdateCygxXzsChooseSend(item, itemsFllow)
 	}
 	if err != nil {
 		br.Msg = "保存失败!"

+ 8 - 27
controllers/wechat.go

@@ -161,12 +161,7 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 			resp.RealName = user.RealName
 			resp.HasPermission = 2
 		}
-		if resp.Headimgurl == "" {
-			resp.Headimgurl = user.HeadimgurlRecord
-		}
-	}
-	if resp.Headimgurl == "" {
-		resp.Headimgurl = utils.HeadimgurlDefault
+		resp.Headimgurl = user.HeadimgurlRecord
 	}
 	resp.Token = token
 	br.Ret = 200
@@ -225,36 +220,23 @@ func (this *WechatCommonController) GetWxSign() {
 
 // @Title 获取用户详情
 // @Description 获取用户详情接口
-// @Param   Token   query   string  true       "Token"
 // @Success 200 {object}  models.UserDetailByUserLogin
 // @router /user/detail [get]
-func (this *WechatCommonController) UserInfo() {
+func (this *WechatController) UserInfo() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	token := this.GetString("Token")
-	if token == "" {
-		br.Msg = "参数错误"
-		br.ErrMsg = "Token 为空"
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
 		return
 	}
 	resp := new(models.UserDetailByUserLogin)
-	session, err := models.GetUnionidByToken(token)
-	if err != nil {
-		br.Msg = "获取用户信息失败"
-		br.ErrMsg = "查询session失败,Err:" + err.Error()
-		return
-	}
-	unionId := session.UnionId
-	user, err := models.GetWxUserItemByUserUnionId(unionId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取用户信息失败"
-		br.ErrMsg = "获取本地用户信息失败,Err:" + err.Error()
-		return
-	}
-	if user == nil {
+	if user.Mobile == "" {
 		resp.HasPermission = 3
 	} else {
 		permissionStr, err := models.GetCompanyPermission(user.CompanyId)
@@ -279,7 +261,6 @@ func (this *WechatCommonController) UserInfo() {
 	if resp.Headimgurl == "" {
 		resp.Headimgurl = utils.HeadimgurlDefault
 	}
-	resp.Token = utils.MD5(unionId)
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 2 - 0
models/chart_permission.go

@@ -7,7 +7,9 @@ import (
 type ChartPermissionResp struct {
 	ChartPermissionId int    `description:"权限id"`
 	PermissionName    string `description:"权限名称"`
+	AllTracks         string `default:"全部赛道";description:"全部赛道"`
 	List              []*IndustrialManagementRep
+	CheckList         []int
 }
 
 func GetChartPermissionAll(condition string) (items []*ChartPermissionResp, err error) {

+ 2 - 1
models/db.go

@@ -20,12 +20,13 @@ func init() {
 	//注册对象
 	orm.RegisterModel(
 		new(WxUser),
-		new(CygxSession),
 		new(WxUserLog),
 		new(WxUserCode),
 		new(UserRecord),
 		new(CygxUserRecord),
 		new(CygxXzsSession),
+		new(CygxXzsChooseSend),
+		new(CygxIndustryFllow),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 15 - 0
models/industry_fllow.go

@@ -17,6 +17,7 @@ type CygxIndustryFllow struct {
 	CreateTime             time.Time `description:"创建时间"`
 	ModifyTime             time.Time `description:"更新时间"`
 	RealName               string    `description:"用户实际名称"`
+	Source                 int       `description:"来源1查研观向,2查研观向小助手"`
 }
 
 type CygxIndustryFllowRep struct {
@@ -30,6 +31,13 @@ func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
 	return
 }
 
+//  批量新增
+func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
 //根据手机号获取用户关注的产业
 func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) {
 	o := orm.NewOrm()
@@ -37,3 +45,10 @@ func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err er
 	_, err = o.Raw(sql, mobile).QueryRows(&items)
 	return
 }
+
+func DelCygxIndustryFllow(activityId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
+	_, err = o.Raw(sql, activityId).Exec()
+	return
+}

+ 1 - 41
models/session.go

@@ -5,53 +5,13 @@ import (
 	"time"
 )
 
-type CygxSession struct {
-	SessionId       int `orm:"column(session_id);pk"`
-	UnionId         string
-	UserId          int
-	OpenId          string
-	AccessToken     string
-	ExpireTime      time.Time
-	CreatedTime     time.Time
-	LastUpdatedTime time.Time
-}
-
-func GetSessionByToken(token string) (item *CygxSession, err error) {
+func GetSessionByToken(token string) (item *CygxXzsSession, err error) {
 	sql := `SELECT * FROM cygx_xzs_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
 	o := orm.NewOrm()
 	err = o.Raw(sql, token).QueryRow(&item)
 	return
 }
 
-func GetSessionCountByToken(token string) (count int, err error) {
-	sql := `SELECT COUNT(1) AS count FROM cygx_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
-	o := orm.NewOrm()
-	err = o.Raw(sql, token).QueryRow(&count)
-	return
-}
-
-//添加用户session信息
-func AddSession(item *CygxSession) (err error) {
-	o := orm.NewOrm()
-	_, err = o.Insert(item)
-	return
-}
-
-func GetTokenByUid(uid int) (item *CygxSession, err error) {
-	sql := `SELECT * FROM cygx_session WHERE user_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
-	o := orm.NewOrm()
-	err = o.Raw(sql, uid).QueryRow(&item)
-	return
-}
-
-//根据用户id获取token
-func GetTokenByOpenId(openId string) (item *CygxSession, err error) {
-	sql := `SELECT * FROM cygx_session WHERE open_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
-	o := orm.NewOrm()
-	err = o.Raw(sql, openId).QueryRow(&item)
-	return
-}
-
 type CygxXzsSession struct {
 	SessionId       int `orm:"column(session_id);pk"`
 	UnionId         string

+ 65 - 3
models/xzs_choose_send.go

@@ -13,7 +13,6 @@ type CygxXzsChooseSend struct {
 	CompanyId    int       `description:"公司id"`
 	CompanyName  string    `description:"公司名称"`
 	RealName     string    `description:"用户实际名称"`
-	SellerName   string    `description:"所属销售"`
 	IsRefuse     int       `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
 	IsSubjective int       `description:"是否选择主观推送, 1 是 、 0否"`
 	IsObjective  int       `description:"是否选择客观推送, 1 是 、 0否"`
@@ -36,8 +35,30 @@ type SubmitChooseSendResp struct {
 }
 
 //添加
-func AddCygxXzsChooseSend(item *CygxXzsChooseSend) (err error) {
-	o := orm.NewOrm()
+func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+
+	//删除原有的关注记录
+	sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
+	_, err = o.Raw(sql, item.Mobile).Exec()
+
+	//批量添加新的关注记录
+	_, err = o.InsertMulti(len(itemsFllow), itemsFllow)
+	if err != nil {
+		return err
+	}
+
+	//添加所勾选的消息类型
 	_, err = o.Insert(item)
 	return
 }
@@ -49,3 +70,44 @@ func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
 	err = o.Raw(sql, mobile).QueryRow(&count)
 	return
 }
+
+//添加
+func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+
+	//删除原有的关注记录
+	sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
+	_, err = o.Raw(sql, item.Mobile).Exec()
+
+	//批量添加新的关注记录
+	_, err = o.InsertMulti(len(itemsFllow), itemsFllow)
+	if err != nil {
+		return err
+	}
+
+	//修改现有的类型
+	updateParams := make(map[string]interface{})
+	updateParams["UserId"] = item.UserId
+	updateParams["Mobile"] = item.Mobile
+	updateParams["Email"] = item.Email
+	updateParams["CompanyId"] = item.CompanyId
+	updateParams["CompanyName"] = item.CompanyName
+	updateParams["RealName"] = item.RealName
+	updateParams["ModifyTime"] = time.Now()
+	updateParams["IsRefuse"] = item.IsRefuse
+	updateParams["IsSubjective"] = item.IsSubjective
+	updateParams["IsObjective"] = item.IsObjective
+	whereParam := map[string]interface{}{"mobile": item.Mobile}
+	err = UpdateByExpr(CygxXzsChooseSend{}, whereParam, updateParams)
+	return
+}

+ 10 - 1
routers/commentsRouter_controllers.go

@@ -16,6 +16,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:UserController"],
+        beego.ControllerComments{
+            Method: "ChooseSubmit",
+            Router: "/choose/submit",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:WechatCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:WechatCommonController"],
         beego.ControllerComments{
             Method: "GetWxSign",
@@ -34,7 +43,7 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:WechatCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:WechatCommonController"],
+    beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:WechatController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygxzs/controllers:WechatController"],
         beego.ControllerComments{
             Method: "UserInfo",
             Router: "/user/detail",