소스 검색

Merge branch 'crm_14.0'

ziwen 1 년 전
부모
커밋
6fbff71f99
9개의 변경된 파일391개의 추가작업 그리고 0개의 파일을 삭제
  1. 182 0
      controller/help_doc.go
  2. BIN
      hz_eta_docs_api
  3. 1 0
      init_serve/router.go
  4. 47 0
      models/crm/eta_business.go
  5. 63 0
      models/crm/help_doc.go
  6. 41 0
      models/crm/help_doc_classify.go
  7. 11 0
      models/request/help_doc.go
  8. 14 0
      routers/help_doc.go
  9. 32 0
      services/help_doc_classify.go

+ 182 - 0
controller/help_doc.go

@@ -0,0 +1,182 @@
+package controller
+
+import (
+	"encoding/json"
+	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
+	"hongze/hz_eta_docs_api/controller/resp"
+	"hongze/hz_eta_docs_api/global"
+	"hongze/hz_eta_docs_api/models/crm"
+	"hongze/hz_eta_docs_api/models/request"
+	"hongze/hz_eta_docs_api/services"
+	"hongze/hz_eta_docs_api/utils"
+	"html"
+)
+
+// HelpDocController 帮助文档
+type HelpDocController struct{}
+
+// ClassifyList
+// @Description 帮助文档分类列表
+// @Success 200 {string} string "获取成功"
+// @Router /help_doc/classify/list [get]
+func (a *HelpDocController) ClassifyList(c *gin.Context) {
+	var req request.HelpDocClassifyListReq
+	err := c.Bind(&req)
+	if err != nil {
+		errs, ok := err.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+err.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
+		return
+	}
+	etaOb := new(crm.EtaBusiness)
+	var pars []interface{}
+	pars = append(pars, req.BusCode)
+	etaBusiness, e := etaOb.GetItemByCondition("code_encrypt=?", pars, "")
+	if e != nil {
+		resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
+		return
+	}
+
+	nodeAll := make([]*crm.HelpDocClassifyItems, 0)
+
+	if etaBusiness != nil{
+		// 获取列表数据
+		docOb := new(crm.HelpDocClassify)
+		var pars []interface{}
+		pars = append(pars, etaBusiness.EtaBusinessId)
+		rootList, e := docOb.GetItemsByCondition("parent_id=0 AND FIND_IN_SET(?,visible_business_ids) > 0 ", pars, "sort asc,classify_id asc")
+		if e != nil {
+			resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
+			return
+		}
+
+		classifyAll, e := docOb.GetItemsByCondition("FIND_IN_SET(?,visible_business_ids) > 0", pars, "sort asc,classify_id asc")
+		if e != nil {
+			resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
+			return
+		}
+
+		classifies := make([]*crm.HelpDocClassifyItems, 0)
+		for _, v := range classifyAll {
+			child := make([]*crm.HelpDocClassifyItems, 0)
+			item := crm.HelpDocClassifyItems{
+				ClassifyId:         v.ClassifyId,
+				ClassifyName:       v.ClassifyName,
+				ParentId:           v.ParentId,
+				Level:              v.Level,
+				Sort:               v.Sort,
+				SysUserId:          v.SysUserId,
+				SysUserRealName:    v.SysUserRealName,
+				VisibleBusinessIds: v.VisibleBusinessIds,
+				Children:           child,
+			}
+			classifies = append(classifies, &item)
+		}
+
+		roots := make([]*crm.HelpDocClassifyItems, 0)
+		for _, v := range rootList {
+			child := make([]*crm.HelpDocClassifyItems, 0)
+			item := crm.HelpDocClassifyItems{
+				ClassifyId:         v.ClassifyId,
+				ClassifyName:       v.ClassifyName,
+				ParentId:           v.ParentId,
+				Level:              v.Level,
+				Sort:               v.Sort,
+				SysUserId:          v.SysUserId,
+				SysUserRealName:    v.SysUserRealName,
+				VisibleBusinessIds: v.VisibleBusinessIds,
+				Children:           child,
+			}
+			roots = append(roots, &item)
+		}
+
+		for k := range roots {
+			rootNode := roots[k]
+			services.HelpDocClassifyItemsMakeTree(classifies, rootNode)
+			nodeAll = append(nodeAll, rootNode)
+		}
+	}
+
+
+	resp.OkData("获取成功", nodeAll, c)
+}
+
+// Detail
+// @Description 文章详情
+// @Success 200 {string} string "获取成功"
+// @Router /help_doc/detail [get]
+func (a *HelpDocController) Detail(c *gin.Context) {
+	var req request.HelpDocClassifyDetailReq
+	err := c.Bind(&req)
+	if err != nil {
+		errs, ok := err.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+err.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
+		return
+	}
+
+	// 获取列表数据
+	docOb := new(crm.HelpDoc)
+	var pars []interface{}
+	pars = append(pars, req.ClassifyId)
+	item, e := docOb.GetItemByCondition("classify_id=?", pars, "")
+	if e != nil {
+		if e == utils.ErrNoRow {
+			resp.SpecificFail("获取失败", "文章不存在, Err: "+e.Error(), c)
+			return
+		}
+		resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
+		return
+	}
+
+	if item.Status != 2 {
+		resp.SpecificFail("获取失败", "文章未发布 ", c)
+		return
+	}
+	item.Content = html.UnescapeString(item.Content)
+
+	var anchor []crm.AnchorList
+	if item.Anchor != "" {
+		err = json.Unmarshal([]byte(item.Anchor), &anchor)
+		if err != nil {
+			resp.FailMsg("解析失败", "解析锚点失败, Err: "+e.Error(), c)
+			return
+		}
+	}
+
+	var recommend []crm.RecommendList
+	if item.Recommend != "" {
+		err = json.Unmarshal([]byte(item.Recommend), &recommend)
+		if err != nil {
+			resp.FailMsg("解析失败", "解析推荐链接失败, Err: "+e.Error(), c)
+			return
+		}
+	}
+
+	respItem := crm.HelpDocResp{
+		Id:            item.Id,
+		ClassifyId:    item.ClassifyId,
+		Title:         item.Title,
+		Author:        item.Author,
+		CreateTime:    item.CreateTime.Format(utils.FormatDateTime),
+		ModifyTime:    item.ModifyTime.Format(utils.FormatDateTime),
+		Status:        item.Status,
+		PublishTime:   item.PublishTime.Format(utils.FormatDateTime),
+		Content:       item.Content,
+		AdminId:       item.AdminId,
+		AdminRealName: item.AdminRealName,
+		Anchor:        anchor,
+		Recommend:     recommend,
+	}
+	if item.PublishTime.IsZero() {
+		respItem.PublishTime = ""
+	}
+	resp.OkData("获取成功", respItem, c)
+}

