Browse Source

orm->gorm

chenhan 5 months ago
parent
commit
a40d771452

+ 35 - 17
models/report_v2.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"errors"
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/models/report"
 	"eta_gn/eta_api/utils"
 	"github.com/beego/beego/v2/client/orm"
@@ -17,8 +18,9 @@ import (
 // @return reportId int64
 // @return err error
 func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGrant, addReportChapterList []AddReportChapter) (reportId int64, err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	to, err := o.Begin()
+	//o := orm.NewOrmUsingDB("rddp")
+	//to, err := o.Begin()
+	to := global.DmSQL["rddp"].Begin()
 	if err != nil {
 		return
 	}
@@ -31,7 +33,9 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 	}()
 
 	// 新增报告
-	reportId, err = to.Insert(reportItem)
+	//reportId, err = to.Insert(reportItem)
+	err = to.Create(reportItem).Error
+	reportId = int64(reportItem.Id)
 	if err != nil {
 		return
 	}
@@ -42,7 +46,8 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 		for _, v := range allGrantUserList {
 			v.ReportId = reportItem.Id
 		}
-		_, err = to.InsertMulti(500, allGrantUserList)
+		//_, err = to.InsertMulti(500, allGrantUserList)
+		err = to.CreateInBatches(allGrantUserList, utils.MultiAddNum).Error
 		if err != nil {
 			return
 		}
@@ -54,11 +59,13 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 			// 新增章节
 			chapterItem := addReportChapter.ReportChapter
 			chapterItem.ReportId = int(reportId)
-			cpId, tmpErr := to.Insert(chapterItem)
+			//cpId, tmpErr := to.Insert(chapterItem)
+			tmpErr := to.Create(chapterItem).Error
 			if tmpErr != nil {
 				err = tmpErr
 				return
 			}
+			cpId := chapterItem.ReportChapterId
 			chapterItem.ReportChapterId = int(cpId)
 
 			// 新增章节授权
@@ -67,7 +74,8 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 				for _, v := range grantList {
 					v.ReportChapterId = chapterItem.ReportChapterId
 				}
-				_, err = to.InsertMulti(500, grantList)
+				//_, err = to.InsertMulti(500, grantList)
+				err = to.CreateInBatches(grantList, utils.MultiAddNum).Error
 				if err != nil {
 					return
 				}
@@ -79,7 +87,8 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 				for _, v := range permissionList {
 					v.ReportChapterId = chapterItem.ReportChapterId
 				}
-				_, err = to.InsertMulti(500, permissionList)
+				//_, err = to.InsertMulti(500, permissionList)
+				err = to.CreateInBatches(permissionList, utils.MultiAddNum).Error
 				if err != nil {
 					return
 				}
@@ -101,8 +110,9 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
 // @param delReportGrantIdList []int
 // @return err error
 func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportGrantList []*report.ReportGrant, delReportGrantIdList []int) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	to, err := o.Begin()
+	//o := orm.NewOrmUsingDB("rddp")
+	//to, err := o.Begin()
+	to := global.DmSQL["rddp"].Begin()
 	if err != nil {
 		return
 	}
@@ -116,7 +126,8 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
 
 	// 变更报告章节信息
 	if len(updateCols) > 0 {
-		_, err = to.Update(reportInfo, updateCols...)
+		//_, err = to.Update(reportInfo, updateCols...)
+		err = to.Select(updateCols).Updates(reportInfo).Error
 		if err != nil {
 			return
 		}
@@ -124,7 +135,8 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
 
 	// 新增报告授权用户
 	if len(addReportGrantList) > 0 {
-		_, err = to.InsertMulti(500, addReportGrantList)
+		//_, err = to.InsertMulti(500, addReportGrantList)
+		err = to.CreateInBatches(addReportGrantList, utils.MultiAddNum).Error
 		if err != nil {
 			return
 		}
@@ -134,7 +146,8 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
 	delNum := len(delReportGrantIdList)
 	if delNum > 0 {
 		sql := `DELETE FROM report_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)`
-		_, err = to.Raw(sql, delReportGrantIdList).Exec()
+		//_, err = to.Raw(sql, delReportGrantIdList).Exec()
+		err = to.Exec(sql, delReportGrantIdList).Error
 		if err != nil {
 			return
 		}
@@ -152,8 +165,9 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
 // @param addChapterPermissionMap []*report.ReportChapterPermissionMapping
 // @return err error
 func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReportChapterGrantList []*report.ReportChapterGrant, addChapterPermissionMap []*report.ReportChapterPermissionMapping) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	to, err := o.Begin()
+	//o := orm.NewOrmUsingDB("rddp")
+	//to, err := o.Begin()
+	to := global.DmSQL["rddp"].Begin()
 	if err != nil {
 		return
 	}
@@ -165,10 +179,12 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
 		}
 	}()
 
