Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

wangbin 3 éve
szülő
commit
f351e012ce

+ 2 - 0
api/v1/rentComputer/enter.go

@@ -8,6 +8,7 @@ type ApiGroup struct {
 	ApiRentComputerShop
 	ApiRentSetMeal
 	ApiRentComputerLedger
+	ApiRentComputerLog
 	// Code generated by log-server End; DO NOT EDIT.
 }
 
@@ -16,4 +17,5 @@ var (
 	ServiceRentComputerLedger = service.ServiceGroupApp.RentComputerServiceGroup.ServiceRentComputerLedger
 	ServiceRentComputerShop   = service.ServiceGroupApp.RentComputerServiceGroup.ServiceRentComputerShop
 	ServiceRentSetMeal        = service.ServiceGroupApp.RentComputerServiceGroup.ServiceRentSetMeal
+	ServiceRentComputerLog    = service.ServiceGroupApp.RentComputerServiceGroup.ServiceRentComputerLog
 )

+ 12 - 0
api/v1/rentComputer/rent_computer.go

@@ -152,6 +152,18 @@ func (s *ApiRentComputer) RenewRentComputer(c *gin.Context) {
 	}
 }
 
+// RenewRentComputerByBatch 租机批量续费
+func (s *ApiRentComputer) RenewRentComputerByBatch(c *gin.Context) {
+	var api request.RenewRentComputersRequest
+	_ = c.ShouldBindJSON(&api)
+	if err := ServiceRentComputer.RenewRentComputerByBatch(api); err != nil {
+		global.GVA_LOG.Error("租机批量续费失败!", zap.Error(err))
+		response.FailWithMessage("租机批量续费失败", c)
+	} else {
+		response.OkWithMessage("租机批量续费成功", c)
+	}
+}
+
 // RentingOutRentComputer 租机退租
 func (s *ApiRentComputer) RentingOutRentComputer(c *gin.Context) {
 	var api request.RentingOutRentComputerRequest

+ 24 - 0
api/v1/rentComputer/rent_computer_ledger.go

@@ -5,6 +5,7 @@ import (
 	"go.uber.org/zap"
 	"log-server/global"
 	"log-server/model/log/response"
+	"log-server/model/rentComputer"
 	"log-server/model/rentComputer/request"
 )
 
@@ -61,3 +62,26 @@ func (s *ApiRentComputerLedger) ExportLedgerListExcel(c *gin.Context) {
 	c.Writer.Header().Add("success", "true")
 	c.File(filePath)
 }
+
+func (s *ApiRentComputerLedger) DeleteRentComputerLedgerByIds(c *gin.Context) {
+	var ids request.IdsReq
+	_ = c.ShouldBindJSON(&ids)
+	if err := ServiceRentComputerLedger.DeleteRentComputerLedgerByIds(ids); err != nil {
+		global.GVA_LOG.Error("删除失败!", zap.Error(err))
+		response.FailWithMessage("删除失败", c)
+	} else {
+		response.OkWithMessage("删除成功", c)
+	}
+}
+
+func (s *ApiRentComputerLedger) DeleteRentComputerLedgerById(c *gin.Context) {
+	var api rentComputer.RentComputerLedger
+	_ = c.ShouldBindJSON(&api)
+
+	if err := ServiceRentComputerLedger.DeleteRentComputerLedgerById(api); err != nil {
+		global.GVA_LOG.Error("删除失败!", zap.Error(err))
+		response.FailWithMessage("删除失败", c)
+	} else {
+		response.OkWithMessage("删除成功", c)
+	}
+}

+ 27 - 0
api/v1/rentComputer/rent_computer_log.go

@@ -0,0 +1,27 @@
+package rentComputer
+
+import (
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+	"log-server/global"
+	"log-server/model/log/response"
+	"log-server/model/rentComputer"
+)
+
+type ApiRentComputerLog struct {
+}
+
+// QueryRentComputerLogByPcNum 查询详细日志
+func (s *ApiRentComputerLog) QueryRentComputerLogByPcNum(c *gin.Context) {
+	var paramsInfo rentComputer.RentComputerLog
+	_ = c.ShouldBindJSON(&paramsInfo)
+	list, err := ServiceRentComputerLog.QueryRentComputerLogByPcNum(paramsInfo)
+	if err != nil {
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		response.OkWithDetailed(response.PageResult{
+			List: list,
+		}, "获取成功", c)
+	}
+}

+ 1 - 0
initialize/router.go

@@ -75,6 +75,7 @@ func Routers() *gin.Engine {
 		rentComputerRouter.InitRentComputerShopRouter(PublicGroup) // 租机供应商管理
 		rentComputerRouter.InitRentSetMealRouter(PublicGroup)
 		rentComputerRouter.InitRentComputerLedgerRouter(PublicGroup)
+		rentComputerRouter.InitRentComputerLogRouter(PublicGroup)
 		dataStatisticsRouter.InitDataAbnormalRateRouter(PublicGroup)      //数据统计
 		dataStatisticsRouter.InitWeChatScannerApiRouter(PublicGroup)      //数据统计
 		dataStatisticsRouter.InitWeChatScannerDetailedRouter(PublicGroup) //数据统计

+ 3 - 3
model/rentComputer/rent_computer.go

@@ -10,13 +10,13 @@ type RentComputer struct {
 	RentStart         string  `json:"rent_start"`         //起租时间
 	RentDuration      int     `json:"rent_duration"`      //租赁天数
 	RentEnd           string  `json:"rent_end"`           //到期时间
-	Remark            string  `json:"remark"`             //备注
+	Remark            string  `json:"remark"`             //最近一次日志
 	TodeskId          string  `json:"todesk_id"`          //todesk账号密码
 	TodeskPassword    string  `json:"todesk_password"`    //todesk账号密码
 	SunflowerId       string  `json:"sunflower_id"`       //向日葵账号密码
 	SunflowerPassword string  `json:"sunflower_password"` //向日葵账号密码
 	RentPriceUsed     float64 `json:"rent_price_used"`    //当前租赁期内已产生租金
-	IsExpire          int     `json:"is_expire"`          //是否到期 0:否 1:是 2:明日到期
+	IsExpire          int     `json:"is_expire"`          //是否到期 0:否 1:是 2:明日到期 3:一周内到期
 	SetMealId         uint    `json:"set_meal_id"`        //套餐名id
 	IsOffShelf        int     `json:"is_off_shelf"`       //是否下架 0:否 1:是
 	DirectorName      string  `json:"director_name"`      //具体使用人
@@ -34,7 +34,7 @@ type RentComputerSetMeal struct {
 	RentDuration int     `json:"rent_duration"`  //租赁天数
 	RentEnd      string  `json:"rent_end"`       //到期时间
 	Remark       string  `json:"remark"`         //备注
-	IsExpire     int     `json:"is_expire"`      //是否到期 0:否 1:是 2:明日到期
+	IsExpire     int     `json:"is_expire"`      //是否到期 0:否 1:是 2:明日到期 3:一周内到期
 	SetMealId    uint    `json:"set_meal_id"`    //套餐名id
 	RentPrice    float64 `json:"rent_price"`     //价格标准
 	RentPriceDay float64 `json:"rent_price_day"` //折算天租金

+ 15 - 0
model/rentComputer/rent_computer_log.go

@@ -0,0 +1,15 @@
+package rentComputer
+
+type RentComputerLog struct {
+	Id         uint   `json:"id"`
+	UpdateTime string `json:"update_time"` // 更新时间
+	CreateTime string `json:"create_time"` // 创建时间
+	PcNum      string `json:"pc_num"`      //电脑编号
+	ShopId     uint   `json:"shop_id"`     //供应商ID
+	SetMealId  uint   `json:"set_meal_id"` //套餐名id
+	Log        string `json:"log"`         //备注
+}
+
+func (RentComputerLog) TableName() string {
+	return "rent_computer_log"
+}

+ 9 - 2
model/rentComputer/request/rent_computer.go

@@ -32,16 +32,23 @@ type ComputerRequest struct {
 	IsOffShelf        int     `json:"is_off_shelf"`       //是否下架 0:否 1:是
 	DirectorName      string  `json:"director_name"`      //具体使用人
 }
+
+// RenewRentComputerRequest 单个续费
 type RenewRentComputerRequest struct {
 	PcId       uint   `json:"pc_id"`       // id
 	UpdateTime string `json:"update_time"` // 更新时间
 	PcNum      string `json:"pc_num"`      //电脑编号
-	Day        int    `json:"day"`         //租赁天数
-	RentRenew  string `json:"rent_renew"`  //到期时间
+	Day        int    `json:"day"`         //续费天数
+	RentRenew  string `json:"rent_renew"`  //续费到期时间
 	Remark     string `json:"remark"`      //备注
 	IsExpire   int    `json:"is_expire"`   //是否到期 0:否 1:是 2:明日到期
 }
 
+// RenewRentComputersRequest 批量续费
+type RenewRentComputersRequest struct {
+	RentMessage []RenewRentComputerRequest `json:"rent_message"` //批量续费电脑信息
+}
+
 type ReplaceNumRentComputerRequest struct {
 	PcNumOld string `json:"pc_num_old"`
 	PcNumNew string `json:"pc_num_new"`

+ 1 - 0
router/rentComputer/enter.go

@@ -5,5 +5,6 @@ type RouterGroup struct {
 	RentComputerRouter
 	RentComputerShopRouter
 	RentSetMealRouter
+	RentComputerLogRouter
 	// Code generated by log-server End; DO NOT EDIT.
 }

+ 1 - 0
router/rentComputer/rent_computer.go

@@ -24,6 +24,7 @@ func (e *RentComputerRouter) InitRentComputerRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("replaceNumRentComputer", rentComputerApi.ReplaceNumRentComputer)     //租机更换编号
 		excelRouter.POST("rentingOutRentComputer", rentComputerApi.RentingOutRentComputer)     //租机提前退租
 		excelRouter.POST("offShelfRentComputer", rentComputerApi.OffShelfRentComputer)         //租机下架
+		excelRouter.POST("renewRentComputerByBatch", rentComputerApi.RenewRentComputerByBatch) //租机批量续费
 
 	}
 }

+ 3 - 1
router/rentComputer/rent_computer_ledger.go

@@ -9,12 +9,14 @@ type RentComputerLedgerRouter struct {
 }
 
 func (e *RentComputerRouter) InitRentComputerLedgerRouter(Router *gin.RouterGroup) {
-	excelRouter := Router.Group("rentComputer")
+	excelRouter := Router.Group("rentComputerLedger")
 	rentComputerApi := v1.ApiGroupApp.RentComputerApiGroup.ApiRentComputerLedger
 	{
 		excelRouter.POST("getRentComputerLedgerList", rentComputerApi.GetRentComputerLedgerList) //查询记录
 		excelRouter.POST("getRentComputerLedgerNum", rentComputerApi.GetRentComputerLedgerNum)
 		excelRouter.POST("exportRentLedgerListExcel", rentComputerApi.ExportLedgerListExcel)
+		excelRouter.POST("deleteRentComputerLedgerById", rentComputerApi.DeleteRentComputerLedgerById)
+		excelRouter.POST("deleteRentComputerLedgerByIds", rentComputerApi.DeleteRentComputerLedgerByIds)
 
 	}
 }

+ 17 - 0
router/rentComputer/rent_computer_log.go

@@ -0,0 +1,17 @@
+package rentComputer
+
+import (
+	"github.com/gin-gonic/gin"
+	v1 "log-server/api/v1"
+)
+
+type RentComputerLogRouter struct {
+}
+
+func (r *RentComputerLogRouter) InitRentComputerLogRouter(Router *gin.RouterGroup) {
+	excelRouter := Router.Group("rentComputerLog")
+	rentComputerLogApi := v1.ApiGroupApp.RentComputerApiGroup.ApiRentComputerLog
+	{
+		excelRouter.POST("queryRentComputerLogByPcNum", rentComputerLogApi.QueryRentComputerLogByPcNum) //查询记录
+	}
+}

+ 1 - 0
service/rentComputer/enter.go

@@ -6,5 +6,6 @@ type ServiceGroup struct {
 	ServiceRentComputerShop
 	ServiceRentSetMeal
 	ServiceRentComputerLedger
+	ServiceRentComputerLog
 	// Code generated by log-server End; DO NOT EDIT.
 }

+ 208 - 31
service/rentComputer/rent_computer.go

@@ -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

+ 17 - 1
service/rentComputer/rent_computer_ledger.go

@@ -2,9 +2,11 @@ package rentComputer
 
 import (
 	"context"
+	"errors"
 	"fmt"
 	"github.com/xuri/excelize/v2"
 	"go.uber.org/zap"
+	"gorm.io/gorm"
 	"log-server/global"
 	"log-server/model/rentComputer"
 	"log-server/model/rentComputer/request"
@@ -73,7 +75,7 @@ func (service *ServiceRentComputerLedger) RentComputerLedgerList(ctx context.Con
 		}
 		err = db.Order(OrderStr).Find(&ledgerComputers).Error
 	} else {
-		err = db.Order("id").Find(&ledgerComputers).Error
+		err = db.Order("pc_num").Find(&ledgerComputers).Error
 	}
 	if err != nil {
 		return nil, 0, err
@@ -158,3 +160,17 @@ func (service *ServiceRentComputerLedger) ParseInfoList2Excel(infoList []*respon
 	err = excel.SaveAs(filePath)
 	return err
 }
+
+func (s *ServiceRentComputerLedger) DeleteRentComputerLedgerByIds(ids request.IdsReq) (err error) {
+	err = global.GVA_DB.Delete(&[]rentComputer.RentComputerLedger{}, "id in ?", ids.Ids).Error
+	return err
+}
+
+func (s *ServiceRentComputerLedger) DeleteRentComputerLedgerById(api rentComputer.RentComputerLedger) (err error) {
+	var entity rentComputer.RentComputerLedger
+	err = global.GVA_DB.Where("id = ?", api.Id).First(&entity).Error // 根据id查询api记录
+	if errors.Is(err, gorm.ErrRecordNotFound) {                      // api记录不存在
+		return err
+	}
+	return global.GVA_DB.Delete(&entity).Error
+}

+ 28 - 0
service/rentComputer/rent_computer_log.go

@@ -0,0 +1,28 @@
+package rentComputer
+
+import (
+	"log-server/global"
+	"log-server/model/rentComputer"
+)
+
+type ServiceRentComputerLog struct {
+}
+
+func (s *ServiceRentComputerLog) AddRentComputerLog(log rentComputer.RentComputerLog) (err error) {
+	//if !errors.Is(global.GVA_DB.Where("pc_num = ? and shop_id = ?", log.PcNum, log.ShopId).First(&rentComputer.RentComputer{}).Error, gorm.ErrRecordNotFound) {
+	//	return errors.New("租机编号已存在")
+	//}
+	global.GVA_LOG.Info("log>>>" + log.Log)
+	return global.GVA_DB.Create(&log).Error
+}
+
+// QueryRentComputerLogByPcNum 查询日志
+func (s *ServiceRentComputerLog) QueryRentComputerLogByPcNum(log rentComputer.RentComputerLog) (list interface{}, err error) {
+	//global.GVA_LOG.Info(log.PcNum)
+	//global.GVA_LOG.Info(strconv.Itoa(int(log.ShopId)))
+	var logList []rentComputer.RentComputerLog
+	db := global.GVA_DB.Model(&rentComputer.RentComputerLog{})
+	db.Where("pc_num = ? and shop_id = ?", log.PcNum, log.ShopId)
+	err = db.Order("create_time desc").Find(&logList).Error
+	return logList, err
+}