123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package eta_business
- import (
- "fmt"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/eta_business"
- "hongze/hz_crm_api/services/alarm_msg"
- "hongze/hz_crm_api/utils"
- "strings"
- "time"
- )
- func CheckEtaBusinessOperateAuth(roleCode string) (ok bool, err error) {
- confKey := "eta_business_auth_role"
- conf, e := company.GetConfigDetailByCode(confKey)
- if e != nil {
- err = fmt.Errorf("获取权限配置失败, Err: %s", e.Error())
- return
- }
- if conf.ConfigValue == "" {
- err = fmt.Errorf("权限配置信息有误")
- return
- }
- authArr := strings.Split(conf.ConfigValue, ",")
- if utils.InArrayByStr(authArr, roleCode) {
- ok = true
- }
- return
- }
- func UpdateEtaBusinessAfterSigning(businessId int) (err error) {
- if businessId <= 0 {
- return
- }
- defer func() {
- if err != nil {
- tips := "签约后更新商家信息失败, Err: " + err.Error()
- utils.FileLog.Info("%s", tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- }()
- businessOb := new(eta_business.EtaBusiness)
- business, e := businessOb.GetItemById(businessId)
- if e != nil {
- err = fmt.Errorf("获取商家信息失败, Err: %s", e.Error())
- return
- }
- contracts := make([]*eta_business.EtaBusinessContract, 0)
- {
- ob := new(eta_business.EtaBusinessContract)
- cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessContractColumns.EtaBusinessId)
- pars := make([]interface{}, 0)
- pars = append(pars, businessId)
- list, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- err = fmt.Errorf("获取商家合同列表失败, Err: " + e.Error())
- return
- }
- contracts = list
- }
- if len(contracts) == 0 {
- return
- }
- strToday := time.Now().Format(utils.FormatDate)
- today, _ := time.ParseInLocation(utils.FormatDate, strToday, time.Local)
- using := false
- for _, c := range contracts {
-
- if today.Equal(c.SigningTime) || today.Equal(c.ExpiredTime) || (today.After(c.SigningTime) && today.Before(c.ExpiredTime)) {
- business.ContractId = c.EtaBusinessContractId
- business.SigningTime = c.SigningTime
- business.ExpiredTime = c.ExpiredTime
- business.ModifyTime = time.Now().Local()
-
- if c.IsFirst == 1 {
- business.SigningStatus = eta_business.EtaBusinessSigningStatusFirst
- } else {
- business.SigningStatus = eta_business.EtaBusinessSigningStatusContinue
- }
- using = true
- break
- }
- }
-
- if !using {
- business.SigningStatus = eta_business.EtaBusinessSigningStatusTerminate
- business.ModifyTime = time.Now().Local()
- cols := []string{"SigningStatus", "ModifyTime"}
- if e = business.Update(cols); e != nil {
- err = fmt.Errorf("更新商家信息失败, Err: %s", e.Error())
- return
- }
- return
- }
-
- cols := []string{"ContractId", "SigningStatus", "SigningTime", "ExpiredTime", "ModifyTime"}
- if e = business.Update(cols); e != nil {
- err = fmt.Errorf("更新商家信息失败, Err: %s", e.Error())
- }
- return
- }
|