-	lastId, err := to.Insert(reportChapterInfo)
+	//lastId, err := to.Insert(reportChapterInfo)
+	err = to.Create(reportChapterInfo).Error
 	if err != nil {
 		return
 	}
+	lastId := reportChapterInfo.ReportChapterId
 	reportChapterInfo.ReportChapterId = int(lastId)
 
 	// 新增报告章节授权用户
@@ -176,7 +192,8 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
 		for k, _ := range addReportChapterGrantList {
 			addReportChapterGrantList[k].ReportChapterId = reportChapterInfo.ReportChapterId
 		}
-		_, err = to.InsertMulti(500, addReportChapterGrantList)
+		//_, err = to.InsertMulti(500, addReportChapterGrantList)
+		err = to.CreateInBatches(addReportChapterGrantList, utils.MultiAddNum).Error
 		if err != nil {
 			return
 		}
@@ -188,7 +205,8 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
 			addChapterPermissionMap[k].ReportChapterId = reportChapterInfo.ReportChapterId
 		}
 
-		_, err = to.InsertMulti(500, addChapterPermissionMap)
+		//_, err = to.InsertMulti(500, addChapterPermissionMap)
+		err = to.CreateInBatches(addChapterPermissionMap, utils.MultiAddNum).Error
 		if err != nil {
 			return
 		}

+ 14 - 12
models/report_view_record.go

@@ -1,26 +1,28 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
 type ReportViewRecord struct {
-	Id          int       `orm:"column(id);pk"`
-	UserId      int       `description:"用户id"`
-	ReportId    int       `description:"报告id"`
-	Mobile      string    `description:"手机号"`
-	Email       string    `description:"邮箱"`
-	RealName    string    `description:"用户实际姓名"`
-	CompanyName string    `description:"公司名称"`
-	CreateTime  time.Time `description:"创建时间"`
+	Id          int       `gorm:"column:id;primaryKey;type:int" orm:"column(id);pk" description:"记录ID"`
+	UserId      int       `gorm:"column:user_id;type:int" orm:"column(user_id)" description:"用户ID"`
+	ReportId    int       `gorm:"column:report_id;type:int" orm:"column(report_id)" description:"报告ID"`
+	Mobile      string    `gorm:"column:mobile;type:varchar(255)" orm:"column(mobile)" description:"手机号"`
+	Email       string    `gorm:"column:email;type:varchar(255)" orm:"column(email)" description:"邮箱"`
+	RealName    string    `gorm:"column:real_name;type:varchar(255)" orm:"column(real_name)" description:"用户实际姓名"`
+	CompanyName string    `gorm:"column:company_name;type:varchar(255)" orm:"column(company_name)" description:"公司名称"`
+	CreateTime  time.Time `gorm:"column:create_time;type:datetime" orm:"column(create_time)" description:"创建时间"`
 }
 
-//获取需要修复的数据列表
+// 获取需要修复的数据列表
 func GetViewListByReportId(reportId int) (total int64, list []*ReportViewRecord, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	//o := orm.NewOrmUsingDB("rddp")
 	sql := `select * from report_view_record where report_id = ? order by id desc `
 
-	total, err = o.Raw(sql, reportId).QueryRows(&list)
+	//total, err = o.Raw(sql, reportId).QueryRows(&list)
+	err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
+	total = int64(len(list))
 	return
 }

+ 11 - 9
models/resource.go

