|
|
@@ -22,7 +22,7 @@ type ServiceRentComputer struct {
|
|
|
func (s *ServiceRentComputer) RentComputerList(ctx context.Context, api rentComputer.RentComputer, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
|
|
|
|
|
|
db := global.GVA_DB.Model(&rentComputer.RentComputer{})
|
|
|
- db = db.Select("rent_computer.id,rent_computer.update_time,rent_computer.create_time,rent_computer.pc_num,rent_computer.set_meal_id," +
|
|
|
+ db = db.Select("rent_computer.id,rent_computer.update_time,rent_computer.create_time,rent_computer.pc_num,rent_computer.set_meal_id,rent_computer.director_name," +
|
|
|
"rent_computer.pc_name,rent_computer.shop_id,rent_computer.rent_start,rent_computer.rent_duration,rent_computer.is_off_shelf,rent_computer.rent_end," +
|
|
|
"rent_computer.remark,rent_computer.todesk_id,rent_computer.todesk_password,rent_computer.sunflower_id,rent_computer.sunflower_password,rent_computer.rent_price_used,rent_computer.is_expire," +
|
|
|
"s.name as shop_name, r.name as set_meal_name,r.rent_price,r.price_type,r.rent_price_day")
|
|
|
@@ -38,11 +38,19 @@ 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")
|
|
|
+ } else {
|
|
|
+ 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)))
|
|
|
- if api.IsOffShelf != -1 {
|
|
|
- db = db.Where("rent_computer.is_off_shelf = ?", api.IsOffShelf)
|
|
|
- }
|
|
|
+ //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)
|
|
|
}
|
|
|
@@ -110,17 +118,37 @@ func (s *ServiceRentComputer) RentComputerList(ctx context.Context, api rentComp
|
|
|
statisticscomputer.IsOffShelf = statisticsLog.IsOffShelf
|
|
|
statisticscomputer.ShopName = statisticsLog.ShopName
|
|
|
statisticscomputer.SetMealName = statisticsLog.SetMealName
|
|
|
+ statisticscomputer.DirectorName = statisticsLog.DirectorName
|
|
|
statisticsLogsComputer = append(statisticsLogsComputer, statisticscomputer)
|
|
|
}
|
|
|
return statisticsLogsComputer, total, err
|
|
|
}
|
|
|
|
|
|
-func (s *ServiceRentComputer) GetRentComputerNum() int64 {
|
|
|
+func (s *ServiceRentComputer) GetRentComputerNum(ctx context.Context, api rentComputer.RentComputer) int64 {
|
|
|
var total int64
|
|
|
|
|
|
db := global.GVA_DB.Model(&rentComputer.RentComputer{})
|
|
|
db = db.Distinct("id")
|
|
|
- db = db.Where("is_off_shelf = 0 and is_expire != 1")
|
|
|
+ //db = db.Where("is_off_shelf = 0 and is_expire != 1")
|
|
|
+ if api.PcNum != "" {
|
|
|
+ db = db.Where("rent_computer.pc_num = ?", api.PcNum)
|
|
|
+ }
|
|
|
+ if api.ShopId != 0 {
|
|
|
+ db = db.Where("rent_computer.shop_id = ?", api.ShopId)
|
|
|
+ }
|
|
|
+ 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")
|
|
|
+ } else {
|
|
|
+ db = db.Where("rent_computer.director_name = ?", api.DirectorName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if api.IsExpire != -1 {
|
|
|
+ db = db.Where("rent_computer.is_expire = ?", api.IsExpire)
|
|
|
+ }
|
|
|
_ = db.Count(&total).Error
|
|
|
return total
|
|
|
}
|
|
|
@@ -146,6 +174,7 @@ func (s *ServiceRentComputer) AddRentComputer(requestCoding request.ComputerRequ
|
|
|
computer.IsExpire = requestCoding.IsExpire
|
|
|
computer.SetMealId = requestCoding.SetMealId
|
|
|
computer.IsOffShelf = requestCoding.IsOffShelf
|
|
|
+ computer.DirectorName = requestCoding.DirectorName
|
|
|
computer.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
computer.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
//key := codeListCacheKey
|
|
|
@@ -156,12 +185,13 @@ func (s *ServiceRentComputer) AddRentComputer(requestCoding request.ComputerRequ
|
|
|
func (s *ServiceRentComputer) GetRentComputerById(id int) (computerShop response.ComputerStatisticsReply2, err error) {
|
|
|
db := global.GVA_DB.Model(&rentComputer.RentComputer{})
|
|
|
var api response.ComputerStatisticsReply2
|
|
|
- db = db.Select("rent_computer.id,rent_computer.update_time,rent_computer.create_time,rent_computer.pc_num,rent_computer.set_meal_id," +
|
|
|
+ db = db.Select("rent_computer.id,rent_computer.update_time,rent_computer.create_time,rent_computer.pc_num,rent_computer.set_meal_id,rent_computer.director_name," +
|
|
|
"rent_computer.pc_name,rent_computer.shop_id,rent_computer.rent_start,rent_computer.rent_duration,rent_computer.is_off_shelf,rent_computer.rent_end," +
|
|
|
"rent_computer.remark,rent_computer.todesk_id,rent_computer.todesk_password,rent_computer.sunflower_id,rent_computer.sunflower_password,rent_computer.rent_price_used,rent_computer.is_expire," +
|
|
|
"s.name as shop_name, r.name as set_meal_name,r.rent_price,r.price_type,r.rent_price_day")
|
|
|
db = db.Joins("left join rent_computer_shop s on s.id = rent_computer.shop_id")
|
|
|
db = db.Joins("left join rent_set_meal r on r.id = rent_computer.set_meal_id")
|
|
|
+ //db = db.Joins("left join responsible_person p on p.name = rent_computer.director_name")
|
|
|
err = db.Where("rent_computer.id = ?", id).Order(id).Limit(1).Find(&api).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
@@ -183,12 +213,13 @@ func (s *ServiceRentComputer) GetRentComputerById(id int) (computerShop response
|
|
|
computerShop.SetMealId = api.SetMealId
|
|
|
computerShop.PriceType = api.PriceType
|
|
|
computerShop.IsOffShelf = api.IsOffShelf
|
|
|
- global.GVA_LOG.Info(strconv.Itoa(api.IsOffShelf))
|
|
|
- global.GVA_LOG.Info(strconv.Itoa(computerShop.IsOffShelf))
|
|
|
+ //global.GVA_LOG.Info(strconv.Itoa(api.IsOffShelf))
|
|
|
+ //global.GVA_LOG.Info(strconv.Itoa(computerShop.IsOffShelf))
|
|
|
computerShop.ShopName = api.ShopName
|
|
|
computerShop.SetMealName = api.SetMealName
|
|
|
computerShop.Remark = api.Remark
|
|
|
computerShop.ShopId = api.ShopId
|
|
|
+ computerShop.DirectorName = api.DirectorName
|
|
|
computerShop.UpdateTime = api.UpdateTime
|
|
|
computerShop.CreateTime = api.CreateTime
|
|
|
return
|
|
|
@@ -215,6 +246,148 @@ func (s *ServiceRentComputer) DeleteRentComputerById(api rentComputer.RentComput
|
|
|
return global.GVA_DB.Delete(&entity).Error
|
|
|
}
|
|
|
|
|
|
+// RenewRentComputer 租机续费
|
|
|
+func (s *ServiceRentComputer) RenewRentComputer(api request.RenewRentComputerRequest) (err error) {
|
|
|
+ var info rentComputer.RentComputer
|
|
|
+ if errors.Is(global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", api.PcId).First(&info).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ //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")
|
|
|
+ nowUnix := time.Now().Unix()
|
|
|
+ rentRenew, _ := time.ParseInLocation("2006-01-02 15:04:05", api.RentRenew, time.Local)
|
|
|
+ if rentRenew.Unix() < nowUnix {
|
|
|
+ api.IsExpire = 1
|
|
|
+ } else if rentRenew.Unix()-nowUnix <= 24*60*60 {
|
|
|
+ api.IsExpire = 2
|
|
|
+ } else {
|
|
|
+ api.IsExpire = 0
|
|
|
+ }
|
|
|
+ //global.GVA_LOG.Info(strconv.Itoa(api.IsExpire))
|
|
|
+ api.Remark = info.Remark + remark
|
|
|
+ var updateInfo rentComputer.RentComputer
|
|
|
+ updateInfo.UpdateTime = api.UpdateTime
|
|
|
+ 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
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+// RentingOutRentComputer 租机退租
|
|
|
+func (s *ServiceRentComputer) RentingOutRentComputer(api request.RentingOutRentComputerRequest) (errMessage string, err error, okMessage string) {
|
|
|
+ var info rentComputer.RentComputer
|
|
|
+ if errors.Is(global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ? ", api.PcId).First(&info).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return "待退租的租机编号不存在", err, ""
|
|
|
+ }
|
|
|
+ nowUnix := time.Now().Unix()
|
|
|
+ now := time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ const oneDayUnix = 24 * 60 * 60
|
|
|
+ rentEnd1, _ := time.ParseInLocation("2006-01-02 15:04:05", info.RentEnd, time.Local)
|
|
|
+ rentEnd2, _ := time.ParseInLocation("2006-01-02 15:04:05", api.RentEnd, time.Local)
|
|
|
+ if rentEnd1.Unix() < nowUnix {
|
|
|
+ return "待退租的租机已到期", err, ""
|
|
|
+ }
|
|
|
+ surplusDay := math.Ceil(float64((rentEnd1.Unix() - rentEnd2.Unix()) / oneDayUnix))
|
|
|
+ remark := now + ",租机编号" + info.PcNum + "退租,剩余" + strconv.Itoa(int(surplusDay)) + "天,"
|
|
|
+
|
|
|
+ for i, v := range api.AddList {
|
|
|
+ //global.GVA_LOG.Info(v.PcNum)
|
|
|
+ //global.GVA_LOG.Info(strconv.Itoa(v.AddDay))
|
|
|
+ var infoTemp rentComputer.RentComputer
|
|
|
+ if errors.Is(global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("pc_num = ? and shop_id = ?", v.PcNum, info.ShopId).First(&infoTemp).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return "增加时间的租机编号不存在", err, ""
|
|
|
+ }
|
|
|
+ if i < len(api.AddList) {
|
|
|
+ remark += "编号" + v.PcNum + "加" + strconv.Itoa(v.AddDay) + "天,"
|
|
|
+ } else {
|
|
|
+ remark += "编号" + v.PcNum + "加" + strconv.Itoa(v.AddDay) + "天;\n"
|
|
|
+ }
|
|
|
+
|
|
|
+ infoTemp.UpdateTime = now
|
|
|
+ infoTemp.RentDuration = infoTemp.RentDuration + v.AddDay
|
|
|
+ rentEndTemp, _ := time.ParseInLocation("2006-01-02 15:04:05", infoTemp.RentEnd, time.Local)
|
|
|
+ infoTemp.RentEnd = rentEndTemp.AddDate(0, 0, v.AddDay).Format("2006-01-02 15:04:05")
|
|
|
+ err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", infoTemp.Id).Updates(infoTemp).Error
|
|
|
+ if err != nil {
|
|
|
+ return "增加时间的租机信息修改失败!", err, ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改退租机器信息
|
|
|
+ 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
|
|
|
+ err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", info.Id).Updates(info).Error
|
|
|
+ if err != nil {
|
|
|
+ return "退租机器信息修改失败!", err, ""
|
|
|
+ }
|
|
|
+
|
|
|
+ return "", err, remark
|
|
|
+}
|
|
|
+
|
|
|
+// ReplaceNumRentComputer 租机换编号
|
|
|
+func (s *ServiceRentComputer) ReplaceNumRentComputer(api request.ReplaceNumRentComputerRequest) (errMessage string, err error, okMessage string) {
|
|
|
+ var infoOld rentComputer.RentComputer
|
|
|
+ if errors.Is(global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("pc_num = ? and shop_id = ?", api.PcNumOld, api.ShopId).First(&infoOld).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return "待更换的租机编号不存在", err, ""
|
|
|
+ }
|
|
|
+ nowUnix := time.Now().Unix()
|
|
|
+ const oneDayUnix = 24 * 60 * 60
|
|
|
+ rentEndOld, _ := time.ParseInLocation("2006-01-02 15:04:05", infoOld.RentEnd, time.Local)
|
|
|
+ if rentEndOld.Unix() < nowUnix {
|
|
|
+ return "待更换的租机已到期", err, ""
|
|
|
+ }
|
|
|
+ var infoNew rentComputer.RentComputer
|
|
|
+ if !errors.Is(global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("pc_num = ? and shop_id = ?", api.PcNumNew, api.ShopId).First(&infoNew).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return "要更换的租机编号已存在,不允许更换", err, ""
|
|
|
+ }
|
|
|
+ remark := time.Now().Format("2006-01-02 15:04:05") + ",租机编号" + api.PcNumOld + "更换为租机编号" + api.PcNumNew + ";\n"
|
|
|
+ okMessage = remark
|
|
|
+ rentDurationNew := math.Ceil(float64((rentEndOld.Unix() - nowUnix) / oneDayUnix))
|
|
|
+ infoNew.PcNum = api.PcNumNew
|
|
|
+ infoNew.PcName = api.PcNumNew
|
|
|
+ infoNew.ShopId = api.ShopId
|
|
|
+ infoNew.RentStart = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ infoNew.RentDuration = int(rentDurationNew)
|
|
|
+ infoNew.RentEnd = infoOld.RentEnd
|
|
|
+ infoNew.Remark = remark
|
|
|
+ infoNew.TodeskId = ""
|
|
|
+ infoNew.TodeskPassword = ""
|
|
|
+ infoNew.SunflowerId = ""
|
|
|
+ infoNew.SunflowerPassword = ""
|
|
|
+ infoNew.RentPriceUsed = 0
|
|
|
+ infoNew.IsExpire = 0
|
|
|
+ infoNew.SetMealId = infoOld.SetMealId
|
|
|
+ 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")
|
|
|
+ // 修改旧编号信息
|
|
|
+ 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)
|
|
|
+ infoOld.RentEnd = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ infoOld.Remark = remark
|
|
|
+ infoOld.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ err = global.GVA_DB.Model(&rentComputer.RentComputer{}).Where("id = ?", infoOld.Id).Updates(infoOld).Error
|
|
|
+ if err != nil {
|
|
|
+ return "旧编号租机修改失败!", err, ""
|
|
|
+ }
|
|
|
+ // 插入新编号至数据库
|
|
|
+ err = global.GVA_DB.Create(&infoNew).Error
|
|
|
+ if err != nil {
|
|
|
+ return "新编号租机创建失败!", err, ""
|
|
|
+ }
|
|
|
+ return "", err, okMessage
|
|
|
+}
|
|
|
+
|
|
|
func (exa *ServiceRentComputer) ParseExcel2InfoList(filePath string) (err error) {
|
|
|
skipHeader := true
|
|
|
fixedHeader := []string{"租机编码", "供应商", "所属套餐", "套餐类型", "起租日", "到期日", "todesk号", "todesk密码", "向日葵号", "向日葵密码"}
|
|
|
@@ -283,9 +456,9 @@ func (exa *ServiceRentComputer) ParseExcel2InfoList(filePath string) (err error)
|
|
|
if flagShopId == false || flagSetMealName == false {
|
|
|
return errors.New("供应商错误")
|
|
|
}
|
|
|
-
|
|
|
- rentStart, _ := time.ParseInLocation("2006-01-02 15:04:05", row[4]+" 00:00:00", time.Local)
|
|
|
- rentEnd, _ := time.ParseInLocation("2006-01-02 15:04:05", row[5]+" 00:00:00", time.Local)
|
|
|
+ // 时间统一设置为日期+12:00:00
|
|
|
+ rentStart, _ := time.ParseInLocation("2006-01-02 15:04:05", row[4]+" 12:00:00", time.Local)
|
|
|
+ rentEnd, _ := time.ParseInLocation("2006-01-02 15:04:05", row[5]+" 12:00:00", time.Local)
|
|
|
//global.GVA_LOG.Info(strconv.FormatInt(rentStart.Unix(), 10))
|
|
|
//global.GVA_LOG.Info(strconv.FormatInt(rentEnd.Unix(), 10))
|
|
|
c.RentStart = row[4] + " 00:00:00"
|
|
|
@@ -356,12 +529,12 @@ func (exa *ServiceRentComputer) compareStrSlice(a, b []string) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-// CheckIsExpire 定时检查是否有电脑到期,修改租机状态/*
|
|
|
+// CheckIsExpire 定时检查是否有电脑到期,修改租机状态
|
|
|
func (s *ServiceRentComputer) CheckIsExpire() {
|
|
|
global.GVA_LOG.Info("检查是否有电脑到期开始执行:" + time.Now().Format("2006-01-02 15:04:05"))
|
|
|
db := global.GVA_DB.Model(&rentComputer.RentComputer{})
|
|
|
//SELECT pc_num,rent_start,rent_end,is_expire FROM shuyou_rent_computer
|
|
|
- db = db.Where("is_off_shelf = 0")
|
|
|
+ //db = db.Where("is_off_shelf = 0")
|
|
|
var computers []*rentComputer.RentComputer
|
|
|
err := db.Order("id").Find(&computers).Error
|
|
|
if err != nil {
|
|
|
@@ -411,6 +584,84 @@ func (s *ServiceRentComputer) CheckIsExpire() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// CreateRentComputerLedger 定时生成今日租机台账表(财务)
|
|
|
+func (s *ServiceRentComputer) CreateRentComputerLedger() {
|
|
|
+ global.GVA_LOG.Info("定时生成今日租机台账表开始执行:" + time.Now().Format("2006-01-02 15:04:05"))
|
|
|
+ //查询当前所有在租电脑
|
|
|
+ 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")
|
|
|
+ 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
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("定时生成今日租机台账表执行失败:"+time.Now().Format("2006-01-02 15:04:05"), zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //查询昨日租机台账表中的rent_price_used_then参数
|
|
|
+ var computersYest []*rentComputer.RentComputerLedger
|
|
|
+ dbYest := global.GVA_DB.Model(&rentComputer.RentComputerLedger{})
|
|
|
+ dbYest = dbYest.Select("rent_price_used_then").Order("id")
|
|
|
+ err = dbYest.Find(&computersYest).Error
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("定时生成今日租机台账表执行失败,查询昨日数据失败:"+time.Now().Format("2006-01-02 15:04:05"), zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nowTime := time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ nowDate := time.Now().Format("2006-01-02")
|
|
|
+ var insertInfos []rentComputer.RentComputerLedger
|
|
|
+ for _, computer := range computers {
|
|
|
+ var info rentComputer.RentComputerLedger
|
|
|
+ info.UpdateTime = nowTime
|
|
|
+ info.CreateTime = nowTime
|
|
|
+ info.NewDate = nowDate
|
|
|
+ info.PcNum = computer.PcNum
|
|
|
+ info.PcName = computer.PcName
|
|
|
+ info.ShopId = computer.ShopId
|
|
|
+ info.RentStartThen = computer.RentStart
|
|
|
+ info.RentDurationThen = computer.RentDuration
|
|
|
+ info.RentEndThen = computer.RentEnd
|
|
|
+ info.RentPriceThen = computer.RentPrice
|
|
|
+ info.RentPriceDayThen = computer.RentPriceDay
|
|
|
+ info.IsExpire = computer.IsExpire
|
|
|
+ info.SetMealId = computer.SetMealId
|
|
|
+ info.Remark = computer.Remark
|
|
|
+
|
|
|
+ flag := false
|
|
|
+ for _, yest := range computersYest {
|
|
|
+ if info.PcNum == yest.PcNum {
|
|
|
+ flag = true
|
|
|
+ info.RentPriceUsedThen = yest.RentPriceUsedThen + computer.RentPriceDay
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if flag == false {
|
|
|
+ info.RentPriceUsedThen = computer.RentPriceDay
|
|
|
+ }
|
|
|
+ if !errors.Is(global.GVA_DB.Where("pc_num = ? and shop_id = ? and new_date = ?", computer.PcNum, computer.ShopId, nowDate).First(&rentComputer.RentComputerLedger{}).Error, gorm.ErrRecordNotFound) {
|
|
|
+ // 已存在,更新
|
|
|
+ err = global.GVA_DB.Model(&rentComputer.RentComputerLedger{}).Where("pc_num = ? and shop_id = ? and new_date = ?", computer.PcNum, computer.ShopId, nowDate).Updates(info).Error
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("定时生成今日租机台账表执行失败,更新数据失败:"+time.Now().Format("2006-01-02 15:04:05"), zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ insertInfos = append(insertInfos, info)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if insertInfos != nil {
|
|
|
+ err = global.GVA_DB.Create(&insertInfos).Error
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("定时生成今日租机台账表执行失败,插入数据失败:"+time.Now().Format("2006-01-02 15:04:05"), zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ global.GVA_LOG.Info("定时生成今日租机台账表执行成功:" + time.Now().Format("2006-01-02 15:04:05"))
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// SubDays 计算日期相差多少天
|
|
|
// 返回值day>0, t1晚于t2; day<0, t1早于t2
|
|
|
func SubDays(t1, t2 time.Time) (day int) {
|