Преглед на файлове

查研观向小助手赛道勾选回显

xingzai преди 2 години
родител
ревизия
0a8d7d141f
променени са 11 файла, в които са добавени 299 реда и са изтрити 306 реда
  1. 4 9
      controllers/base_auth.go
  2. 131 2
      controllers/user.go
  3. 7 10
      controllers/wechat.go
  4. 18 0
      models/chart_permission.go
  5. 20 0
      models/industrial_management.go
  6. 39 0
      models/industry_fllow.go
  7. 9 6
      models/session.go
  8. 0 60
      models/user_record.go
  9. 20 146
      models/wx_user.go
  10. 51 0
      models/xzs_choose_send.go
  11. 0 73
      services/user.go

+ 4 - 9
controllers/base_auth.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"fmt"
 	beego "github.com/beego/beego/v2/adapter"
-	"hongze/hongze_cygxzs/services"
 	"net/http"
 	"net/url"
 	"strconv"
@@ -66,17 +65,13 @@ func (this *BaseAuthController) Prepare() {
 				return
 			}
 			//wxUser, err := models.GetWxUserItemByUserId(session.UserId)
-			wxUser, err := services.GetWxUserItemByOpenId(session.OpenId)
-			if err != nil && err != services.ERR_USER_NOT_BIND {
-				if err.Error() == utils.ErrNoRow() {
-					this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取信息失败 " + strconv.Itoa(session.UserId)}, false, false)
-					this.StopRun()
-					return
-				}
-				this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取wx_user信息异常,Eerr:" + err.Error()}, false, false)
+			wxUser, err := models.GetWxUserAouthByUnionId(session.UnionId)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取信息失败 " + strconv.Itoa(session.UserId)}, false, false)
 				this.StopRun()
 				return
 			}
+
 			if wxUser == nil {
 				this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "admin is empty "}, false, false)
 				this.StopRun()

+ 131 - 2
controllers/user.go

@@ -1,7 +1,10 @@
 package controllers
 
 import (
+	"encoding/json"
 	"hongze/hongze_cygxzs/models"
+	"hongze/hongze_cygxzs/utils"
+	"time"
 )
 
 type UserController struct {
@@ -14,7 +17,7 @@ type UserCommonController struct {
 
 // @Title 获取用户的选择详情
 // @Description 获取用户的选择详情接口
-// @Success 200 {object}  models.UserDetailByUserLogin
+// @Success 200 {object}  models.CygxXzsChooseSendResp
 // @router /choose/detail [get]
 func (this *UserController) ChooseDetail() {
 	br := new(models.BaseResponse).Init()
@@ -22,9 +25,135 @@ func (this *UserController) ChooseDetail() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	resp := new(models.UserDetailByUserLogin)
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	mobile := user.Mobile
+	//所有的产业map
+	//var itemsIndustrial  []*models.IndustrialManagementRep
+	mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
+	mapFllow := make(map[int]int)
+	fllowList, err := models.GetCygxIndustryFllowList(mobile)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range fllowList {
+		mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
+	}
+	industrialList, err := models.GetindustrialManagement()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range industrialList {
+		if mapFllow[v.IndustrialManagementId] > 0 {
+			v.IsFllow = true
+		}
+		mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
+	}
+	permissionList, err := models.GetChartPermissionAll("")
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
+		return
+	}
+	for k, v := range permissionList {
+		permissionList[k].List = mapIndustrial[v.ChartPermissionId]
+	}
+	count, err := models.GetXzsChooseSendCountByMobile(mobile)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
+		return
+	}
+	resp := new(models.CygxXzsChooseSendResp)
+	if count == 0 {
+		resp.IsObjective = 1
+		resp.IsSubjective = 1
+	}
+	resp.List = permissionList
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 提交用户的选择详情
+// @Description 提交用户的选择详情接口
+// @Param	request	body models.ActivityIdRep true "type json string"
+// @Success 200 {object}  models.CygxXzsChooseSendResp
+// @router /choose/submit [post]
+func (this *UserController) ChooseSubmit() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+
+	var req models.SubmitChooseSendResp
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	mobile := user.Mobile
+	item := new(models.CygxXzsChooseSend)
+	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.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+	item.IsRefuse = req.IsRefuse
+	item.IsSubjective = req.IsSubjective
+	item.IsObjective = req.IsObjective
+	count, err := models.GetXzsChooseSendCountByMobile(mobile)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
+		return
+	}
+	if count == 0 {
+		err = models.AddCygxXzsChooseSend(item)
+	} 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)
+	}
+	if err != nil {
+		br.Msg = "保存失败!"
+		br.ErrMsg = "保存失败!,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}

+ 7 - 10
controllers/wechat.go

@@ -79,7 +79,7 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 	unionId := wxUserInfo.Unionid
 	if unionId == "" {
 		br.Msg = "获取用户信息失败"
-		br.ErrMsg = "获取unionid失败,unionid:" + item.Openid
+		br.ErrMsg = "获取unionid失败,unionid:" + wxUserInfo.Unionid
 		return
 	}
 	total, err := models.GetCygxUserRecordCount(openId)
@@ -106,15 +106,9 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 			return
 		}
 	}