@@ -1,15 +1,15 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
 type Resource struct {
-	Id           int       `orm:"column(id);" description:"资源id"`
-	ResourceUrl  string    `description:"资源地址"`
-	CreateTime   time.Time `description:"创建时间"`
-	ResourceType int       `description:"资源类型,1:图片,2:音频,3:视频 ,4:ppt"`
+	Id           int       `gorm:"column:id;primaryKey;type:int" orm:"column(id);" description:"资源ID"`
+	ResourceUrl  string    `gorm:"column:resource_url;type:varchar(255)" orm:"column(resource_url)" description:"资源地址"`
+	CreateTime   time.Time `gorm:"column:create_time;type:datetime" orm:"column(create_time)" description:"创建时间"`
+	ResourceType int       `gorm:"column:resource_type;type:int" orm:"column(resource_type)" description:"资源类型,1:图片,2:音频,3:视频,4:PPT"`
 }
 
 type ResourceResp struct {
@@ -24,15 +24,17 @@ type ResourceResp struct {
 }
 
 func AddResource(item *Resource) (newId int64, err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	newId, err = o.Insert(item)
+	//o := orm.NewOrmUsingDB("rddp")
+	//newId, err = o.Insert(item)
+	err = global.DmSQL["rddp"].Create(item).Error
 	return
 }
 
 func GetResourceById(id string) (item *Resource, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	//o := orm.NewOrmUsingDB("rddp")
 	sql := "SELECT * FROM resource WHERE id=? "
-	err = o.Raw(sql, id).QueryRow(&item)
+	//err = o.Raw(sql, id).QueryRow(&item)
+	err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
 	return
 }
 

+ 14 - 14
models/search_key_word.go

@@ -1,35 +1,35 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
 // SearchKeyWord 搜索关键词
 type SearchKeyWord struct {
-	SearchKeyWordId     int       `orm:"column(search_key_word_id)" description:"主键ID"`
-	KeyWord             string    `description:"关键词"`
-	From                string    `description:"来源,在什么地方筛选"`
-	CreatedTime         time.Time `description:"创建时间"`
-	LastUpdatedTime     time.Time `description:"更新时间"`
-	TeleconferenceImage string    `description:"电话会对应的类型图片"`
-	BannerImage         string    `description:"Banner图"`
+	SearchKeyWordId     int       `gorm:"column:search_key_word_id;primaryKey;type:int" orm:"column(search_key_word_id)" description:"主键ID"`
+	KeyWord             string    `gorm:"column:key_word;type:varchar(255)" orm:"column(key_word)" description:"关键词"`
+	From                string    `gorm:"column:from;type:varchar(255)" orm:"column(from)" description:"来源,在什么地方筛选"`
+	CreatedTime         time.Time `gorm:"column:created_time;type:datetime" orm:"column(created_time)" description:"创建时间"`
+	LastUpdatedTime     time.Time `gorm:"column:last_updated_time;type:datetime" orm:"column(last_updated_time)" description:"更新时间"`
+	TeleconferenceImage string    `gorm:"column:teleconference_image;type:varchar(255)" orm:"column(teleconference_image)" description:"电话会对应的类型图片"`
+	BannerImage         string    `gorm:"column:banner_image;type:varchar(255)" orm:"column(banner_image)" description:"Banner图"`
 }
 
 // AddTrendTagKeyWord 新增趋势标签关键词
 func AddTrendTagKeyWord(trend string) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := " REPLACE INTO search_key_word (`key_word`,`from`) values (?,'trend') "
-	_, err = o.Raw(sql, trend).Exec()
-
+	//_, err = o.Raw(sql, trend).Exec()
+	err = global.DEFAULT_DmSQL.Exec(sql, trend).Error
 	return
 }
 
 // GetKeyWordListByFrom 根据来源获取搜索关键词列表
 func GetKeyWordListByFrom(from string) (list []*SearchKeyWord, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := " SELECT * FROM search_key_word WHERE `from` = ? ORDER BY created_time ASC "
-	_, err = o.Raw(sql, from).QueryRows(&list)
-
+	//_, err = o.Raw(sql, from).QueryRows(&list)
+	err = global.DEFAULT_DmSQL.Raw(sql, from).Find(&list).Error
 	return
 }

+ 14 - 13
models/user_seller_relation.go

