|
@@ -0,0 +1,543 @@
|
|
|
+package contract
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "github.com/go-playground/validator/v10"
|
|
|
+ "hongze/fms_api/controller/resp"
|
|
|
+ "hongze/fms_api/global"
|
|
|
+ "hongze/fms_api/models/base"
|
|
|
+ "hongze/fms_api/models/fms"
|
|
|
+ "hongze/fms_api/models/system"
|
|
|
+ "hongze/fms_api/utils"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// RegisterController 合同登记
|
|
|
+type RegisterController struct{}
|
|
|
+
|
|
|
+// List
|
|
|
+// @Title 合同登记列表
|
|
|
+// @Description 合同登记列表
|
|
|
+// @Param Keyword query string false "关键词"
|
|
|
+// @Param StartDate query string false "合同开始日期"
|
|
|
+// @Param EndDate query string false "合同结束日期"
|
|
|
+// @Param ServiceType query int false "套餐类型"
|
|
|
+// @Param ContractType query int false "合同类型"
|
|
|
+// @Param RegisterStatus query int false "登记状态"
|
|
|
+// @Success 200 {object} fms.ContractRegisterListResp
|
|
|
+// @router /contract/register/list [get]
|
|
|
+func (rg *RegisterController) List(c *gin.Context) {
|
|
|
+ var req fms.ContractRegisterListReq
|
|
|
+ if e := c.BindQuery(&req); e != nil {
|
|
|
+ err, ok := e.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", err.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ cond := ``
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ if req.Keyword != "" {
|
|
|
+ kw := "%" + req.Keyword + "%"
|
|
|
+ cond += ` AND (company_name LIKE ? OR contract_code LIKE ? OR seller_name LIKE ?)`
|
|
|
+ pars = append(pars, kw, kw, kw)
|
|
|
+ }
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ cond += ` AND (start_time >= ? AND end_time <= ?)`
|
|
|
+ pars = append(pars, req.StartDate, req.EndDate)
|
|
|
+ }
|
|
|
+ if req.ServiceType != 0 {
|
|
|
+ cond += ` AND service_type = ?`
|
|
|
+ pars = append(pars, req.ServiceType)
|
|
|
+ }
|
|
|
+ if req.ContractType != 0 {
|
|
|
+ cond += ` AND contract_type = ?`
|
|
|
+ pars = append(pars, req.ContractType)
|
|
|
+ }
|
|
|
+ if req.RegisterStatus != 0 {
|
|
|
+ cond += ` AND register_status = ?`
|
|
|
+ pars = append(pars, req.RegisterStatus)
|
|
|
+ }
|
|
|
+ page := new(base.Page)
|
|
|
+ page.SetPageSize(req.PageSize)
|
|
|
+ page.SetCurrent(req.Current)
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
|
|
|
+
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ total, list, e := ob.PageList(page, cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取合同登记列表, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ respList := make([]*fms.ContractRegisterListResp, 0)
|
|
|
+ for i := range list {
|
|
|
+ // TODO:套餐信息
|
|
|
+ respList = append(respList, &fms.ContractRegisterListResp{
|
|
|
+ ContractRegisterId: list[i].ContractRegisterId,
|
|
|
+ ContractCode: list[i].ContractCode,
|
|
|
+ CompanyName: list[i].CompanyName,
|
|
|
+ SellerId: list[i].SellerId,
|
|
|
+ SellerName: list[i].SellerName,
|
|
|
+ ContractType: list[i].ContractType,
|
|
|
+ ContractAmount: list[i].ContractAmount,
|
|
|
+ InvoicedAmount: list[i].InvoicedAmount,
|
|
|
+ PaymentAmount: list[i].PaymentAmount,
|
|
|
+ StartDate: utils.TimeTransferString(utils.FormatDate, list[i].StartDate),
|
|
|
+ EndDate: utils.TimeTransferString(utils.FormatDate, list[i].EndDate),
|
|
|
+ SignDate: utils.TimeTransferString(utils.FormatDate, list[i].SignDate),
|
|
|
+ AgreedPayTime: list[i].AgreedPayTime,
|
|
|
+ ContractStatus: list[i].ContractStatus,
|
|
|
+ RegisterStatus: list[i].RegisterStatus,
|
|
|
+ Remark: list[i].Remark,
|
|
|
+ CreateTime: utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ page.SetTotal(total)
|
|
|
+ baseData := new(base.BaseData)
|
|
|
+ baseData.SetPage(page)
|
|
|
+ baseData.SetList(respList)
|
|
|
+ resp.OkData("获取成功", baseData, c)
|
|
|
+}
|
|
|
+
|
|
|
+// Add
|
|
|
+// @Title 新增合同登记
|
|
|
+// @Description 新增合同登记
|
|
|
+// @Param request body fms.ContractRegisterAddReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/register/add [post]
|
|
|
+func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
+ req := new(fms.ContractRegisterAddReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
+ if err != nil {
|
|
|
+ errs, ok := err.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ claims, _ := c.Get("adminInfo")
|
|
|
+ adminInfo := claims.(*system.SysAdmin)
|
|
|
+
|
|
|
+ // 日期校验
|
|
|
+ startDate, e := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("合同开始日期格式有误", "合同开始日期格式有误, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endDate, e := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("合同结束日期格式有误", "合同结束日期格式有误, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ signDate, e := time.ParseInLocation(utils.FormatDate, req.SignDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("合同签订日期格式有误", "合同签订日期格式有误, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否存在相同合同编号的登记
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ existCond := `contract_code = ?`
|
|
|
+ existPars := make([]interface{}, 0)
|
|
|
+ existPars = append(existPars, req.ContractCode)
|
|
|
+ exist, e := ob.FetchByCondition(existCond, existPars)
|
|
|
+ if e != nil && e != utils.ErrNoRow {
|
|
|
+ resp.FailMsg("操作失败", "获取相同登记号失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if exist != nil && exist.ContractRegisterId > 0 {
|
|
|
+ resp.Fail("合同编号已存在", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ ob.ContractCode = req.ContractCode
|
|
|
+ ob.CrmContractId = req.CrmContractId
|
|
|
+ ob.ContractSource = req.ContractSource
|
|
|
+ ob.CompanyName = req.CompanyName
|
|
|
+ ob.SellerId = req.SellerId
|
|
|
+ ob.SellerName = req.SellerName
|
|
|
+ ob.ContractType = req.ContractType
|
|
|
+ ob.ContractAmount = req.ContractAmount
|
|
|
+ ob.StartDate = startDate
|
|
|
+ ob.EndDate = endDate
|
|
|
+ ob.SignDate = signDate
|
|
|
+ ob.AgreedPayTime = req.AgreedPayTime
|
|
|
+ ob.ContractStatus = req.ContractStatus
|
|
|
+ ob.RegisterStatus = fms.ContractRegisterStatusIng
|
|
|
+ ob.Remark = req.Remark
|
|
|
+ ob.Set()
|
|
|
+
|
|
|
+ // TODO:套餐信息
|
|
|
+ if e = ob.Create(); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "新增合同登记失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 操作日志
|
|
|
+ go func() {
|
|
|
+ opData := ""
|
|
|
+ opDataByte, e := json.Marshal(req)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ opData = string(opDataByte)
|
|
|
+
|
|
|
+ logItem := new(fms.ContractRegisterLog)
|
|
|
+ logItem.ContractRegisterId = ob.ContractRegisterId
|
|
|
+ logItem.AdminId = int(adminInfo.AdminId)
|
|
|
+ logItem.AdminName = adminInfo.AdminName
|
|
|
+ logItem.OpData = opData
|
|
|
+ logItem.OpType = fms.ContractRegisterOpTypeSave
|
|
|
+ logItem.CreateTime = nowTime
|
|
|
+ if e = logItem.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+// Edit
|
|
|
+// @Title 编辑合同登记
|
|
|
+// @Description 编辑合同登记
|
|
|
+// @Param request body fms.ContractRegisterEditReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/register/edit [post]
|
|
|
+func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
+ req := new(fms.ContractRegisterEditReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
+ if err != nil {
|
|
|
+ errs, ok := err.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ claims, _ := c.Get("adminInfo")
|
|
|
+ adminInfo := claims.(*system.SysAdmin)
|
|
|
+
|
|
|
+ // 日期校验
|
|
|
+ startDate, e := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("合同开始日期格式有误", "合同开始日期格式有误, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endDate, e := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("合同结束日期格式有误", "合同结束日期格式有误, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ signDate, e := time.ParseInLocation(utils.FormatDate, req.SignDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("合同签订日期格式有误", "合同签订日期格式有误, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ item, e := ob.Fetch(req.ContractRegisterId)
|
|
|
+ if e != nil {
|
|
|
+ if e == utils.ErrNoRow {
|
|
|
+ resp.Fail("登记记录不存在或已被删除", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailMsg("操作失败", "获取合同登记信息失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 是否存在相同合同编号的登记
|
|
|
+ existCond := `contract_code = ?`
|
|
|
+ existPars := make([]interface{}, 0)
|
|
|
+ existPars = append(existPars, req.ContractCode)
|
|
|
+ exist, e := ob.FetchByCondition(existCond, existPars)
|
|
|
+ if e != nil && e != utils.ErrNoRow {
|
|
|
+ resp.FailMsg("操作失败", "获取相同登记号失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if exist != nil && exist.ContractRegisterId > 0 && exist.ContractRegisterId != item.ContractRegisterId {
|
|
|
+ resp.Fail("合同编号已存在", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ item.ContractCode = req.ContractCode
|
|
|
+ item.CrmContractId = req.CrmContractId
|
|
|
+ item.ContractSource = req.ContractSource
|
|
|
+ item.CompanyName = req.CompanyName
|
|
|
+ item.SellerId = req.SellerId
|
|
|
+ item.SellerName = req.SellerName
|
|
|
+ item.ContractType = req.ContractType
|
|
|
+ item.ContractAmount = req.ContractAmount
|
|
|
+ item.StartDate = startDate
|
|
|
+ item.EndDate = endDate
|
|
|
+ item.SignDate = signDate
|
|
|
+ item.AgreedPayTime = req.AgreedPayTime
|
|
|
+ item.ContractStatus = req.ContractStatus
|
|
|
+ item.RegisterStatus = fms.ContractRegisterStatusIng
|
|
|
+ item.Remark = req.Remark
|
|
|
+ item.ModifyTime = nowTime
|
|
|
+ updateCols := []string{
|
|
|
+ "ContractCode", "CrmContractId", "ContractSource", "CompanyName", "SellerId", "SellerName",
|
|
|
+ "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime", "ContractStatus",
|
|
|
+ "RegisterStatus", "Remark", "ModifyTime",
|
|
|
+ }
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新合同登记失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO:套餐信息
|
|
|
+
|
|
|
+ // TODO:校验金额-是否修改状态
|
|
|
+
|
|
|
+ // 操作日志
|
|
|
+ go func() {
|
|
|
+ opData := ""
|
|
|
+ opDataByte, e := json.Marshal(req)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ opData = string(opDataByte)
|
|
|
+
|
|
|
+ logItem := new(fms.ContractRegisterLog)
|
|
|
+ logItem.ContractRegisterId = item.ContractRegisterId
|
|
|
+ logItem.AdminId = int(adminInfo.AdminId)
|
|
|
+ logItem.AdminName = adminInfo.AdminName
|
|
|
+ logItem.OpData = opData
|
|
|
+ logItem.OpType = fms.ContractRegisterOpTypeSave
|
|
|
+ logItem.CreateTime = nowTime
|
|
|
+ if e = logItem.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+// Del
|
|
|
+// @Title 删除合同登记
|
|
|
+// @Description 删除合同登记
|
|
|
+// @Param request body fms.ContractRegisterDelReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/register/del [post]
|
|
|
+func (rg *RegisterController) Del(c *gin.Context) {
|
|
|
+ req := new(fms.ContractRegisterDelReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
+ if err != nil {
|
|
|
+ errs, ok := err.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ claims, _ := c.Get("adminInfo")
|
|
|
+ adminInfo := claims.(*system.SysAdmin)
|
|
|
+
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ item, e := ob.Fetch(req.ContractRegisterId)
|
|
|
+ if e != nil {
|
|
|
+ if e == utils.ErrNoRow {
|
|
|
+ resp.Fail("合同登记不存在或已被删除", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailMsg("获取合同登记失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ item.IsDeleted = 1
|
|
|
+ item.ModifyTime = nowTime
|
|
|
+ updateCols := []string{"IsDeleted", "ModifyTime"}
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新合同登记失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 操作日志
|
|
|
+ go func() {
|
|
|
+ opData := ""
|
|
|
+ opDataByte, e := json.Marshal(req)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ opData = string(opDataByte)
|
|
|
+
|
|
|
+ logItem := new(fms.ContractRegisterLog)
|
|
|
+ logItem.ContractRegisterId = req.ContractRegisterId
|
|
|
+ logItem.AdminId = int(adminInfo.AdminId)
|
|
|
+ logItem.AdminName = adminInfo.AdminName
|
|
|
+ logItem.OpData = opData
|
|
|
+ logItem.OpType = fms.ContractRegisterOpTypeDel
|
|
|
+ logItem.CreateTime = nowTime
|
|
|
+ if e = logItem.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+// 查看详情
|
|
|
+func (rg *RegisterController) Detail(c *gin.Context) {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// UpdateStatus
|
|
|
+// @Title 修改合同状态
|
|
|
+// @Description 修改合同状态
|
|
|
+// @Param request body fms.ContractRegisterUpdateStatusReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/register/update_status [post]
|
|
|
+func (rg *RegisterController) UpdateStatus(c *gin.Context) {
|
|
|
+ req := new(fms.ContractRegisterUpdateStatusReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
+ if err != nil {
|
|
|
+ errs, ok := err.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ claims, _ := c.Get("adminInfo")
|
|
|
+ adminInfo := claims.(*system.SysAdmin)
|
|
|
+
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ item, e := ob.Fetch(req.ContractRegisterId)
|
|
|
+ if e != nil {
|
|
|
+ if e == utils.ErrNoRow {
|
|
|
+ resp.Fail("合同登记不存在或已被删除", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailMsg("获取合同登记失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ item.ContractStatus = req.ContractStatus
|
|
|
+ item.ModifyTime = nowTime
|
|
|
+ updateCols := []string{"ContractStatus", "ModifyTime"}
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新合同登记失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 操作日志
|
|
|
+ go func() {
|
|
|
+ opData := ""
|
|
|
+ opDataByte, e := json.Marshal(req)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ opData = string(opDataByte)
|
|
|
+
|
|
|
+ logItem := new(fms.ContractRegisterLog)
|
|
|
+ logItem.ContractRegisterId = req.ContractRegisterId
|
|
|
+ logItem.AdminId = int(adminInfo.AdminId)
|
|
|
+ logItem.AdminName = adminInfo.AdminName
|
|
|
+ logItem.OpData = opData
|
|
|
+ logItem.OpType = fms.ContractRegisterOpTypeStatus
|
|
|
+ logItem.CreateTime = nowTime
|
|
|
+ if e = logItem.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+// 导出
|
|
|
+func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// Invoice
|
|
|
+// @Title 开票/到款登记
|
|
|
+// @Description 开票/到款登记
|
|
|
+// @Param request body fms.ContractInvoiceSaveReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/register/invoice [post]
|
|
|
+func (rg *RegisterController) Invoice(c *gin.Context) {
|
|
|
+ req := new(fms.ContractInvoiceSaveReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
+ if err != nil {
|
|
|
+ errs, ok := err.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ claims, _ := c.Get("adminInfo")
|
|
|
+ adminInfo := claims.(*system.SysAdmin)
|
|
|
+
|
|
|
+ newInvoice := make([]*fms.ContractInvoice, 0)
|
|
|
+ if len(req.AmountList) > 0 {
|
|
|
+ for i := range req.AmountList {
|
|
|
+ if req.AmountList[i].Amount <= 0 {
|
|
|
+ resp.Fail("登记金额有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.AmountList[i].InvoiceDate == "" {
|
|
|
+ resp.Fail("请选择日期", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ t, e := time.ParseInLocation(utils.FormatDate, req.AmountList[i].InvoiceDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("日期格式有误", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ v := &fms.ContractInvoice{
|
|
|
+ ContractRegisterId: req.ContractRegisterId,
|
|
|
+ Amount: req.AmountList[i].Amount,
|
|
|
+ InvoiceType: req.InvoiceType,
|
|
|
+ InvoiceDate: t,
|
|
|
+ AdminId: int(adminInfo.AdminId),
|
|
|
+ AdminName: adminInfo.AdminName,
|
|
|
+ }
|
|
|
+ v.Set()
|
|
|
+ newInvoice = append(newInvoice, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除并新增登记
|
|
|
+ ob := new(fms.ContractInvoice)
|
|
|
+ if e := ob.DeleteAndCreateNewInvoice(req.ContractRegisterId, req.InvoiceType, newInvoice); e != nil {
|
|
|
+ resp.FailData("日期格式有误", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 操作日志
|
|
|
+ go func() {
|
|
|
+ opData := ""
|
|
|
+ opDataByte, e := json.Marshal(req)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ opData = string(opDataByte)
|
|
|
+ opType := fms.ContractRegisterOpTypeInvoice
|
|
|
+ if req.InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
+ opType = fms.ContractRegisterOpTypePayment
|
|
|
+ }
|
|
|
+
|
|
|
+ logItem := new(fms.ContractRegisterLog)
|
|
|
+ logItem.ContractRegisterId = req.ContractRegisterId
|
|
|
+ logItem.AdminId = int(adminInfo.AdminId)
|
|
|
+ logItem.AdminName = adminInfo.AdminName
|
|
|
+ logItem.OpData = opData
|
|
|
+ logItem.OpType = opType
|
|
|
+ logItem.CreateTime = time.Now().Local()
|
|
|
+ if e = logItem.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|