BIN
hz_eta_docs_api


+ 1 - 0
init_serve/router.go

@@ -18,5 +18,6 @@ func InitRouter() (r *gin.Engine) {
 
 	rBase := r.Group("api/")
 	routers.InitVersionUpdateLog(rBase) // 版本更新日志
+	routers.InitHelpDoc(rBase)          // 帮助文档
 	return
 }

+ 47 - 0
models/crm/eta_business.go

@@ -0,0 +1,47 @@
+package crm
+
+import (
+	"hongze/hz_eta_docs_api/global"
+	"time"
+)
+
+type EtaBusiness struct {
+	EtaBusinessId    int       `gorm:"column:eta_business_id;primary_key;AUTO_INCREMENT" json:"eta_business_id"`
+	BusinessName     string    `gorm:"column:business_name;NOT NULL" json:"business_name"`             // 商家名称
+	BusinessCode     string    `gorm:"column:business_code;NOT NULL" json:"business_code"`             // 商家编码
+	CodeEncrypt      string    `gorm:"column:code_encrypt;NOT NULL" json:"code_encrypt"`               // 商家编码encrypt
+	CreditCode       string    `gorm:"column:credit_code;NOT NULL" json:"credit_code"`                 // 社会统一信用码
+	RegionType       string    `gorm:"column:region_type;NOT NULL" json:"region_type"`                 // 所属区域:国内;海外
+	Province         string    `gorm:"column:province;NOT NULL" json:"province"`                       // 省份
+	City             string    `gorm:"column:city;NOT NULL" json:"city"`                               // 城市
+	Address          string    `gorm:"column:address;NOT NULL" json:"address"`                         // 商家地址
+	SellerId         int       `gorm:"column:seller_id;default:0;NOT NULL" json:"seller_id"`           // 销售ID
+	SellerName       string    `gorm:"column:seller_name;NOT NULL" json:"seller_name"`                 // 销售名称
+	Leader           string    `gorm:"column:leader;NOT NULL" json:"leader"`                           // 决策人
+	IndustryId       int       `gorm:"column:industry_id;default:0;NOT NULL" json:"industry_id"`       // 行业ID
+	IndustryName     string    `gorm:"column:industry_name;NOT NULL" json:"industry_name"`             // 行业名称
+	CapitalScale     string    `gorm:"column:capital_scale;NOT NULL" json:"capital_scale"`             // 资金规模
+	ResearchTeamSize string    `gorm:"column:research_team_size;NOT NULL" json:"research_team_size"`   // 研究团队规模
+	UserMax          int       `gorm:"column:user_max;default:0;NOT NULL" json:"user_max"`             // 用户上限
+	SigningStatus    int       `gorm:"column:signing_status;default:0;NOT NULL" json:"signing_status"` // 签约状态:0-未签约;1-首次签约;2-续约中;3-已终止
+	Enable           int       `gorm:"column:enable;default:0;NOT NULL" json:"enable"`                 // 状态:0-禁用;1-启用
+	ContractId       int       `gorm:"column:contract_id;default:0;NOT NULL" json:"contract_id"`       // 当前签约ID
+	SigningTime      time.Time `gorm:"column:signing_time" json:"signing_time"`                        // 当前合约的签约时间
+	ExpiredTime      time.Time `gorm:"column:expired_time" json:"expired_time"`                        // 当前合约的到期时间
+	CreateTime       time.Time `gorm:"column:create_time" json:"create_time"`                          // 创建时间
+	ModifyTime       time.Time `gorm:"column:modify_time" json:"modify_time"`                          // 更新时间
+}
+
+
+func (m *EtaBusiness) TableName() string {
+	return "`eta_business`"
+}
+
+// GetItemByCondition 获取
+func (m *EtaBusiness) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *EtaBusiness, err error) {
+	if orderRule == "" {
+		orderRule = "create_time DESC"
+	}
+	err = global.MYSQL["hz_crm"].Where(condition, pars...).Order(orderRule).Limit(1).Find(&item).Error
+	return
+}