@@ -1,27 +1,28 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
 type UserSellerRelation struct {
-	RelationId int64     `orm:"column(relation_id);pk"`
-	UserId     int       `description:"用户id"`
-	CompanyId  int       `description:"企业用户id"`
-	SellerId   int       `description:"销售id"`
-	Seller     string    `description:"销售员名称"`
-	ProductId  int       `description:"产品id"`
-	Mobile     string    `description:"手机号"`
-	Email      string    `description:"邮箱"`
-	ModifyTime time.Time `description:"修改时间"`
-	CreateTime time.Time `description:"创建时间"`
+	RelationId int64     `gorm:"column:relation_id;primaryKey;type:bigint" orm:"column(relation_id);pk" description:"关系ID"`
+	UserId     int       `gorm:"column:user_id;type:int" orm:"column(user_id)" description:"用户ID"`
+	CompanyId  int       `gorm:"column:company_id;type:int" orm:"column(company_id)" description:"企业用户ID"`
+	SellerId   int       `gorm:"column:seller_id;type:int" orm:"column(seller_id)" description:"销售ID"`
+	Seller     string    `gorm:"column:seller;type:varchar(255)" orm:"column(seller)" description:"销售员名称"`
+	ProductId  int       `gorm:"column:product_id;type:int" orm:"column(product_id)" description:"产品ID"`
+	Mobile     string    `gorm:"column:mobile;type:varchar(255)" orm:"column(mobile)" description:"手机号"`
+	Email      string    `gorm:"column:email;type:varchar(255)" orm:"column(email)" description:"邮箱"`
+	ModifyTime time.Time `gorm:"column:modify_time;type:datetime" orm:"column(modify_time)" description:"修改时间"`
+	CreateTime time.Time `gorm:"column:create_time;type:datetime" orm:"column(create_time)" description:"创建时间"`
 }
 
 // DeleteUserSellerRelationByProductId 根据产品id删除销售员与员工的关系
 func DeleteUserSellerRelationByProductId(userId, productId int) (err error) {
-	o := orm.NewOrmUsingDB("weekly")
+	//o := orm.NewOrmUsingDB("weekly")
 	sql := ` DELETE FROM user_seller_relation WHERE user_id=? and product_id = ?`
-	_, err = o.Raw(sql, userId, productId).Exec()
+	//_, err = o.Raw(sql, userId, productId).Exec()
+	err = global.DmSQL["weekly"].Exec(sql, userId, productId).Error
 	return
 }

+ 7 - 6
models/user_view_history.go

@@ -1,14 +1,14 @@
 package models
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
-	"github.com/beego/beego/v2/client/orm"
 )
 
 type ResearchReportViewPUV struct {
-	ResearchReportId int
-	Pv               int
-	Uv               int
+	ResearchReportId int `gorm:"column:research_report_id;primaryKey;type:int" orm:"column(research_report_id);pk" description:"研究报告ID"`
+	Pv               int `gorm:"column:pv;type:int" orm:"column(pv)" description:"页面浏览量"`
+	Uv               int `gorm:"column:uv;type:int" orm:"column(uv)" description:"独立访客数"`
 }
 
 // GetPUVByResearchReportIds 通过报告IDs获取老报告PV、UV
@@ -16,7 +16,7 @@ func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPU
 	if len(reportIds) == 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("weekly")
+	//o := orm.NewOrmUsingDB("weekly")
 	sql := `SELECT
 				research_report_id,
 				COUNT(1) AS pv,
@@ -27,6 +27,7 @@ func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPU
 				research_report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)
 			GROUP BY
 				research_report_id`
-	_, err = o.Raw(sql, reportIds).QueryRows(&list)
+	//_, err = o.Raw(sql, reportIds).QueryRows(&list)
+	err = global.DmSQL["weekly"].Raw(sql, reportIds).Scan(&list).Error
 	return
 }

+ 7 - 5
models/wechat_send_msg.go

