xingzai 1 anno fa
parent
commit
9f11e6d2c9

+ 1 - 95
models/cygx/activity_special_trip_bill.go

@@ -49,7 +49,7 @@ type CygxActivitySpecialTripBillList struct {
 
 // 添加
 func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	_, err = o.Insert(item)
 	if err != nil {
 		return
@@ -57,61 +57,11 @@ func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err erro
 	return
 }
 
-func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT *
-			FROM
-			cygx_activity_special_trip_bill  
-			WHERE 1 = 1 ` + condition
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT
-			b.*,
-			c.chart_permission_name 
-		FROM
-			cygx_activity_special_trip_bill AS b
-			LEFT JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
-		WHERE
-			1 = 1` + condition
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
 type AirborneCount struct {
 	Count             int
 	ChartPermissionId int ` description:"品种权限ID"`
 }
 
-// 获取空降的公司报名的记录
-func GetActivitySpecialTripAirborneListByActivitySpecial(condition string, pars []interface{}) (items []*AirborneCount, err error) {
-	sqlCount := ` SELECT chart_permission_id,COUNT(1) AS count
-		FROM
-			cygx_activity_special_meeting_detail AS t
-			INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id 
-		WHERE
-			 1= 1  	AND YEAR ( t.create_time )= YEAR (NOW()) ` + condition + `GROUP BY chart_permission_id`
-	o := orm.NewOrm()
-	_, err = o.Raw(sqlCount, pars).QueryRows(&items)
-	return
-}
-
-// 获取空降的公司报名的记录
-func GetActivitySpecialTripAirborneCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := ` SELECT COUNT(1) AS count
-		FROM
-			cygx_activity_special_meeting_detail AS t
-			INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id 
-		WHERE
-			 1= 1  	AND YEAR ( t.create_time )= YEAR (NOW()) ` + condition
-	o := orm.NewOrm()
-	err = o.Raw(sqlCount, pars).QueryRow(&count)
-	return
-}
-
 type CygxActivitySpecialTripBillDetailList struct {
 	Id                  int       `orm:"column(id);pk"`
 	UserId              int       `description:"用户id,多个用,隔开"`
@@ -135,22 +85,6 @@ type CygxActivitySpecialTripBillDetailList struct {
 	Total               string    `description:"总和"`
 }
 
-func GetCygxActivitySpecialTripBillDetailList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillDetailList, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT
-			b.*,
-			a.research_theme,
-			c.chart_permission_name 
-		FROM
-			cygx_activity_special_trip_bill AS b
-			INNER JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
-			INNER JOIN cygx_activity_special AS a ON a.activity_id = b.activity_id
-		WHERE
-			1 = 1` + condition
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
 type CygxActivitySpecialPointsBillRespItem struct {
 	Id                  int    `gorm:"column:id;primary_key;AUTO_INCREMENT"`
 	Content             string `gorm:"column:content" `                                 // 内容说明
@@ -169,31 +103,3 @@ type CygxActivitySpecialPointsBillResp struct {
 	List []*CygxActivitySpecialPointsBillRespItem
 }
 
-func GetCygxActivitySpecialTripBillDetailListAll(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillDetailList, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT
-			b.*,
-			a.research_theme,
-			c.chart_permission_name 
-		FROM
-			cygx_activity_special_trip_bill AS b
-			LEFT JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
-			LEFT JOIN cygx_activity_special AS a ON a.activity_id = b.activity_id
-		WHERE
-			1 = 1` + condition
-
-	sql += ` ORDER BY b.create_time DESC`
-	_, err = o.Raw(sql, pars).QueryRows(&item)
-	return
-}
-
-func GetCygxActivitySpecialTripBillByCompanyId(companyId int) (item *CygxActivitySpecialTripBill, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT
-			*
-		FROM
-			cygx_activity_special_trip_bill WHERE company_id = ? ORDER BY create_time DESC LIMIT 1
-		`
-	err = o.Raw(sql, companyId).QueryRow(&item)
-	return
-}

+ 1 - 15
models/cygx/cygx_activity_special_points_company.go

@@ -16,23 +16,9 @@ type CygxActivitySpecialInheritPointsCompany struct {
 	ChartPermissionName string    // 品种名称
 }
 
-func AddCygxActivitySpecialPointsCompany(item *CygxActivitySpecialInheritPointsCompany) (err error) {
-	o := orm.NewOrm()
-	_, err = o.Insert(item)
-	if err != nil {
-		return
-	}
-	return
-}
-
-func AddCygxActivitySpecialInheritPointsCompanyMulti(items []*CygxActivitySpecialInheritPointsCompany) (err error) {
-	o := orm.NewOrm()
-	_, err = o.InsertMulti(1, items)
-	return
-}
 
 func GetCygxActivitySpecialInheritPointsByCompanyId(companyId int) (list []*CygxActivitySpecialInheritPointsCompany, err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := ` SELECT * FROM cygx_activity_special_inherit_points_company WHERE company_id = ?  `
 	_, err = o.Raw(sql,companyId).QueryRows(&list)
 	return

+ 8 - 0
models/db_init.go

@@ -69,6 +69,14 @@ func init() {
 	report_db, _ := orm.GetDB("rddp")
 	report_db.SetConnMaxLifetime(10 * time.Minute)
 
+
+	_ = orm.RegisterDataBase("hz_cygx", "mysql", utils.MYSQL_URL_CYGX)
+	orm.SetMaxIdleConns("hz_cygx", 50)
+	orm.SetMaxOpenConns("hz_cygx", 100)
+
+	cygx_db, _ := orm.GetDB("hz_cygx")
+	cygx_db.SetConnMaxLifetime(10 * time.Minute)
+
 	orm.Debug = true
 	orm.DebugLog = orm.NewLog(utils.Binlog)
 

+ 5 - 13
models/tables/cygx_company_user_type/company_user_type.go

@@ -16,13 +16,13 @@ type CygxCompanyUserType struct {
 
 // 新增权益客户身份类型
 func AddCygxCompanyUserType(item *CygxCompanyUserType) (err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	_, err = o.Insert(item)
 	return
 }
 
 func GetCygxCompanyUserTypeByCompanyId(companyId int) (count int, err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT COUNT(1) AS count FROM cygx_company_user_type AS a WHERE a.company_id=?  `
 	err = o.Raw(sql, companyId).QueryRow(&count)
 	return
@@ -30,7 +30,7 @@ func GetCygxCompanyUserTypeByCompanyId(companyId int) (count int, err error) {
 
 // CygxCompanyUserType 更新权益客户身份类型
 func UpdateCygxCompanyUserType(companyId, useType int) (err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `UPDATE cygx_company_user_type SET customer_type_id=? WHERE company_id=? `
 	_, err = o.Raw(sql, useType, companyId).Exec()
 	return
@@ -38,23 +38,15 @@ func UpdateCygxCompanyUserType(companyId, useType int) (err error) {
 
 // 通过活动ID获取详情
 func GetCygxCompanyUserType(companyId int) (item *CygxCompanyUserType, err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT *  FROM cygx_company_user_type AS a WHERE a.company_id=?  `
 	err = o.Raw(sql, companyId).QueryRow(&item)
 	return
 }
 
-// 获取大套餐客户列表
-func GetCygxCompanyUserTypeList() (items []*CygxCompanyUserType, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT *  FROM cygx_company_user_type AS a WHERE a.customer_type_id=2  `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
 // CygxCompanyUserType 更新权益客户身份类型
 func UpdateCygxCompanyUserTypeAndPackageType(companyId, useType, packageType int) (err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `UPDATE cygx_company_user_type SET customer_type_id=?, package_type = ? WHERE company_id=? `
 	_, err = o.Raw(sql, useType, packageType, companyId).Exec()
 	return

+ 2 - 1
models/tables/cygx_config/config.go

@@ -15,7 +15,8 @@ type CygxConfig struct {
 
 
 func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT * FROM cygx_config WHERE config_code=? `
-	err = orm.NewOrm().Raw(sql, configCode).QueryRow(&item)
+	err = o.Raw(sql, configCode).QueryRow(&item)
 	return
 }

+ 22 - 0
models/wechat_send_msg.go

@@ -32,4 +32,26 @@ func GetUserRecordListByMobile(platform int, bindAccount string) (items []*OpenI
 	}
 	_, err = orm.NewOrm().Raw(sql, platform).QueryRows(&items)
 	return
+}
+
+// 根据手机号获取用户的openid
+func GetUserRecordListByMobileArr(bindAccount []string) (items []*OpenIdList, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	lenarr := len(bindAccount)
+	if lenarr == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
+	pars = append(pars, bindAccount)
+	sql := `SELECT
+			u.open_id,
+			u.cygx_user_id AS user_id 
+		FROM
+			cygx_user_record AS u 
+		WHERE
+			1 = 1  ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
 }

+ 8 - 9
services/company_approval_message.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hongze_mobile_admin/models"
 	"hongze/hongze_mobile_admin/models/tables/admin"
@@ -10,9 +11,7 @@ import (
 	"hongze/hongze_mobile_admin/models/tables/cygx_config"
 	"hongze/hongze_mobile_admin/services/alarm_msg"
 	"hongze/hongze_mobile_admin/utils"
-	"strings"
 	"time"
-	"errors"
 )
 
 //消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论,7:视频评论,8:线上路演评论
@@ -167,12 +166,11 @@ func AddCompanyApprovalMessageRai(companyId , companyContractId int, applyRealNa
 	if err != nil {
 		return
 	}
-	var mobiles string
+	var mobiles [] string
 	for _, v := range adminList {
-		mobiles += "'" + v.Mobile + "'" + ","
+		mobiles = append(mobiles,v.Mobile)
 	}
-	mobiles = strings.TrimRight(mobiles, ",")
-	openIdList, err := models.GetUserRecordListByMobile(4, mobiles)
+	openIdList, err := models.GetUserRecordListByMobileArr(mobiles)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		return err
 	}
@@ -199,14 +197,15 @@ func AddCompanyApprovalMessageWangYang(companyId , companyContractId int, applyR
 	var  keyword1, keyword2, keyword3, keyword4 string
 	keyword1 = companyName  + "(" + applyRealName+")"
 	keyword2 = "买方研选转正"
-	var mobiles string
+
 	cnf, e := cygx_config.GetConfigByCode(utils.TPL_MSG_WANG_YANG)
 	if e != nil {
 		err = errors.New("GetConfigByCode, Err: " + e.Error())
 		return
 	}
-	mobiles = cnf.ConfigValue
-	openIdList, err := models.GetUserRecordListByMobile(4, mobiles)
+	var mobiles [] string
+	mobiles = append(mobiles,cnf.ConfigValue)
+	openIdList, err := models.GetUserRecordListByMobileArr(mobiles)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		return err
 	}

+ 2 - 0
utils/config.go

@@ -12,6 +12,7 @@ var (
 	RunMode        string //运行模式
 	MYSQL_URL      string //数据库连接
 	MYSQL_URL_RDDP string //数据库连接
+	MYSQL_URL_CYGX         string // 查研观向
 
 	REDIS_CACHE string       //缓存地址
 	Rc          *cache.Cache //redis缓存
@@ -112,6 +113,7 @@ func init() {
 	logs.Info(RunMode + " 模式")
 	MYSQL_URL = config["mysql_url"]
 	MYSQL_URL_RDDP = config["mysql_url_rddp"]
+	MYSQL_URL_CYGX = config["mysql_url_cygx"]
 
 	REDIS_CACHE = config["beego_cache"]
 	if len(REDIS_CACHE) <= 0 {