-	//else {
-	//	err = models.UpdateCygxUserRecord(items)
-	//	if err != nil {
-	//		br.Msg = "获取用户信息失败"
-	//		br.ErrMsg = "添加openid失败,Err:" + err.Error()
-	//		return
-	//	}
-	//}
-	token := utils.MD5(unionId)
+	timeUnix := time.Now().Unix()
+	timeUnixStr := strconv.FormatInt(timeUnix, 10)
+	token := utils.MD5(unionId) + utils.MD5(timeUnixStr)
 	user, err := models.GetWxUserItemByUserUnionId(unionId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取用户信息失败"
@@ -131,8 +125,11 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 	if totalToken == 0 {
 		itemsSession := new(models.CygxXzsSession)
 		itemsSession.UnionId = unionId
+		itemsSession.OpenId = openId
 		itemsSession.AccessToken = token
 		itemsSession.CreatedTime = time.Now()
+		itemsSession.LastUpdatedTime = time.Now()
+		itemsSession.ExpireTime = time.Now().AddDate(0, 3, 0)
 		if user != nil {
 			itemsSession.UserId = user.UserId
 		}

+ 18 - 0
models/chart_permission.go

@@ -0,0 +1,18 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type ChartPermissionResp struct {
+	ChartPermissionId int    `description:"权限id"`
+	PermissionName    string `description:"权限名称"`
+	List              []*IndustrialManagementRep
+}
+
+func GetChartPermissionAll(condition string) (items []*ChartPermissionResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND show_type=1  AND permission_type!=2  ` + condition + ` ORDER BY sort ASC `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 20 - 0
models/industrial_management.go

@@ -0,0 +1,20 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type IndustrialManagementRep struct {
+	IndustrialManagementId int    `description:"产业ID"`
+	ChartPermissionId      int    `description:"权限id"`
+	IndustryName           string `description:"产业名称"`
+	IsFllow                bool   `description:"是否关注"`
+}
+
+//获取所有的产业
+func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industrial_management `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 39 - 0
models/industry_fllow.go

@@ -0,0 +1,39 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxIndustryFllow struct {
+	Id                     int       `orm:"column(id);pk"`
+	IndustrialManagementId int       `description:"产业D"`
+	UserId                 int       `description:"用户ID"`
+	Mobile                 string    `description:"手机号"`
+	Email                  string    `description:"邮箱"`
+	CompanyId              int       `description:"公司id"`
+	CompanyName            string    `description:"公司名称"`
+	Type                   int       `description:"操作方式,1报名,2取消报名"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+	RealName               string    `description:"用户实际名称"`
+}
+
+type CygxIndustryFllowRep struct {
+	IndustrialManagementId int `description:"产业D"`
+}
+
+//添加
+func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//根据手机号获取用户关注的产业
+func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industry_fllow WHERE mobile = ?`
+	_, err = o.Raw(sql, mobile).QueryRows(&items)
+	return
+}

+ 9 - 6
models/session.go

@@ -17,7 +17,7 @@ type CygxSession struct {
 }
 
 func GetSessionByToken(token string) (item *CygxSession, err error) {
-	sql := `SELECT * FROM cygx_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
+	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
@@ -53,11 +53,14 @@ func GetTokenByOpenId(openId string) (item *CygxSession, err error) {
 }
 
 type CygxXzsSession struct {
-	SessionId   int `orm:"column(session_id);pk"`
-	UserId      int
-	UnionId     string
-	AccessToken string
-	CreatedTime time.Time
+	SessionId       int `orm:"column(session_id);pk"`
+	UnionId         string
+	UserId          int
+	OpenId          string
+	AccessToken     string
+	ExpireTime      time.Time
+	CreatedTime     time.Time
+	LastUpdatedTime time.Time
 }
 
 //添加用户session信息

+ 0 - 60
models/user_record.go

@@ -38,63 +38,3 @@ func UnBindUserRecordByOpenid(openId string) (err error) {
 	_, err = o.Raw(msql, openId).Exec()
 	return
 }
-
-//根据用户id和平台id获取用户关系
-func GetUserRecordByUserId(userId, platform int) (item *UserRecord, err error) {
-	sql := `SELECT * FROM user_record WHERE user_id=? AND create_platform = ?`
-	err = orm.NewOrm().Raw(sql, userId, platform).QueryRow(&item)
-	return
-}
-
-//添加用户关系
-func AddUserRecord(record *UserRecord) (recordId int64, err error) {
-	o := orm.NewOrm()
-	recordId, err = o.Insert(record)
-	return
-}
-
-//根据openid绑定用户关系
-func BindUserRecordByOpenid(userId int, openId, bindAccount string) (err error) {
-	o := orm.NewOrm()
-	msql := " UPDATE user_record SET user_id = ?,bind_account=? WHERE open_id = ? "
-	_, err = o.Raw(msql, userId, bindAccount, openId).Exec()
-	return
-}
-
-//修改用户微信信息
-func ModifyUserRecordInfo(openId, nickName, headimgUrl, city, province, country, sessionKey string, sex, userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE user_record SET nick_name=?,headimgurl=?,sex=?,city=?,province=?,country=?,session_key=? WHERE user_id=? and open_id=? `
-	_, err = o.Raw(sql, nickName, headimgUrl, sex, city, province, country, sessionKey, userId, openId).Exec()
-	return
-}
-
-//修改用户微信信息
-func ModifyUserRecordByDetail(openId, unionId, nickName, headimgUrl, city, province, country string, sex, userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE user_record SET union_id=?, nick_name=?,headimgurl=?,sex=?,city=?,province=?,country=? WHERE user_id=? and open_id=? `
-	_, err = o.Raw(sql, unionId, nickName, headimgUrl, sex, city, province, country, userId, openId).Exec()
-	return
-}
-
-//修改用户微信信息
-func ModifyUserRecordSessionKey(openId, sessionKey string) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE user_record SET session_key=? WHERE open_id=? `
-	_, err = o.Raw(sql, sessionKey, openId).Exec()
-	return
-}
-
-//根据用户id和平台id获取用户关系
-func GetUserRecordByMobile(platform int, bindAccount string) (item *UserRecord, err error) {
-	sql := `SELECT * FROM user_record WHERE create_platform=? AND bind_account = ?`
-	err = orm.NewOrm().Raw(sql, platform, bindAccount).QueryRow(&item)
-	return
-}
-
-//获取该用户第一个的 三方信息(微信头像信息)
-func GetUserThirdRecordByUserId(userId int) (item *UserRecord, err error) {
-	sql := `SELECT * FROM user_record WHERE user_id = ? order by user_record_id asc`
-	err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
-	return
-}

+ 20 - 146
models/wx_user.go

@@ -50,13 +50,6 @@ type WxUser struct {
 	OutboundCountryCode string    `description:"外呼手机号区号"`
 }
 
-//添加用户信息
-func AddWxUser(item *WxUser) (lastId int64, err error) {
-	o := orm.NewOrm()
-	lastId, err = o.Insert(item)
-	return
-}
-
 type WxUserItem struct {
 	UserId              int       `description:"用户id"`
 	OpenId              string    `description:"open_id"`
@@ -85,12 +78,6 @@ type WxUserItem struct {
 	Source              int
 }
 
-func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
-	sql := `SELECT * FROM wx_user WHERE union_id=? `
-	err = orm.NewOrm().Raw(sql, unionid).QueryRow(&item)
-	return
-}
-
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
 	sql := `SELECT a.*,b.company_name FROM wx_user AS a
 			LEFT JOIN company AS b on a.company_id=b.company_id
@@ -99,12 +86,6 @@ func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
 	return
 }
 
-func GetWxUserItemByOpenId(openId string) (item *WxUserItem, err error) {
-	sql := `SELECT * FROM wx_user WHERE open_id=? `
-	err = orm.NewOrm().Raw(sql, openId).QueryRow(&item)
-	return
-}
-
 type WxLoginResp struct {
 	Authorization string
 	UserId        int
@@ -125,133 +106,6 @@ type WxGetUserInfoReq struct {
 	Iv            string `description:"iv"`
 }
 
-//修改用户会话key
-func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE wx_user SET session_key=? WHERE user_id=? `
-	_, err = o.Raw(sql, sessionKey, userId).Exec()
-	return
-}
-
-//添加用户信息
-func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string, gender, userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE wx_user SET union_id=?,unionid=?,nick_name=?,sex=?,province=?,city=?,country=?,headimgurl=? WHERE user_id=? `
-	_, err = o.Raw(sql, unionId, unionId, nickName, gender, province, city, country, avatar, userId).Exec()
-	return
-}
-
-//修改用户会话key
-func DeleteWxUserByUserId(userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `DELETE FROM wx_user WHERE user_id=? `
-	_, err = o.Raw(sql, userId).Exec()
-	return
-}
-
-type WxGetUserInfoResp struct {
-	//UsersId       int       `orm:"column(id);pk"`
-	//Mobile        string    `description:"手机号"`
-	//NickName      string    `description:"昵称"`
-	//Gender        int       `description:"用户性别 1:男性,2:女性,0:未知(默认)"`
-	//CreateTime    time.Time `description:"注册时间"`
-	//ModifyTime    time.Time `description:"修改时间"`
-	//AvatarUrl     string    `description:"头像地址"`
-	//City          string    `description:"城市"`
-	//Province      string    `description:"省"`
-	//Country       string    `description:"国家"`
-	//Language      string    `description:"语言"`
-	//Appid         string    `description:"Appid"`
-	//Timestamp     int64     `description:"时间戳"`
-	Authorization string `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
-}
-
-type WxGetPhoneNumberReq struct {
-	EncryptedData string `description:"encryptedData"`
-	Iv            string `description:"iv"`
-}
-
-func ModifyUsersMobile(usersId int, phoneNumber string) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE wx_user SET mobile=? WHERE user_id=? `
-	_, err = o.Raw(sql, phoneNumber, usersId).Exec()
-	return
-}
-
-type WxGetPhoneNumberResp struct {
-	PhoneNumber     string `description:"用户绑定的手机号(国外手机号会有区号)"`
-	PurePhoneNumber string `description:"没有区号的手机号"`
-	CountryCode     string `description:"区号"`
-}
-
-func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
-	sql := `SELECT a.*,b.company_name FROM wx_user AS a
-			LEFT JOIN company AS b on a.company_id=b.company_id
-			WHERE a.mobile=? `
-	err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
-	return
-}
-
-func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
-	sql := `SELECT * FROM wx_user WHERE email=? `
-	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
-	return
-}
-
-func ModifyReportLastViewTime(uid int) (err error) {
-	sql := ` UPDATE wx_user SET report_last_view_time=NOW()
-			WHERE user_id=? `
-	_, err = orm.NewOrm().Raw(sql, uid).Exec()
-	return
-}
-
-//变更联系人是否已注册状态
-func ModifyWxUserRegisterStatus(userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
-	_, err = o.Raw(sql, 1, userId).Exec()
-	return
-}
-
-//修改用户是否绑定外呼手机号弹窗
-func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
-	o := orm.NewOrm()
-	sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
-	_, err = o.Raw(sql, userId).Exec()
-	return
-}
-
-//列表
-func GetUserListAll() (items []*WxUserItem, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT * FROM wx_user  WHERE mobile <>'' AND outbound_mobile = ''`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-//修改手机号区号  8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
-func UPdateUserCountryCode(item *WxUserItem) (err error) {
-	o := orm.NewOrm()
-	if item.CountryCode == "" && len(item.Mobile) >= 11 {
-		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=86 , country_code=86  WHERE user_id = ?`
-		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
-	} else if item.CountryCode == "" && len(item.Mobile) == 8 {
-		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=852 , country_code=852  WHERE user_id = ?`
-		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
-	} else if item.CountryCode == "" && len(item.Mobile) == 9 {
-		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=886 , country_code=886  WHERE user_id = ?`
-		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
-	} else if item.CountryCode == "" && len(item.Mobile) == 10 {
-		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=1 , country_code=1  WHERE user_id = ?`
-		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
-	} else {
-		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=?  WHERE user_id = ?`
-		_, err = o.Raw(sql, item.Mobile, item.CountryCode, item.UserId).Exec()
-	}
-
-	return
-}
-
 func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
 	sql := `SELECT a.*,r.headimgurl as headimgurl_record, b.company_name FROM wx_user AS a
 			INNER JOIN company AS b on a.company_id=b.company_id
@@ -261,3 +115,23 @@ func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
 	err = orm.NewOrm().Raw(sql, unionId).QueryRow(&item)
 	return
 }
+
+//根据用户UnionId取相关信息
+func GetWxUserAouthByUnionId(UnionId string) (item *WxUserItem, err error) {
+	sql := `SELECT
+			a.*,
+			s.union_id,
+			b.company_name 
+		FROM
+			cygx_xzs_session  AS s
+			INNER JOIN  user_record as  r ON r.union_id = s.union_id 
+			LEFT JOIN wx_user AS a ON a.mobile = r.bind_account
+			LEFT JOIN company AS b ON a.company_id = b.company_id 
+		WHERE
+			s.union_id = ?
+		ORDER BY
+			a.company_id DESC 
+			LIMIT 1`
+	err = orm.NewOrm().Raw(sql, UnionId).QueryRow(&item)
+	return
+}

+ 51 - 0
models/xzs_choose_send.go

@@ -0,0 +1,51 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxXzsChooseSend struct {
+	Id           int       `orm:"column(id);pk"`
+	UserId       int       `description:"用户ID"`
+	Mobile       string    `description:"手机号"`
+	Email        string    `description:"邮箱"`
+	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否"`
+	CreateTime   time.Time `description:"创建时间"`
+	ModifyTime   time.Time `description:"更新时间"`
+}
+
+type CygxXzsChooseSendResp struct {
+	IsRefuse     int `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
+	IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
+	IsObjective  int `description:"是否选择客观推送, 1 是 、 0否"`
+	List         []*ChartPermissionResp
+}
+
+type SubmitChooseSendResp struct {
+	IsRefuse                int    `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
+	IsSubjective            int    `description:"是否选择主观推送, 1 是 、 0否"`
+	IsObjective             int    `description:"是否选择客观推送, 1 是 、 0否"`
+	IndustrialManagementIds string `description:"产业ID,多个用, 隔开"`
+}
+
+//添加
+func AddCygxXzsChooseSend(item *CygxXzsChooseSend) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+//获取数量
+func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
+	sql := ` SELECT  COUNT(1) AS count  FROM cygx_xzs_choose_send WHERE mobile = ? `
+	o := orm.NewOrm()
+	err = o.Raw(sql, mobile).QueryRow(&count)
+	return
+}

+ 0 - 73
services/user.go

@@ -1,77 +1,9 @@
 package services
 
 import (
-	"errors"
-	"fmt"
 	"hongze/hongze_cygxzs/models"
-	"hongze/hongze_cygxzs/utils"
 )
 
-var ERR_NO_USER_RECORD = errors.New("用户关系没有入库")
-var ERR_USER_NOT_BIND = errors.New("用户没有绑定")
-
-//通过openid获取用户信息
-func GetWxUserItemByOpenId(openid string) (item *models.WxUserItem, err error) {
-	//通过openid获取用户关联信息
-	userRecord, userRecordErr := models.GetUserRecordByOpenId(openid)
-	fmt.Println("userRecordErr", userRecordErr)
-	if userRecordErr != nil {
-		if userRecordErr.Error() == utils.ErrNoRow() {
-			err = ERR_NO_USER_RECORD
-			return
-		} else {
-			err = userRecordErr
-			return
-		}
-	}
-
-	//该openid在系统中没有关联关系
-	if userRecord == nil {
-		err = ERR_NO_USER_RECORD
-		return
-	}
-
-	//该openid没有绑定用户
-	if userRecord.UserId <= 0 {
-		err = ERR_USER_NOT_BIND
-		item = new(models.WxUserItem)
-		//格式化返回用户数据
-		formatWxUserAndUserRecord(item, userRecord)
-		return
-	}
-
-	//获取用户信息
-	item, wxUserErr := models.GetWxUserItemByUserId(userRecord.UserId)
-	fmt.Println("wxUserErr", wxUserErr)
-	if wxUserErr != nil {
-		err = wxUserErr
-		//如果是找不到数据,那么可能是该用户被删除了,但是user_record没有删除对应的关系
-		if wxUserErr.Error() == utils.ErrNoRow() {
-			//用户被删除了,但是user_record没有删除对应的关系,那么去解除绑定
-			userUnbindErr := models.UnBindUserRecordByOpenid(openid)
-			if userUnbindErr != nil {
-				err = userUnbindErr
-				return
-			}
-			//返回状态为 用户未绑定 逻辑代码
-			err = ERR_USER_NOT_BIND
-			item = new(models.WxUserItem)
-			//格式化返回用户数据
-			formatWxUserAndUserRecord(item, userRecord)
-			return
-		}
-		return
-	}
-	if item.RealName == "" {
-		item.RealName = userRecord.RealName
-	}
-	//格式化返回用户数据
-	formatWxUserAndUserRecord(item, userRecord)
-	return
-}
-
-
-
 //通过用户 关系表记录  和  用户记录  格式化返回 用户数据
 func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.UserRecord) {
 	wxUser.OpenId = userRecord.OpenId
@@ -82,8 +14,3 @@ func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.Use
 	wxUser.Headimgurl = userRecord.Headimgurl
 	wxUser.SessionKey = userRecord.SessionKey
 }
-
-
-
-
-