@@ -1,7 +1,7 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 )
 
 type OpenIdList struct {
@@ -16,8 +16,9 @@ func GetOpenIdArr() (items []string, err error) {
 		INNER JOIN user_record  AS ur ON wu.user_id=ur.user_id
           WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND  d.status IN('正式','试用','永续')
          ORDER BY FIELD(c.company_id, 16) desc, ur.user_record_id asc`
-	o := orm.NewOrmUsingDB("weekly")
-	_, err = o.Raw(sql).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("weekly")
+	//_, err = o.Raw(sql).QueryRows(&items)
+	err = global.DmSQL["weekly"].Raw(sql).Scan(&items).Error
 	return
 }
 
@@ -33,7 +34,8 @@ func GetOpenIdArrByClassifyId(classifyId int) (items []string, err error) {
 			AND g.from='rddp'
 			AND g.classify_id=?
 			ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC  `
-	o := orm.NewOrmUsingDB("weekly")
-	_, err = o.Raw(sql, classifyId).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("weekly")
+	//_, err = o.Raw(sql, classifyId).QueryRows(&items)
+	err = global.DmSQL["weekly"].Raw(sql, classifyId).Scan(&items).Error
 	return
 }

+ 41 - 35
models/wx_user.go

@@ -1,63 +1,67 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
 type WxUser struct {
-	UserId              int64  `gorm:"column:user_id"` //`orm:"column(user_id);pk"`
-	Mobile              string `go`
-	Email               string
-	CompanyId           int
-	RealName            string `description:"姓名"`
-	NickName            string `description:"昵称"`
-	CreatedTime         time.Time
-	MobileTwo           string `description:"备用手机号"`
-	BusinessCardUrl     string `description:"名片"`
-	IsMaker             int    `description:"是否决策人,1:是,0:否"`
-	Position            string `description:"职位"`
-	Sex                 int    `description:"普通用户性别,1为男性,2为女性"`
-	DepartmentName      string `description:"联系人部门"`
-	RegisterTime        time.Time
-	RegisterPlatform    int
-	Remark              string    `description:"备注"`
-	CountryCode         string    `description:"区号,86、852、886等"`
-	OutboundMobile      string    `description:"外呼手机号"`
-	OutboundCountryCode string    `description:"外呼手机号区号,86、852、886等"`
-	LastUpdatedTime     time.Time `description:"最近一次更新时间"`
-	IsDeal              int       `description:"是否标记处理 0-未处理 1-已处理"`
-	OpenId              string    `orm:"column(open_id)" description:"微信openid"`
-	Headimgurl          string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	UserLabel           string    `description:"查研观向用户标签"`
+	UserId              int64     `gorm:"column:user_id;primaryKey;type:bigint" orm:"column(user_id);pk" description:"用户ID"`
+	Mobile              string    `gorm:"column:mobile;type:varchar(255)" orm:"column(mobile)" description:"手机号"`
+	Email               string    `gorm:"column:email;type:varchar(255)" orm:"column(email)" description:"邮箱"`
+	CompanyId           int       `gorm:"column:company_id;type:int" orm:"column(company_id)" description:"公司ID"`
+	RealName            string    `gorm:"column:real_name;type:varchar(255)" orm:"column(real_name)" description:"姓名"`
+	NickName            string    `gorm:"column:nick_name;type:varchar(255)" orm:"column(nick_name)" description:"昵称"`
+	CreatedTime         time.Time `gorm:"column:created_time;type:datetime" orm:"column(created_time)" description:"创建时间"`
+	MobileTwo           string    `gorm:"column:mobile_two;type:varchar(255)" orm:"column(mobile_two)" description:"备用手机号"`
+	BusinessCardUrl     string    `gorm:"column:business_card_url;type:varchar(255)" orm:"column(business_card_url)" description:"名片"`
+	IsMaker             int       `gorm:"column:is_maker;type:int" orm:"column(is_maker)" description:"是否决策人,1:是,0:否"`
+	Position            string    `gorm:"column:position;type:varchar(255)" orm:"column(position)" description:"职位"`
+	Sex                 int       `gorm:"column:sex;type:int" orm:"column(sex)" description:"普通用户性别,1为男性,2为女性"`
+	DepartmentName      string    `gorm:"column:department_name;type:varchar(255)" orm:"column(department_name)" description:"联系人部门"`
+	RegisterTime        time.Time `gorm:"column:register_time;type:datetime" orm:"column(register_time)" description:"注册时间"`
+	RegisterPlatform    int       `gorm:"column:register_platform;type:int" orm:"column(register_platform)" description:"注册平台"`
+	Remark              string    `gorm:"column:remark;type:varchar(255)" orm:"column(remark)" description:"备注"`
+	CountryCode         string    `gorm:"column:country_code;type:varchar(255)" orm:"column(country_code)" description:"区号,86、852、886等"`
+	OutboundMobile      string    `gorm:"column:outbound_mobile;type:varchar(255)" orm:"column(outbound_mobile)" description:"外呼手机号"`
+	OutboundCountryCode string    `gorm:"column:outbound_country_code;type:varchar(255)" orm:"column(outbound_country_code)" description:"外呼手机号区号,86、852、886等"`
+	LastUpdatedTime     time.Time `gorm:"column:last_updated_time;type:datetime" orm:"column(last_updated_time)" description:"最近一次更新时间"`
+	IsDeal              int       `gorm:"column:is_deal;type:int" orm:"column(is_deal)" description:"是否标记处理 0-未处理 1-已处理"`
+	OpenId              string    `gorm:"column:open_id;type:varchar(255)" orm:"column(open_id)" description:"微信openid"`
+	Headimgurl          string    `gorm:"column:headimgurl;type:varchar(255)" orm:"column(headimgurl)" description:"用户头像"`
+	UserLabel           string    `gorm:"column:user_label;type:varchar(255)" orm:"column(user_label)" description:"查研观向用户标签"`
 }
 
 func GetWxUserByMobile(mobile string) (item *WxUser, err error) {
-	o := orm.NewOrmUsingDB("weekly")
+	//o := orm.NewOrmUsingDB("weekly")
 	sql := `SELECT * FROM wx_user WHERE mobile = ? LIMIT 1`
-	err = o.Raw(sql, mobile).QueryRow(&item)
+	//err = o.Raw(sql, mobile).QueryRow(&item)
+	err = global.DmSQL["weekly"].Raw(sql, mobile).First(&item).Error
 	return
 }
 
 // Update 更新wxUser信息
 func (wxUser *WxUser) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	_, err = o.Update(wxUser, cols...)
+	//o := orm.NewOrmUsingDB("weekly")
+	//_, err = o.Update(wxUser, cols...)
+	err = global.DmSQL["weekly"].Select(cols).Updates(wxUser).Error
 	return
 }
 
 // GetWxUserByCompanyIdAndMobile 根据客户ID及手机号获取用户
 func GetWxUserByCompanyIdAndMobile(companyId int, mobile string) (item *WxUser, err error) {
-	o := orm.NewOrmUsingDB("weekly")
+	//o := orm.NewOrmUsingDB("weekly")
 	sql := ` SELECT * FROM wx_user WHERE company_id = ? AND mobile = ? LIMIT 1 `
-	err = o.Raw(sql, companyId, mobile).QueryRow(&item)
+	//err = o.Raw(sql, companyId, mobile).QueryRow(&item)
+	err = global.DmSQL["weekly"].Raw(sql, companyId, mobile).First(&item).Error
 	return
 }
 
 // DeleteWxUserAndRecordByUserId 删除用户及第三方信息
 func DeleteWxUserAndRecordByUserId(userId int) (err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	to, err := o.Begin()
+	//o := orm.NewOrmUsingDB("weekly")
+	//to, err := o.Begin()
+	to := global.DmSQL["weekly"].Begin()
 	if err != nil {
 		return
 	}
@@ -71,11 +75,13 @@ func DeleteWxUserAndRecordByUserId(userId int) (err error) {
 
 	// 删除wx_user
 	userSql := ` DELETE FROM wx_user WHERE user_id = ? LIMIT 1 `
-	_, err = to.Raw(userSql, userId).Exec()
+	//_, err = to.Raw(userSql, userId).Exec()
+	err = to.Exec(userSql, userId).Error
 	// 删除user_record
 	if err == nil {
 		recordSql := ` DELETE FROM user_record WHERE user_id = ? `
-		_, err = to.Raw(recordSql, userId).Exec()
+		//_, err = to.Raw(recordSql, userId).Exec()
+		err = to.Exec(recordSql, userId).Error
 	}
 
 	return