Files
zmkgC/internal/app/common/controller/bususer.go

119 lines
3.9 KiB
Go
Raw Normal View History

2025-07-07 20:11:59 +08:00
package controller
import (
"context"
"regexp"
"strconv"
"strings"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
busFolderFile "github.com/tiger1103/gfast/v3/internal/app/system/logic/busFolderFile"
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/dao"
"github.com/tiger1103/gfast/v3/internal/app/wxApplet/model"
"github.com/tiger1103/gfast/v3/library/liberr"
)
// CommmonUpdateFile 修改施工人员图片/文件信息
func CommmonUpdateFile(ctx context.Context, filesListReq []*model.BusConstructionUserFileListRes, id int64, wxOrPc string, openid string, projectId int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
// 4、批量修改身份证等图片数据
if filesListReq != nil && id != 0 {
listReq := filesListReq
for i := range listReq {
//根据id+图片类型插入数据,如果数据存在则修改
//if wxOrPc != "1" {
// var str = ""
// busfile := strings.Split(listReq[i].Path, ",")
// for _, imgData := range busfile {
// str = str + strings.Replace(imgData, "file", "wxfile", 1) + ","
// }
// listReq[i].Path = str[0 : len(str)-1]
//}
_, err = dao.BusConstructionUserFile.Ctx(ctx).WherePri(listReq[i].Id).Update(listReq[i])
// 5、将图片信息添加到图库中
pe := strings.Split(listReq[i].Path, ",")
zjId := strconv.FormatUint(ct.New().GetLoginUser(ctx).Id, 10)
if wxOrPc != "1" {
zjId = openid
for i, imgData := range pe {
pe[i] = strings.Replace(imgData, "file", "wxfile", 1)
}
}
// 判断是否是图片,不是就不允许进入图库
for i, imgData := range pe {
re := regexp.MustCompile(`(?i)\.(` + coryCommon.PictureSuffix + `)$`)
match := re.FindString(imgData)
if match != "" {
err = busFolderFile.New().AllPicture(
ctx,
pe,
3,
dao.BusConstructionUserFile.Table(),
listReq[i].Id,
wxOrPc,
zjId,
"",
projectId,
)
}
}
}
}
liberr.ErrIsNil(ctx, err)
})
return
}
// @Title BatchUpdateTheOpenidsOfIndividualTables 2024/4/26 15:07:00
// @Description 批量更新各个表的openid 原因是最开始账号的openid是微信开发生成的如果当前账号进入过了小程序那就根据小程序的微信openid来
// @Auth Cory
// @param openid ---> "openid"
// @Return error ---> "错误信息"
func BatchUpdateTheOpenidsOfIndividualTables(ctx context.Context, openid string) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
tableNmaes := []string{
"bus_attendance",
"bus_complaint_box",
"bus_constructiom_user_signature",
"bus_construction_blacklist",
"bus_question_offline",
"bus_question_save",
"bus_question_save_pdf",
"bus_reissue_a_card",
"bus_violation_record",
"sys_project_team_member",
"user_registration",
"bus_askforleave",
}
// 1、批量修改对应表字段
for i := range tableNmaes {
err = updateFunc(ctx, tableNmaes[i], openid)
if err != nil {
liberr.ErrIsNil(ctx, err)
return
}
}
// 2、站班会不一样单独写sql sys_project_team_squad
sql := `UPDATE sys_project_team_squad set participant_id = REPLACE(participant_id,participant_id,` + "'" + openid + "'" + `) WHERE participant_id like '%` + openid + `%'`
_, err = g.DB().Exec(ctx, sql)
liberr.ErrIsNil(ctx, err)
_, err = g.DB().Model("sys_project_team_squad").Ctx(ctx).Unscoped().Where("compere_id", openid).Update(g.Map{"compere_id": openid})
liberr.ErrIsNil(ctx, err)
return
})
return err
})
return
}
func updateFunc(ctx context.Context, tableName string, openid string) (err error) {
op := "openid"
_, err = g.DB().Model(tableName).Ctx(ctx).Unscoped().Where(op, openid).Update(g.Map{op: openid})
return
}