Selaa lähdekoodia

移动图表分类修改

xyxie 3 kuukautta sitten
vanhempi
commit
f67f00cac7

+ 4 - 0
controllers/eta_business/eta_business.go

@@ -1582,6 +1582,10 @@ func (this *EtaBusinessController) AddChartPermission() {
 		item := new(eta_business.BusinessChartClassifyPermission)
 		item.ChartClassifyId = classifyId
 		item.BusinessCode = businessInfo.BusinessCode
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.AdminId = sysUser.AdminId
+		item.Source = 1
 		addList = append(addList, item)
 	}
 

+ 5 - 1
controllers/eta_business/user.go

@@ -278,6 +278,7 @@ func (this *EtaBusinessUserController) AddUser() {
 	user.RealName = utils.TrimStr(req.RealName)
 	user.CountryCode = utils.TrimStr(req.CountryCode)
 	user.Mobile = utils.TrimStr(req.Mobile)
+	user.UserName = user.Mobile
 	user.Position = req.Position
 	user.PositionStatus = req.PositionStatus
 	user.Enabled = 1
@@ -484,10 +485,11 @@ func (this *EtaBusinessUserController) EditUser() {
 	}
 
 	//待更新字段
-	updateCol := []string{"RealName", "Mobile", "LastUpdatedTime", "Position", "PositionStatus", "DepartmentName", "BusinessCode", "CountryCode"}
+	updateCol := []string{"RealName", "Mobile", "UserName", "LastUpdatedTime", "Position", "PositionStatus", "DepartmentName", "BusinessCode", "CountryCode"}
 
 	userInfo.RealName = req.RealName
 	userInfo.Mobile = req.Mobile
+	userInfo.UserName = userInfo.Mobile
 	userInfo.LastUpdatedTime = time.Now()
 	userInfo.Position = req.Position
 	userInfo.DepartmentName = req.DepartmentName
@@ -694,6 +696,7 @@ func (this *EtaBusinessUserController) ImportList() {
 					item.PositionStatus = 0
 				}
 				item.Mobile = mobileOne
+				item.UserName = item.Mobile
 				item.Position = position
 				item.DepartmentName = departmentName
 				// 查询商户信息
@@ -970,6 +973,7 @@ func (this *EtaBusinessUserController) Import() {
 					item.PositionStatus = 0
 				}
 				item.Mobile = mobileOne
+				item.UserName = item.Mobile
 				item.Position = position
 				item.DepartmentName = departmentName
 				// 查询商户信息

+ 8 - 0
models/chart_classify.go

@@ -23,6 +23,7 @@ type ChartClassify struct {
 	Source              int       `description:"1:ETA图库;2:商品价格曲线"`
 	IsJoinPermission    int       `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
 	ChartClassifyNameEn string    `description:"英文分类名称"`
+	LevelPath           string    `description:"分类的所有上级分类包括自己"`
 }
 
 func AddChartClassify(item *ChartClassify) (lastId int64, err error) {
@@ -424,3 +425,10 @@ func (m ChartClassifyItemList) Less(i, j int) bool {
 func (m ChartClassifyItemList) Swap(i, j int) {
 	m[i], m[j] = m[j], m[i]
 }
+
+func GetChartClassifyByLevelPath(levelPath string) (items []*ChartClassify, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM chart_classify where level_path like "` + levelPath + `%"`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 9 - 8
models/db.go

@@ -78,14 +78,15 @@ func initETATrial() {
 // initEtaBusiness ETA商家相关表
 func initEtaBusiness() {
 	orm.RegisterModel(
-		new(eta_business.EtaBusiness),                // ETA商家表
-		new(eta_business.EtaBusinessContract),        // ETA合同表
-		new(eta_business.EtaBusinessOperationRecord), // ETA操作记录表
-		new(eta_business.EtaBusinessMenu),            // ETA商家菜单表
-		new(eta_business.EtaBusinessMenuRelate),      // ETA商家菜单关联表
-		new(eta_business.EtaBusinessConfigRelate),    // ETA商家配置关联表
-		new(eta_business.EtaBusinessMenuIcon),        // ETA商家菜单icon表
-		new(User),                                    // 商家用户表
+		new(eta_business.EtaBusiness),                     // ETA商家表
+		new(eta_business.EtaBusinessContract),             // ETA合同表
+		new(eta_business.EtaBusinessOperationRecord),      // ETA操作记录表
+		new(eta_business.EtaBusinessMenu),                 // ETA商家菜单表
+		new(eta_business.EtaBusinessMenuRelate),           // ETA商家菜单关联表
+		new(eta_business.EtaBusinessConfigRelate),         // ETA商家配置关联表
+		new(eta_business.EtaBusinessMenuIcon),             // ETA商家菜单icon表
+		new(User),                                         // 商家用户表
+		new(eta_business.BusinessChartClassifyPermission), //商家图表权限表
 	)
 }
 

+ 1 - 0
models/user.go

@@ -10,6 +10,7 @@ import (
 type User struct {
 	UserId               int `orm:"column(user_id);pk"`
 	BusinessCode         string
+	UserName             string `description:"用户名"`
 	RealName             string `description:"姓名"`
 	Mobile               string
 	Email                string

+ 55 - 2
services/chart_classify.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_forum_admin/utils"
 	"fmt"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -195,6 +196,7 @@ func AddChartClassify(chartClassifyName string, parentId, source int, lang strin
 	}
 	// 查询level值
 	level := 0
+	levelPath := ""
 	if parentId > 0 {
 		parentClassify, tErr := models.GetChartClassifyById(parentId)
 		if tErr != nil {
@@ -208,6 +210,7 @@ func AddChartClassify(chartClassifyName string, parentId, source int, lang strin
 			return
 		}
 		level = parentClassify.Level
+		levelPath = parentClassify.LevelPath
 	}
 
 	//获取该层级下最大的排序数
@@ -228,10 +231,26 @@ func AddChartClassify(chartClassifyName string, parentId, source int, lang strin
 	classifyInfo.Sort = maxSort + 1
 	classifyInfo.Source = source
 
-	_, err = models.AddChartClassify(classifyInfo)
-	if err != nil {
+	classifyId, e := models.AddChartClassify(classifyInfo)
+	if e != nil {
+		errMsg = "保存分类失败"
+		err = errors.New("保存分类失败,Err:" + e.Error())
+		return
+	}
+	if parentId > 0 {
+		levelPath = fmt.Sprintf("%s%d,", levelPath, classifyId)
+	} else {
+		levelPath = fmt.Sprintf("%d,", classifyId)
+	}
+	classifyInfo.ChartClassifyId = int(classifyId)
+	classifyInfo.LevelPath = levelPath
+	e = classifyInfo.Update([]string{"LevelPath"})
+	if e != nil {
+		errMsg = "保存分类失败"
+		err = errors.New("保存分类失败,Err:" + e.Error())
 		return
 	}
+
 	return
 }
 
@@ -614,6 +633,40 @@ func moveChartClassify(parentClassifyInfo, edbClassifyInfo, prevClassify, nextCl
 					}
 				}
 			}*/
+
+			if oldParentId != parentClassifyId {
+				oldLevelPath := edbClassifyInfo.LevelPath
+				levelPath := fmt.Sprintf("%s%d,", parentClassifyInfo.LevelPath, edbClassifyInfo.ChartClassifyId)
+				edbClassifyInfo.LevelPath = levelPath
+				err = edbClassifyInfo.Update([]string{"LevelPath"})
+				if err != nil {
+					err = fmt.Errorf("修改失败,Err:" + err.Error())
+					return
+				}
+
+				//更新子分类的levelpath
+				tmpList, e := models.GetChartClassifyByLevelPath(oldLevelPath)
+				if e != nil {
+					err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+					return
+				}
+				// 把原先的父级levePath,替换成最新的父级序列
+				for _, tmp := range tmpList {
+					//获取字符串前缀的位置
+					after, _ := strings.CutPrefix(tmp.LevelPath, oldLevelPath)
+					fmt.Println("after", after)
+					// 拼接字符串
+					if after != "" {
+						tmp.LevelPath = levelPath + after
+						tmp.ModifyTime = time.Now()
+						e = tmp.Update([]string{"LevelPath", "ModifyTime"})
+						if e != nil {
+							err = fmt.Errorf("修改子分类,Err:" + e.Error())
+							return
+						}
+					}
+				}
+			}
 		}
 	} else {
 		if chartInfo == nil {