更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -16,22 +16,10 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendCrmContactController CRM 联系人管理(客户 / 供应商的对接人)
|
||||
//
|
||||
// 数据复用已有的「公司联系人」表 models.ErpCompanyContact:
|
||||
// - related_type(1=客户,2=供应商) <-> company_type(customer/supplier)
|
||||
// - related_id <-> company_id
|
||||
// - contact_name <-> name
|
||||
// - mobile(手机号) <-> mobiles(JSON数组,取第一个)
|
||||
// - phone(座机) <-> phone
|
||||
// - wechat / qq / dingtalk / home_address / status <-> 同名字段
|
||||
//
|
||||
// 这样 CRM 联系人与 ERP 公司联系人是同一份数据,不会分裂。
|
||||
type BackendCrmContactController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// crmContactDTO 返回给前端的联系人结构
|
||||
type crmContactDTO struct {
|
||||
ID uint64 `json:"id"`
|
||||
RelatedType int `json:"related_type"`
|
||||
@@ -39,24 +27,23 @@ type crmContactDTO struct {
|
||||
RelatedName string `json:"related_name"`
|
||||
ContactName string `json:"contact_name"`
|
||||
Gender int8 `json:"gender"`
|
||||
Mobile string `json:"mobile"` // 手机号(mobiles 数组第一个)
|
||||
Mobiles string `json:"mobiles"` // 手机号原始 JSON 数组
|
||||
Phone string `json:"phone"` // 座机
|
||||
Mobile string `json:"mobile"`
|
||||
Mobiles string `json:"mobiles"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Wechat string `json:"wechat"` // 微信
|
||||
QQ string `json:"qq"` // QQ
|
||||
Dingtalk string `json:"dingtalk"` // 钉钉
|
||||
Wechat string `json:"wechat"`
|
||||
QQ string `json:"qq"`
|
||||
Dingtalk string `json:"dingtalk"`
|
||||
Department string `json:"department"`
|
||||
Position string `json:"position"`
|
||||
HomeAddress string `json:"home_address"` // 家庭住址
|
||||
HomeAddress string `json:"home_address"`
|
||||
IsPrimary int8 `json:"is_primary"`
|
||||
Remark string `json:"remark"`
|
||||
Status int8 `json:"status"` // 1-在职 0-离职
|
||||
Status int8 `json:"status"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
UpdateTime time.Time `json:"update_time"`
|
||||
}
|
||||
|
||||
// buildMobiles 将单个手机号转为 mobiles 的 JSON 数组字符串
|
||||
func buildMobiles(mobile string) string {
|
||||
mobile = strings.TrimSpace(mobile)
|
||||
if mobile == "" {
|
||||
@@ -70,7 +57,6 @@ func buildMobiles(mobile string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// buildMobilesFromList 将多个手机号去空、去重后转为 mobiles 的 JSON 数组字符串(最多 5 个,与 ERP 通讯录一致)
|
||||
func buildMobilesFromList(mobiles []string) string {
|
||||
cleaned := make([]string, 0, len(mobiles))
|
||||
seen := map[string]bool{}
|
||||
@@ -95,9 +81,6 @@ func buildMobilesFromList(mobiles []string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// normalizeMobiles 归一请求中的手机号:
|
||||
// 优先取 mobiles(数组,CRM 联系人支持登记多个手机号,如一人多号),
|
||||
// 缺省时回退单个 mobile(兼容线索转化 / 合同签约人自动建档等旧调用方)。
|
||||
func normalizeMobiles(mobiles []string, mobile string) string {
|
||||
if len(mobiles) == 0 {
|
||||
return buildMobiles(mobile)
|
||||
@@ -105,7 +88,6 @@ func normalizeMobiles(mobiles []string, mobile string) string {
|
||||
return buildMobilesFromList(mobiles)
|
||||
}
|
||||
|
||||
// splitMobiles 把手机号文本(JSON 数组 / 逗号等分隔符拼接)拆成号码列表(去空)
|
||||
func splitMobiles(mobiles string) []string {
|
||||
mobiles = strings.TrimSpace(mobiles)
|
||||
if mobiles == "" {
|
||||
@@ -137,12 +119,6 @@ func splitMobiles(mobiles string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// mobilesFromPayload 解析请求体中的手机号字段,兼容多种入参形式:
|
||||
// - JSON 数组:["138…","139…"](新前端)
|
||||
// - JSON 字符串:'["138…"]' 或 '138…,139…'(旧调用方)
|
||||
// - 缺省:回退单个 mobile / phone 字段
|
||||
//
|
||||
// 统一返回 mobiles 的 JSON 数组字符串(去空去重,最多 5 个)。
|
||||
func mobilesFromPayload(raw json.RawMessage, fallback string) string {
|
||||
if len(raw) > 0 {
|
||||
text := strings.TrimSpace(string(raw))
|
||||
@@ -163,7 +139,6 @@ func mobilesFromPayload(raw json.RawMessage, fallback string) string {
|
||||
return buildMobiles(fallback)
|
||||
}
|
||||
|
||||
// firstMobile 从 mobiles(JSON 数组或普通字符串)中取出第一个手机号
|
||||
func firstMobile(mobiles string) string {
|
||||
mobiles = strings.TrimSpace(mobiles)
|
||||
if mobiles == "" {
|
||||
@@ -178,7 +153,6 @@ func firstMobile(mobiles string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
// 非 JSON,按原样返回
|
||||
return mobiles
|
||||
}
|
||||
|
||||
@@ -196,7 +170,6 @@ func crmContactRelatedType(companyType string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// crmContactAtoi 将查询参数安全转为 int,非法值返回 0
|
||||
func crmContactAtoi(s string) int {
|
||||
n, _ := strconv.Atoi(strings.TrimSpace(s))
|
||||
return n
|
||||
@@ -217,7 +190,6 @@ func (c *BackendCrmContactController) crmContactOk(data interface{}) {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// toCrmContactDTO 模型转 DTO,names 为关联对象名称映射(key: "customer:123")
|
||||
func toCrmContactDTO(row models.ErpCompanyContact, names map[string]string) crmContactDTO {
|
||||
relatedType := crmContactRelatedType(row.CompanyType)
|
||||
key := fmt.Sprintf("%s:%d", row.CompanyType, row.CompanyID)
|
||||
@@ -246,7 +218,6 @@ func toCrmContactDTO(row models.ErpCompanyContact, names map[string]string) crmC
|
||||
}
|
||||
}
|
||||
|
||||
// loadRelatedNames 批量查询关联的客户/供应商名称,避免逐条查询
|
||||
func loadRelatedNames(tenantID string, rows []models.ErpCompanyContact) map[string]string {
|
||||
names := map[string]string{}
|
||||
if len(rows) == 0 || models.Orm == nil {
|
||||
@@ -286,7 +257,6 @@ func loadRelatedNames(tenantID string, rows []models.ErpCompanyContact) map[stri
|
||||
return names
|
||||
}
|
||||
|
||||
// clearOtherPrimary 将同一公司下的其他联系人取消主联系人,保证只有一个主联系人
|
||||
func clearOtherPrimary(tenantID, companyType string, companyID, excludeID uint64) {
|
||||
if models.Orm == nil || companyID == 0 {
|
||||
return
|
||||
@@ -300,8 +270,6 @@ func clearOtherPrimary(tenantID, companyType string, companyID, excludeID uint64
|
||||
_, _ = qs.Update(map[string]interface{}{"is_primary": 0})
|
||||
}
|
||||
|
||||
// isMobileNumber 粗略识别手机号(11 位、1 开头,忽略空格 / 横线等分隔符);
|
||||
// 非手机号按座机写入 phone 字段,保证联系人资料里手机号 / 座机分列正确。
|
||||
func isMobileNumber(phone string) bool {
|
||||
digits := strings.Map(func(r rune) rune {
|
||||
if r >= '0' && r <= '9' {
|
||||
@@ -312,7 +280,6 @@ func isMobileNumber(phone string) bool {
|
||||
return len(digits) == 11 && digits[0] == '1'
|
||||
}
|
||||
|
||||
// crmContactCompanyExists 关联企业(客户 / 供应商)在当前租户下是否存在且未删除
|
||||
func crmContactCompanyExists(tenantID, companyType string, companyID uint64) bool {
|
||||
if models.Orm == nil || companyID == 0 {
|
||||
return false
|
||||
@@ -329,7 +296,6 @@ func crmContactCompanyExists(tenantID, companyType string, companyID uint64) boo
|
||||
return err == nil && cnt > 0
|
||||
}
|
||||
|
||||
// contactPhoneMatched 联系人是否已登记该电话(手机号数组或座机任一命中)
|
||||
func contactPhoneMatched(row models.ErpCompanyContact, phone string) bool {
|
||||
if strings.TrimSpace(row.Phone) == phone {
|
||||
return true
|
||||
@@ -345,10 +311,6 @@ func contactPhoneMatched(row models.ErpCompanyContact, phone string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// crmEnsureCompanyContact 确保企业通讯录(联系人)中已有该对接人:
|
||||
// - 同名或同电话已存在时不再重复建档,仅在原联系人缺电话时补全;
|
||||
// - 不存在时按「姓名 + 电话」建档,其余资料留空,后续可在联系人管理中补全;
|
||||
// - 该企业还没有任何联系人时,默认把首个联系人设为主联系人。
|
||||
func crmEnsureCompanyContact(tenantID, companyType string, companyID uint64, name, phone string) {
|
||||
if models.Orm == nil || companyID == 0 {
|
||||
return
|
||||
@@ -374,7 +336,6 @@ func crmEnsureCompanyContact(tenantID, companyType string, companyID uint64, nam
|
||||
if !sameName && !samePhone {
|
||||
continue
|
||||
}
|
||||
// 已存在:仅在原记录没有电话时补全,不覆盖其他已填资料
|
||||
if phone != "" && strings.TrimSpace(row.Mobiles) == "" && strings.TrimSpace(row.Phone) == "" {
|
||||
up := map[string]interface{}{"update_time": time.Now()}
|
||||
if isMobileNumber(phone) {
|
||||
@@ -412,7 +373,6 @@ func crmEnsureCompanyContact(tenantID, companyType string, companyID uint64, nam
|
||||
_, _ = models.Orm.Insert(&contact)
|
||||
}
|
||||
|
||||
// List GET /backend/crm/contact/list?related_type=1&related_id=7&keyword=&is_primary=
|
||||
func (c *BackendCrmContactController) List() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
@@ -481,7 +441,6 @@ func (c *BackendCrmContactController) List() {
|
||||
})
|
||||
}
|
||||
|
||||
// Add POST /backend/crm/contact/add
|
||||
func (c *BackendCrmContactController) Add() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
@@ -495,7 +454,6 @@ func (c *BackendCrmContactController) Add() {
|
||||
ContactName string `json:"contact_name"`
|
||||
Gender int8 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
// 手机号可登记多个(有的人有多个号码):优先使用,缺省时回退单个 mobile
|
||||
Mobiles []string `json:"mobiles"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
@@ -531,8 +489,8 @@ func (c *BackendCrmContactController) Add() {
|
||||
CompanyID: p.RelatedID,
|
||||
Name: strings.TrimSpace(p.ContactName),
|
||||
Gender: p.Gender,
|
||||
Phone: strings.TrimSpace(p.Phone), // 座机
|
||||
Mobiles: normalizeMobiles(p.Mobiles, p.Mobile), // 手机号(支持多个,JSON数组)
|
||||
Phone: strings.TrimSpace(p.Phone),
|
||||
Mobiles: normalizeMobiles(p.Mobiles, p.Mobile),
|
||||
Email: strings.TrimSpace(p.Email),
|
||||
Wechat: strings.TrimSpace(p.Wechat),
|
||||
QQ: strings.TrimSpace(p.QQ),
|
||||
@@ -546,7 +504,6 @@ func (c *BackendCrmContactController) Add() {
|
||||
CreateTime: now,
|
||||
UpdateTime: now,
|
||||
}
|
||||
// 新增联系人默认在职
|
||||
if p.Status == 0 {
|
||||
contact.Status = 1
|
||||
} else {
|
||||
@@ -563,7 +520,6 @@ func (c *BackendCrmContactController) Add() {
|
||||
c.crmContactOk(map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// Edit POST /backend/crm/contact/edit
|
||||
func (c *BackendCrmContactController) Edit() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
@@ -578,7 +534,6 @@ func (c *BackendCrmContactController) Edit() {
|
||||
ContactName string `json:"contact_name"`
|
||||
Gender int8 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
// 手机号可登记多个(有的人有多个号码):优先使用,缺省时回退单个 mobile
|
||||
Mobiles []string `json:"mobiles"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
@@ -617,7 +572,6 @@ func (c *BackendCrmContactController) Edit() {
|
||||
return
|
||||
}
|
||||
|
||||
// 允许调整关联对象;未传则保持原值
|
||||
companyType := contact.CompanyType
|
||||
companyID := contact.CompanyID
|
||||
if p.RelatedID > 0 {
|
||||
@@ -629,8 +583,8 @@ func (c *BackendCrmContactController) Edit() {
|
||||
contact.CompanyID = companyID
|
||||
contact.Name = strings.TrimSpace(p.ContactName)
|
||||
contact.Gender = p.Gender
|
||||
contact.Phone = strings.TrimSpace(p.Phone) // 座机
|
||||
contact.Mobiles = normalizeMobiles(p.Mobiles, p.Mobile) // 手机号(支持多个,JSON数组)
|
||||
contact.Phone = strings.TrimSpace(p.Phone)
|
||||
contact.Mobiles = normalizeMobiles(p.Mobiles, p.Mobile)
|
||||
contact.Email = strings.TrimSpace(p.Email)
|
||||
contact.Wechat = strings.TrimSpace(p.Wechat)
|
||||
contact.QQ = strings.TrimSpace(p.QQ)
|
||||
@@ -653,7 +607,6 @@ func (c *BackendCrmContactController) Edit() {
|
||||
c.crmContactOk(map[string]interface{}{"id": contact.ID})
|
||||
}
|
||||
|
||||
// Delete POST /backend/crm/contact/delete 软删除
|
||||
func (c *BackendCrmContactController) Delete() {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user