Explorar o código

Merge branch 'cygx/cygx_need_928' of http://8.136.199.33:3000/hongze/hz_crm_api

xingzai hai 11 meses
pai
achega
2ecf9e168e

+ 63 - 1
controllers/cygx/yanxuan_special.go

@@ -2,6 +2,7 @@ package cygx
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"github.com/tealeg/xlsx"
 	"hongze/hz_crm_api/controllers"
@@ -75,6 +76,7 @@ func (this *YanxuanSpecialController) Add() {
 		UserId:      req.UserId,
 		RealName:    req.RealName,
 		Mobile:      req.Mobile,
+		MobileInit:  infoUser.Mobile,
 		CompanyName: infoUser.CompanyName,
 		CompanyId:   infoUser.CompanyId,
 		CreateTime:  time.Now(),
@@ -252,15 +254,46 @@ func (this *YanxuanSpecialController) AuthorList() {
 	}
 
 	var userIds []int
-
+	var mobiles []string
 	for _, v := range list {
 		userIds = append(userIds, v.UserId)
+		if v.MobileInit != "" {
+			mobiles = append(mobiles, v.MobileInit)
+		}
+	}
+
+	listUser, err := models.GetWxUserRaiSllerListByUserMobile(mobiles)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
 	}
+	//获取用户当前最新的公司信息
+	mapWxUserSller := make(map[string]*models.WxUserSller)
+	for _, v := range listUser {
+		mapWxUserSller[v.Mobile] = v
+	}
+
+	//对权益管理员跟超管展示全部手机号
+	var isShow bool
+	if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
+		isShow = true
+	}
+
 	//获取专栏用户最新的一篇文章信息
 	mapNewTime := cygxService.GetBestNewYanxuanSpecialByUserId(userIds)
 	for _, v := range list {
 		v.SpecialAuthorId = v.Id
 		v.ArticlePublishTime = mapNewTime[v.UserId]
+		mapItem := mapWxUserSller[v.MobileInit]
+		if mapItem != nil {
+			v.CompanyName = mapItem.CompanyName
+			v.CompanyId = mapItem.CompanyId
+		}
+		if isShow {
+			v.Mobile = v.MobileInit
+		}
+
 	}
 	resp := new(cygx.GetCygxYanxuanSpecialAuthorItemResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)
@@ -812,3 +845,32 @@ func (this *YanxuanSpecialController) SpecialAuthorFansList() {
 	br.Success = true
 	br.Msg = "获取成功"
 }
+
+func init_928() {
+	var condition string
+	var pars []interface{}
+	list, err := cygx.GetYanxuanSpecialAuthorList(condition, pars, 0, 999)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	for k, v := range list {
+		fmt.Println(k)
+		//获取关联公司的用户信息
+		infoUser, err := cygx.GetUserAndCompanyNameList(v.UserId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			fmt.Println(err)
+			return
+		}
+		if infoUser == nil {
+			continue
+		}
+		err = cygx.UpdateSpecialAuthormobile_init(infoUser.Mobile, infoUser.UserId)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+	}
+	return
+}

+ 12 - 0
models/cygx/cygx_yanxuan_special_user.go

@@ -15,6 +15,7 @@ type CygxYanxuanSpecialAuthor struct {
 	NickName     string    // 昵称
 	RealName     string    // 姓名
 	Mobile       string    // 手机号
+	MobileInit   string    // 初始化手机号(没有脱敏的)
 	CreateTime   time.Time // 创建时间
 	ModifyTime   time.Time // 修改时间
 	HeadImg      string    // 头像
@@ -30,12 +31,14 @@ type CygxYanxuanSpecialAuthorItem struct {
 	Id                 int    `orm:"column(id);pk"`
 	UserId             int    // 用户ID
 	CompanyName        string // 公司名
+	CompanyId          int    // 公Id
 	SpecialName        string // 专栏名称
 	Introduction       string // 介绍
 	Label              string // 标签
 	NickName           string // 昵称
 	RealName           string // 姓名
 	Mobile             string // 手机号
+	MobileInit         string // 初始化手机号(没有脱敏的)
 	CreateTime         string // 创建时间
 	ModifyTime         string // 修改时间
 	HeadImg            string // 头像
@@ -135,3 +138,12 @@ type CygxYanxuanSpecialCenterAuthorResp struct {
 	PublishTime string // 提审过审或驳回时间
 	Title       string // 标题
 }
+
+// 启用禁用作者
+func UpdateSpecialAuthormobile_init(mobile_init string, userId int) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET mobile_init = ?  WHERE user_id = ? `
+	_, err = o.Raw(sql, mobile_init, userId).Exec()
+	return
+}

+ 27 - 1
models/wx_user.go

@@ -562,6 +562,32 @@ func GetWxUserRaiSllerListByUserIds(userIds []int) (list []*WxUserSller, err err
 	return
 }
 
+// GetWxUserRaiSllerListByUserMobile 根据用户手机号获取权益相关用户信息
+func GetWxUserRaiSllerListByUserMobile(mobiles []string) (list []*WxUserSller, err error) {
+	lenarr := len(mobiles)
+	if lenarr == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := ` SELECT
+				w.user_id,
+				w.real_name,
+				w.mobile,
+				c.company_name,
+				c.company_id,
+				p.seller_name 
+			FROM
+				wx_user AS w
+				INNER JOIN company_product AS p ON p.company_id = w.company_id
+				INNER JOIN company AS c ON c.company_id = w.company_id 
+			WHERE
+				1 = 1 
+				AND p.product_id = 2 
+				AND w.mobile IN (` + utils.GetOrmInReplace(lenarr) + `)  `
+	_, err = o.Raw(sql, mobiles).QueryRows(&list)
+	return
+}
+
 // GetWxUserByCompanyIds 根据客户ID集合获取用户列表
 func GetWxUserByCompanyIds(companyIds []int) (items []*WxUser, err error) {
 	num := len(companyIds)
@@ -598,4 +624,4 @@ func GetCompanyFollowCount(companyId int) (count int, err error) {
 	sql := ` SELECT COUNT(1) FROM wx_user WHERE company_id=? AND is_follow = 1 `
 	err = o.Raw(sql, companyId).QueryRow(&count)
 	return
-}
+}