|
|
@@ -17,6 +17,7 @@ import (
|
|
|
)
|
|
|
|
|
|
type ServiceRentComputer struct {
|
|
|
+ Log ServiceRentComputerLog
|
|
|
}
|
|
|
|
|
|
func (s *ServiceRentComputer) RentComputerList(ctx context.Context, api rentComputer.RentComputer, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
|
|
|
@@ -38,21 +39,24 @@ func (s *ServiceRentComputer) RentComputerList(ctx context.Context, api rentComp
|
|
|
if api.SetMealId != 0 {
|
|
|
db = db.Where("rent_computer.set_meal_id = ?", api.SetMealId)
|
|
|
}
|
|
|
- if api.DirectorName != "ALL" {
|
|
|
- if api.DirectorName == "" {
|
|
|
- db = db.Where("rent_computer.director_name IS NULL or rent_computer.director_name = ''")
|
|
|
- } else {
|
|
|
+ if api.DirectorName != "" {
|
|
|
+ if api.DirectorName != "ALL" {
|
|
|
db = db.Where("rent_computer.director_name = ?", api.DirectorName)
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
//global.GVA_LOG.Info(strconv.Itoa(int(api.IsOffShelf)))
|
|
|
- //global.GVA_LOG.Info(strconv.Itoa(int(api.IsExpire)))
|
|
|
+ global.GVA_LOG.Info(strconv.Itoa(int(api.IsExpire)))
|
|
|
if api.IsOffShelf != -1 {
|
|
|
db = db.Where("rent_computer.is_off_shelf = ?", api.IsOffShelf)
|
|
|
}
|
|
|
if api.IsExpire != -1 {
|
|
|
- db = db.Where("rent_computer.is_expire = ?", api.IsExpire)
|
|
|
+ if api.IsExpire == 3 {
|
|
|
+ day7 := time.Now().AddDate(0, 0, 7).Format("2006-01-02 15:04:05")
|
|
|
+ db = db.Where("rent_computer.rent_end <= ?", day7)
|
|
|
+ } else {
|
|
|
+ db = db.Where("rent_computer.is_expire = ?", api.IsExpire)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
var total int64
|
|
|
@@ -139,15 +143,18 @@ func (s *ServiceRentComputer) GetRentComputerNum(ctx context.Context, api rentCo
|
|
|
if api.SetMealId != 0 {
|
|
|
db = db.Where("rent_computer.set_meal_id = ?", api.SetMealId)
|
|
|
}
|
|
|
- if api.DirectorName != "ALL" {
|
|
|
- if api.DirectorName == "" {
|
|
|
- db = db.Where("rent_computer.director_name IS NULL or rent_computer.director_name = ''")
|
|
|
- } else {
|
|
|
+ if api.DirectorName != "" {
|
|
|
+ if api.DirectorName != "ALL" {
|
|
|
db = db.Where("rent_computer.director_name = ?", api.DirectorName)
|
|
|
}
|
|
|
}
|
|
|
if api.IsExpire != -1 {
|
|
|
- db = db.Where("rent_computer.is_expire = ?", api.IsExpire)
|
|
|
+ if api.IsExpire == 3 {
|
|
|
+ day7 := time.Now().AddDate(0, 0, 7).Format("2006-01-02 15:04:05")
|
|
|
+ db = db.Where("rent_computer.rent_end <= ?", day7)
|
|
|
+ } else {
|
|
|
+ db = db.Where("rent_computer.is_expire = ?", api.IsExpire)
|
|
|
+ }
|
|
|
}
|
|
|
if api.IsOffShelf != -1 {
|
|
|
db = db.Where("rent_computer.is_off_shelf = ?", api.IsOffShelf)
|
|
|
@@ -258,26 +265,115 @@ func (s *ServiceRentComputer) RenewRentComputer(api request.RenewRentComputerReq
|
|
|
//global.GVA_LOG.Info(info.PcNum)
|
|
|
remark := time.Now().Format("2006-01-02 15:04:05") + ",租机编号" + api.PcNum + "续费" + strconv.Itoa(api.Day) + "天,续费至" + api.RentRenew + ";\n"
|
|
|
global.GVA_LOG.Info(remark)
|
|
|
- api.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ //global.GVA_LOG.Info(strconv.Itoa(api.IsExpire))
|
|
|
+ var updateInfo rentComputer.RentComputer
|
|
|
+ updateInfo.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
nowUnix := time.Now().Unix()
|
|
|
rentRenew, _ := time.ParseInLocation("2006-01-02 15:04:05", api.RentRenew, time.Local)
|
|
|
if rentRenew.Unix() < nowUnix {
|
|
|
- api.IsExpire = 1
|
|
|
+ updateInfo.IsExpire = 1
|
|
|
} else if rentRenew.Unix()-nowUnix <= 24*60*60 {
|
|
|
- api.IsExpire = 2
|
|
|
+ updateInfo.IsExpire = 2
|
|
|
+ } else if rentRenew.Unix()-nowUnix <= 24*60*60*7 {
|
|
|
+ updateInfo.IsExpire = 3
|
|
|
} else {
|
|
|
- api.IsExpire = 0
|
|
|
+ updateInfo.IsExpire = 0
|
|
|
}
|
|
|
- //global.GVA_LOG.Info(strconv.Itoa(api.IsExpire))
|
|
|
- api.Remark = info.Remark + remark
|
|
|
- var updateInfo rentComputer.RentComputer
|
|
|
- updateInfo.UpdateTime = api.UpdateTime
|
|
|
+ //updateInfo.Remark = info.Remark + remark
|
|
|
+ updateInfo.Remark = remark
|
|
|
updateInfo.Id = api.PcId
|
|
|
- updateInfo.IsExpire = api.IsExpire
|
|
|
updateInfo.RentDuration = info.RentDuration + api.Day
|
|
|
updateInfo.RentEnd = api.RentRenew
|
|
|
- updateInfo.Remark = api.Remark
|
|
|
- err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", api.PcId).Updates(updateInfo).Error
|
|
|
+ updateInfo.CreateTime = info.CreateTime
|
|
|
+ updateInfo.PcNum = info.PcNum
|
|
|
+ updateInfo.PcName = info.PcName
|
|
|
+ updateInfo.ShopId = info.ShopId
|
|
|
+ updateInfo.RentStart = info.RentStart
|
|
|
+ updateInfo.TodeskId = info.TodeskId
|
|
|
+ updateInfo.TodeskPassword = info.TodeskPassword
|
|
|
+ updateInfo.SunflowerId = info.SunflowerId
|
|
|
+ updateInfo.SunflowerPassword = info.SunflowerPassword
|
|
|
+ updateInfo.RentPriceUsed = info.RentPriceUsed
|
|
|
+ updateInfo.SetMealId = info.SetMealId
|
|
|
+ updateInfo.IsOffShelf = info.IsOffShelf
|
|
|
+ updateInfo.DirectorName = info.DirectorName
|
|
|
+
|
|
|
+ err = global.GVA_DB.Save(updateInfo).Error
|
|
|
+ if err == nil {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = updateInfo.UpdateTime
|
|
|
+ log.CreateTime = updateInfo.UpdateTime
|
|
|
+ log.PcNum = updateInfo.PcNum
|
|
|
+ log.ShopId = updateInfo.ShopId
|
|
|
+ log.SetMealId = updateInfo.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", api.PcId).Updates(updateInfo).Error
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+// RenewRentComputerByBatch 租机批量续费(仅限于续费天数一致的)
|
|
|
+func (s *ServiceRentComputer) RenewRentComputerByBatch(api request.RenewRentComputersRequest) (err error) {
|
|
|
+ for _, one := range api.RentMessage {
|
|
|
+ var info rentComputer.RentComputer
|
|
|
+ if errors.Is(global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", one.PcId).First(&info).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ remark := time.Now().Format("2006-01-02 15:04:05") + ",租机编号" + one.PcNum + "续费" + strconv.Itoa(one.Day) + "天,续费至" + one.RentRenew + ";\n"
|
|
|
+ var updateInfo rentComputer.RentComputer
|
|
|
+ nowUnix := time.Now().Unix()
|
|
|
+ rentRenew, _ := time.ParseInLocation("2006-01-02 15:04:05", one.RentRenew, time.Local)
|
|
|
+ if rentRenew.Unix() < nowUnix {
|
|
|
+ updateInfo.IsExpire = 1
|
|
|
+ } else if rentRenew.Unix()-nowUnix <= 24*60*60 {
|
|
|
+ updateInfo.IsExpire = 2
|
|
|
+ } else if rentRenew.Unix()-nowUnix <= 24*60*60*7 {
|
|
|
+ updateInfo.IsExpire = 3
|
|
|
+ } else {
|
|
|
+ updateInfo.IsExpire = 0
|
|
|
+ }
|
|
|
+ updateInfo.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ updateInfo.Remark = remark
|
|
|
+ updateInfo.RentDuration = info.RentDuration + one.Day
|
|
|
+ updateInfo.RentEnd = one.RentRenew
|
|
|
+ updateInfo.Id = info.Id
|
|
|
+ updateInfo.CreateTime = info.CreateTime
|
|
|
+ updateInfo.PcNum = info.PcNum
|
|
|
+ updateInfo.PcName = info.PcName
|
|
|
+ updateInfo.ShopId = info.ShopId
|
|
|
+ updateInfo.RentStart = info.RentStart
|
|
|
+ updateInfo.TodeskId = info.TodeskId
|
|
|
+ updateInfo.TodeskPassword = info.TodeskPassword
|
|
|
+ updateInfo.SunflowerId = info.SunflowerId
|
|
|
+ updateInfo.SunflowerPassword = info.SunflowerPassword
|
|
|
+ updateInfo.RentPriceUsed = info.RentPriceUsed
|
|
|
+ updateInfo.SetMealId = info.SetMealId
|
|
|
+ updateInfo.IsOffShelf = info.IsOffShelf
|
|
|
+ updateInfo.DirectorName = info.DirectorName
|
|
|
+
|
|
|
+ err = global.GVA_DB.Save(updateInfo).Error
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ } else {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = updateInfo.UpdateTime
|
|
|
+ log.CreateTime = updateInfo.UpdateTime
|
|
|
+ log.PcNum = updateInfo.PcNum
|
|
|
+ log.ShopId = updateInfo.ShopId
|
|
|
+ log.SetMealId = updateInfo.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -296,7 +392,7 @@ func (s *ServiceRentComputer) RentingOutRentComputer(api request.RentingOutRentC
|
|
|
return "待退租的租机已到期", err, ""
|
|
|
}
|
|
|
surplusDay := math.Ceil(float64((rentEnd1.Unix() - rentEnd2.Unix()) / oneDayUnix))
|
|
|
- remark := now + ",租机编号" + info.PcNum + "退租,剩余" + strconv.Itoa(int(surplusDay)) + "天,"
|
|
|
+ remark := now + ",租机编号" + info.PcNum + "于" + api.RentEnd + "执行退租,剩余" + strconv.Itoa(int(surplusDay)) + "天,"
|
|
|
|
|
|
for i, v := range api.AddList {
|
|
|
//global.GVA_LOG.Info(v.PcNum)
|
|
|
@@ -318,20 +414,47 @@ func (s *ServiceRentComputer) RentingOutRentComputer(api request.RentingOutRentC
|
|
|
err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", infoTemp.Id).Updates(infoTemp).Error
|
|
|
if err != nil {
|
|
|
return "增加时间的租机信息修改失败!", err, ""
|
|
|
+ } else {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = infoTemp.UpdateTime
|
|
|
+ log.CreateTime = infoTemp.UpdateTime
|
|
|
+ log.PcNum = infoTemp.PcNum
|
|
|
+ log.ShopId = infoTemp.ShopId
|
|
|
+ log.SetMealId = infoTemp.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return "", err, remark
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//修改退租机器信息
|
|
|
info.RentEnd = api.RentEnd
|
|
|
info.RentDuration = info.RentDuration - int(surplusDay)
|
|
|
info.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
- info.Remark = info.Remark + remark
|
|
|
+ //info.Remark = info.Remark + remark
|
|
|
+ info.Remark = remark
|
|
|
info.IsOffShelf = 1
|
|
|
+ logPcNum := info.PcNum
|
|
|
info.PcNum = "offShelf_" + info.PcNum + "_" + strconv.Itoa(int(time.Now().Unix()))
|
|
|
err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", info.Id).Updates(info).Error
|
|
|
if err != nil {
|
|
|
return "退租机器信息修改失败!", err, ""
|
|
|
+ } else {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = info.UpdateTime
|
|
|
+ log.CreateTime = info.UpdateTime
|
|
|
+ log.PcNum = logPcNum
|
|
|
+ log.ShopId = info.ShopId
|
|
|
+ log.SetMealId = info.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return "", err, remark
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return "", err, remark
|
|
|
}
|
|
|
|
|
|
@@ -347,9 +470,25 @@ func (s *ServiceRentComputer) OffShelfRentComputer(api request.ComputerRequest)
|
|
|
var updateInfo rentComputer.RentComputer
|
|
|
updateInfo.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
updateInfo.IsOffShelf = 1
|
|
|
+ logPcNum := api.PcNum
|
|
|
updateInfo.PcNum = "offShelf_" + api.PcNum + "_" + strconv.Itoa(int(time.Now().Unix()))
|
|
|
- updateInfo.Remark = info.Remark + remark
|
|
|
+ //updateInfo.Remark = info.Remark + remark
|
|
|
+ updateInfo.Remark = remark
|
|
|
err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", api.Id).Updates(updateInfo).Error
|
|
|
+ if err == nil {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = updateInfo.UpdateTime
|
|
|
+ log.CreateTime = updateInfo.UpdateTime
|
|
|
+ log.PcNum = logPcNum
|
|
|
+ log.ShopId = updateInfo.ShopId
|
|
|
+ log.SetMealId = updateInfo.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -389,10 +528,11 @@ func (s *ServiceRentComputer) ReplaceNumRentComputer(api request.ReplaceNumRentC
|
|
|
infoNew.IsOffShelf = 0
|
|
|
infoNew.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
infoNew.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ infoNew.DirectorName = infoOld.DirectorName
|
|
|
// 修改旧编号信息
|
|
|
- if infoOld.Remark != "" {
|
|
|
- remark = infoOld.Remark + ";" + remark
|
|
|
- }
|
|
|
+ //if infoOld.Remark != "" {
|
|
|
+ // remark = infoOld.Remark + ";" + remark
|
|
|
+ //}
|
|
|
rentStartOld, _ := time.ParseInLocation("2006-01-02 15:04:05", infoOld.RentStart, time.Local)
|
|
|
rentDurationOld := math.Ceil(float64((rentEndOld.Unix() - rentStartOld.Unix()) / oneDayUnix))
|
|
|
infoOld.RentDuration = int(rentDurationOld)
|
|
|
@@ -400,15 +540,42 @@ func (s *ServiceRentComputer) ReplaceNumRentComputer(api request.ReplaceNumRentC
|
|
|
infoOld.Remark = remark
|
|
|
infoOld.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
infoOld.IsOffShelf = 1
|
|
|
+ logPcNum := infoOld.PcNum
|
|
|
infoOld.PcNum = "offShelf_" + infoOld.PcNum + "_" + strconv.Itoa(int(time.Now().Unix()))
|
|
|
err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", infoOld.Id).Updates(infoOld).Error
|
|
|
if err != nil {
|
|
|
return "旧编号租机修改失败!", err, ""
|
|
|
+ } else {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = infoOld.UpdateTime
|
|
|
+ log.CreateTime = infoOld.UpdateTime
|
|
|
+ log.PcNum = logPcNum
|
|
|
+ log.ShopId = infoOld.ShopId
|
|
|
+ log.SetMealId = infoOld.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return "旧编号租机日志创建失败!", err, ""
|
|
|
+ }
|
|
|
}
|
|
|
// 插入新编号至数据库
|
|
|
err = global.GVA_DB.Create(&infoNew).Error
|
|
|
if err != nil {
|
|
|
return "新编号租机创建失败!", err, ""
|
|
|
+ } else {
|
|
|
+ //添加log
|
|
|
+ var log rentComputer.RentComputerLog
|
|
|
+ log.UpdateTime = infoNew.UpdateTime
|
|
|
+ log.CreateTime = infoNew.UpdateTime
|
|
|
+ log.PcNum = infoNew.PcNum
|
|
|
+ log.ShopId = infoNew.ShopId
|
|
|
+ log.SetMealId = infoNew.SetMealId
|
|
|
+ log.Log = remark
|
|
|
+ err = s.Log.AddRentComputerLog(log)
|
|
|
+ if err != nil {
|
|
|
+ return "新编号租机日志创建失败!", err, ""
|
|
|
+ }
|
|
|
}
|
|
|
return "", err, okMessage
|
|
|
}
|
|
|
@@ -570,6 +737,7 @@ func (s *ServiceRentComputer) CheckIsExpire() {
|
|
|
return
|
|
|
}
|
|
|
const overtime = 24 * 60 * 60
|
|
|
+ const overtime7 = 24 * 60 * 60 * 7
|
|
|
nowUnix := time.Now().Unix()
|
|
|
|
|
|
//global.GVA_LOG.Info(strconv.FormatInt(nowUnix, 10))
|
|
|
@@ -578,13 +746,17 @@ func (s *ServiceRentComputer) CheckIsExpire() {
|
|
|
for _, c := range computers {
|
|
|
endUnix, _ := time.ParseInLocation("2006-01-02 15:04:05", c.RentEnd, time.Local)
|
|
|
//global.GVA_LOG.Info(strconv.FormatInt(endUnix.Unix(), 10))
|
|
|
+
|
|
|
if endUnix.Unix() < nowUnix {
|
|
|
computer.IsExpire = 1
|
|
|
} else if endUnix.Unix()-nowUnix <= overtime {
|
|
|
computer.IsExpire = 2
|
|
|
+ } else if endUnix.Unix()-nowUnix <= overtime7 {
|
|
|
+ computer.IsExpire = 3
|
|
|
} else {
|
|
|
computer.IsExpire = 0
|
|
|
}
|
|
|
+
|
|
|
if c.IsExpire == computer.IsExpire {
|
|
|
continue
|
|
|
}
|
|
|
@@ -606,7 +778,12 @@ func (s *ServiceRentComputer) CheckIsExpire() {
|
|
|
computer.SetMealId = c.SetMealId
|
|
|
computer.IsOffShelf = c.IsOffShelf
|
|
|
computer.DirectorName = c.DirectorName
|
|
|
-
|
|
|
+ //if c.PcNum == "S11" {
|
|
|
+ // global.GVA_LOG.Info(strconv.FormatInt(nowUnix, 10))
|
|
|
+ // global.GVA_LOG.Info(strconv.FormatInt(endUnix.Unix(), 10))
|
|
|
+ // global.GVA_LOG.Info(strconv.FormatInt(overtime7, 10))
|
|
|
+ // global.GVA_LOG.Info(strconv.Itoa(computer.IsExpire))
|
|
|
+ //}
|
|
|
err = global.GVA_DB.Save(computer).Error
|
|
|
}
|
|
|
global.GVA_LOG.Info("检查是否有电脑到期执行成功:" + time.Now().Format("2006-01-02 15:04:05"))
|
|
|
@@ -620,7 +797,7 @@ func (s *ServiceRentComputer) CreateRentComputerLedger() {
|
|
|
db := global.GVA_DB.Model(&rentComputer.RentComputer{})
|
|
|
var computers []*rentComputer.RentComputerSetMeal
|
|
|
db = db.Select("rent_computer.pc_num, rent_computer.pc_name,rent_computer.shop_id, rent_computer.rent_start, rent_computer.rent_duration, rent_computer.rent_end, rent_computer.is_expire, " +
|
|
|
- "r.rent_price,r.rent_price_day,rent_computer.set_meal_id")
|
|
|
+ "r.rent_price,r.rent_price_day,rent_computer.set_meal_id,rent_computer.remark")
|
|
|
db = db.Joins("left join rent_set_meal r on r.id = rent_computer.set_meal_id")
|
|
|
db = db.Where("rent_computer.is_expire != 1")
|
|
|
err := db.Order("rent_computer.id").Find(&computers).Error
|