+ 63 - 0
models/crm/help_doc.go

@@ -0,0 +1,63 @@
+package crm
+
+import (
+	"hongze/hz_eta_docs_api/global"
+	"time"
+)
+
+type HelpDoc struct {
+	Id            int       `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
+	ClassifyId    int       `gorm:"column:classify_id;default:0" json:"classify_id"`                 // 分类id
+	ClassifyName  string    `gorm:"column:classify_name" json:"classify_name"`                       // 分类名称
+	Title         string    `gorm:"column:title" json:"title"`                                       // 标题
+	Author        string    `gorm:"column:author" json:"author"`                                     // 作者
+	CreateTime    time.Time `gorm:"column:create_time;default:CURRENT_TIMESTAMP" json:"create_time"` // 创建时间
+	ModifyTime    time.Time `gorm:"column:modify_time;default:CURRENT_TIMESTAMP" json:"modify_time"` // 修改时间
+	Status        int       `gorm:"column:status;default:1" json:"status"`                           // 1:未发布,2:已发布
+	PublishTime   time.Time `gorm:"column:publish_time" json:"publish_time"`                         // 发布时间
+	Content       string    `gorm:"column:content" json:"content"`                                   // 内容
+	AdminId       int       `gorm:"column:admin_id;default:0;NOT NULL" json:"admin_id"`              // 创建人
+	AdminRealName string    `gorm:"column:admin_real_name" json:"admin_real_name"`                   // 创建人姓名
+	Anchor        string    `gorm:"column:anchor" json:"anchor"`                                     // 锚点
+	Recommend     string    `gorm:"column:recommend" json:"recommend"`                               // 推荐
+}
+
+func (m *HelpDoc) TableName() string {
+	return "`help_doc`"
+}
+
+// GetItemByCondition 获取
+func (m *HelpDoc) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *HelpDoc, err error) {
+	if orderRule == "" {
+		orderRule = "create_time DESC"
+	}
+	err = global.MYSQL["hz_crm"].Where(condition, pars...).Order(orderRule).First(&item).Error
+	return
+}
+
+type HelpDocResp struct {
+	Id            int             `orm:"column(id);pk"`
+	ClassifyId    int             // 分类id
+	Title         string          // 标题
+	Author        string          // 作者
+	CreateTime    string          // 创建时间
+	ModifyTime    string          // 修改时间
+	Status        int             // 1:未发布,2:已发布
+	PublishTime   string          // 发布时间
+	Content       string          // 内容
+	AdminId       int             // 创建人
+	AdminRealName string          // 创建人姓名
+	Anchor        []AnchorList    // 锚点
+	Recommend     []RecommendList // 推荐
+}
+type AnchorList struct {
+	AnchorId   string
+	Anchor     string
+	AnchorName string
+	Child      []AnchorList
+}
+
+type RecommendList struct {
+	Name string
+	Url  string
+}

+ 41 - 0
models/crm/help_doc_classify.go

@@ -0,0 +1,41 @@
+package crm
+
+import "hongze/hz_eta_docs_api/global"
+
+type HelpDocClassify struct {
+	ClassifyId         int    `gorm:"column:classify_id;primary_key;AUTO_INCREMENT" json:"classify_id"`
+	ClassifyName       string `gorm:"column:classify_name;NOT NULL" json:"classify_name"`   // 分类名称
+	ParentId           int    `gorm:"column:parent_id;default:0;NOT NULL" json:"parent_id"` // 父级id
+	CreateTime         string `gorm:"column:create_time" json:"create_time"`                // 创建时间
+	ModifyTime         string `gorm:"column:modify_time" json:"modify_time"`                // 修改时间
+	SysUserId          int    `gorm:"column:sys_user_id" json:"sys_user_id"`                // 创建人id
+	SysUserRealName    string `gorm:"column:sys_user_real_name" json:"sys_user_real_name"`  // 创建人姓名
+	Level              int    `gorm:"column:level;default:0" json:"level"`                  // 层级
+	Sort               int    `gorm:"column:sort;default:10" json:"sort"`                   // 排序字段,越小越靠前,默认值:10
+	VisibleBusinessIds string `gorm:"column:visible_business_ids;NOT NULL" json:"-"`        // 可见商家ids
+}
+
+func (m *HelpDocClassify) TableName() string {
+	return "`help_doc_classify`"
+}
+
+// GetItemsByCondition 获取列表
+func (m *HelpDocClassify) GetItemsByCondition(condition string, pars []interface{}, orderRule string) (items []*HelpDocClassify, err error) {
+	if orderRule == "" {
+		orderRule = "create_time DESC"
+	}
+	err = global.MYSQL["hz_crm"].Where(condition, pars...).Order(orderRule).Find(&items).Error
+	return
+}
+
+type HelpDocClassifyItems struct {
+	ClassifyId         int `description:"分类id"`
+	ClassifyName       string
+	ParentId           int
+	Level              int    `description:"层级"`
+	Sort               int    `description:"排序字段,越小越靠前,默认值:10"`
+	SysUserId          int    `description:"创建人id"`
+	SysUserRealName    string `description:"创建人姓名"`
+	VisibleBusinessIds string `json:"-"`
+	Children           []*HelpDocClassifyItems
+}

+ 11 - 0
models/request/help_doc.go

@@ -0,0 +1,11 @@
+package request
+
+// VersionUpdateLogListReq 更新日志列表请求体
+type HelpDocClassifyListReq struct {
+	BusCode string `json:"bus_code" form:"bus_code"`
+}
+
+type HelpDocClassifyDetailReq struct {
+	BusCode string `json:"bus_code" form:"bus_code"`
+	ClassifyId string `json:"classify_id" form:"classify_id"`
+}

+ 14 - 0
routers/help_doc.go

@@ -0,0 +1,14 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hz_eta_docs_api/controller"
+)
+
+func InitHelpDoc(r *gin.RouterGroup) {
+	c := new(controller.HelpDocController)
+	authGroup := r.Group("help_doc/")
+	authGroup.GET("classify/list", c.ClassifyList)
+	authGroup.GET("detail", c.Detail)
+}
+

+ 32 - 0
services/help_doc_classify.go

@@ -0,0 +1,32 @@
+package services
+
+import "hongze/hz_eta_docs_api/models/crm"
+
+func helpDocClassifyHaveChild(allNode []*crm.HelpDocClassifyItems, node *crm.HelpDocClassifyItems) (childs []*crm.HelpDocClassifyItems, yes bool) {
+	for _, v := range allNode {
+		if v.ParentId == node.ClassifyId {
+			childs = append(childs, v)
+		}
+	}
+	if len(childs) > 0 {
+		yes = true
+	}
+	return
+}
+
+func HelpDocClassifyItemsMakeTree(allNode []*crm.HelpDocClassifyItems, node *crm.HelpDocClassifyItems) {
+	childs, _ := helpDocClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
+	if len(childs) > 0 {
+		node.Children = append(node.Children, childs[0:]...) //添加子节点
+		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+			_, has := helpDocClassifyHaveChild(allNode, v)
+			if has {
+				HelpDocClassifyItemsMakeTree(allNode, v) //递归添加节点
+			} else {
+				v.Children = nil
+			}
+		}
+	} else {
+		node.Children = nil
+	}
+}