|
@@ -9,6 +9,7 @@ import (
|
|
|
"hongze/fms_api/models/base"
|
|
|
"hongze/fms_api/models/fms"
|
|
|
"hongze/fms_api/models/system"
|
|
|
+ fmsService "hongze/fms_api/services/fms"
|
|
|
"hongze/fms_api/utils"
|
|
|
"time"
|
|
|
)
|
|
@@ -25,7 +26,7 @@ type RegisterController struct{}
|
|
|
// @Param ServiceType query int false "套餐类型"
|
|
|
// @Param ContractType query int false "合同类型"
|
|
|
// @Param RegisterStatus query int false "登记状态"
|
|
|
-// @Success 200 {object} fms.ContractRegisterListResp
|
|
|
+// @Success 200 {object} fms.ContractRegisterItem
|
|
|
// @router /contract/register/list [get]
|
|
|
func (rg *RegisterController) List(c *gin.Context) {
|
|
|
var req fms.ContractRegisterListReq
|
|
@@ -39,7 +40,7 @@ func (rg *RegisterController) List(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- cond := ``
|
|
|
+ cond := `1 = 1`
|
|
|
pars := make([]interface{}, 0)
|
|
|
if req.Keyword != "" {
|
|
|
kw := "%" + req.Keyword + "%"
|
|
@@ -50,10 +51,6 @@ func (rg *RegisterController) List(c *gin.Context) {
|
|
|
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)
|
|
@@ -62,39 +59,83 @@ func (rg *RegisterController) List(c *gin.Context) {
|
|
|
cond += ` AND register_status = ?`
|
|
|
pars = append(pars, req.RegisterStatus)
|
|
|
}
|
|
|
+ // 套餐筛选
|
|
|
+ if req.ServiceType != 0 {
|
|
|
+ registerIds, e := fms.GetContractRegisterIdsByTempId(req.ServiceType)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(registerIds) > 0 {
|
|
|
+ cond += ` AND contract_register_id IN ?`
|
|
|
+ pars = append(pars, registerIds)
|
|
|
+ } else {
|
|
|
+ cond += ` AND 1 = 2`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
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)
|
|
|
+ total, list, e := fms.GetContractRegisterItemPageList(page, cond, pars)
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取合同登记列表, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("获取失败", "获取合同登记列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- respList := make([]*fms.ContractRegisterListResp, 0)
|
|
|
+ registerIds := make([]int, 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),
|
|
|
- })
|
|
|
+ registerIds = append(registerIds, list[i].ContractRegisterId)
|
|
|
+ }
|
|
|
+
|
|
|
+ serviceMap := make(map[int]string, 0)
|
|
|
+ invoiceMap := make(map[int][]*fms.ContractInvoiceItem, 0)
|
|
|
+ paymentMap := make(map[int][]*fms.ContractInvoiceItem, 0)
|
|
|
+ if len(registerIds) > 0 {
|
|
|
+ // 获取服务套餐
|
|
|
+ servicesNameList, e := fms.GetContractRegisterServicesNameByRegisterIds(registerIds)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取套餐拼接字符串失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for i := range servicesNameList {
|
|
|
+ serviceMap[servicesNameList[i].ContractRegisterId] = servicesNameList[i].ServicesName
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取开票/到款列表
|
|
|
+ invoiceCond := `contract_register_id IN ?`
|
|
|
+ invoicePars := make([]interface{}, 0)
|
|
|
+ invoicePars = append(invoicePars, registerIds)
|
|
|
+ invoiceList, e := fms.GetContractInvoiceItemList(invoiceCond, invoicePars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取开票/到款列表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for i := range invoiceList {
|
|
|
+ if invoiceMap[invoiceList[i].ContractRegisterId] == nil {
|
|
|
+ invoiceMap[invoiceList[i].ContractRegisterId] = make([]*fms.ContractInvoiceItem, 0)
|
|
|
+ }
|
|
|
+ if paymentMap[invoiceList[i].ContractRegisterId] == nil {
|
|
|
+ paymentMap[invoiceList[i].ContractRegisterId] = make([]*fms.ContractInvoiceItem, 0)
|
|
|
+ }
|
|
|
+ if invoiceList[i].InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
+ invoiceMap[invoiceList[i].ContractRegisterId] = append(invoiceMap[invoiceList[i].ContractRegisterId], invoiceList[i])
|
|
|
+ }
|
|
|
+ if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
+ paymentMap[invoiceList[i].ContractRegisterId] = append(paymentMap[invoiceList[i].ContractRegisterId], invoiceList[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ respList := make([]*fms.ContractRegisterList, 0)
|
|
|
+ for i := range list {
|
|
|
+ v := new(fms.ContractRegisterList)
|
|
|
+ list[i].ServicesName = serviceMap[list[i].ContractRegisterId]
|
|
|
+ v.ContractRegisterItem = *list[i]
|
|
|
+ v.InvoiceList = invoiceMap[list[i].ContractRegisterId]
|
|
|
+ v.PaymentList = paymentMap[list[i].ContractRegisterId]
|
|
|
+ respList = append(respList, v)
|
|
|
}
|
|
|
|
|
|
page.SetTotal(total)
|
|
@@ -175,9 +216,16 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
ob.Remark = req.Remark
|
|
|
ob.Set()
|
|
|
|
|
|
- // TODO:套餐信息
|
|
|
- if e = ob.Create(); e != nil {
|
|
|
- resp.FailMsg("操作失败", "新增合同登记失败, Err:"+e.Error(), c)
|
|
|
+ // 套餐信息
|
|
|
+ serviceList, e := fmsService.HandleContractServiceAndDetail(req.ProductId, req.Services)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增合同及套餐
|
|
|
+ if e = fms.CreateContractRegisterAndServices(ob, serviceList); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -288,14 +336,22 @@ func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
"ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime", "ContractStatus",
|
|
|
"RegisterStatus", "Remark", "ModifyTime",
|
|
|
}
|
|
|
- if e = item.Update(updateCols); e != nil {
|
|
|
- resp.FailMsg("操作失败", "更新合同登记失败, Err: "+e.Error(), c)
|
|
|
+
|
|
|
+ // 套餐信息
|
|
|
+ serviceList, e := fmsService.HandleContractServiceAndDetail(req.ProductId, req.Services)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // TODO:套餐信息
|
|
|
+ // 更新合同及套餐
|
|
|
+ if e = fms.UpdateContractRegisterAndServices(ob, updateCols, serviceList); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新合同及套餐失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // TODO:校验金额-是否修改状态
|
|
|
+ // 校验金额-是否修改状态
|
|
|
+ go fmsService.CheckContractRegisterAmount(item.ContractRegisterId)
|
|
|
|
|
|
// 操作日志
|
|
|
go func() {
|
|
@@ -384,9 +440,75 @@ func (rg *RegisterController) Del(c *gin.Context) {
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|
|
|
|
|
|
-// 查看详情
|
|
|
+// Detail
|
|
|
+// @Title 合同登记详情
|
|
|
+// @Description 合同登记详情
|
|
|
+// @Param ContractRegisterId query int false "合同登记ID"
|
|
|
+// @Success 200 {object} fms.ContractRegisterDetail
|
|
|
+// @router /contract/register/detail [get]
|
|
|
func (rg *RegisterController) Detail(c *gin.Context) {
|
|
|
+ var req fms.ContractRegisterDetailReq
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ result := new(fms.ContractRegisterDetail)
|
|
|
+
|
|
|
+ // 合同登记信息
|
|
|
+ item, e := fms.GetContractRegisterItemById(req.ContractRegisterId)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取失败", "获取合同登记详情失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result.ContractRegisterItem = *item
|
|
|
+
|
|
|
+ // 套餐信息
|
|
|
+ serviceList, e := fmsService.GetContractServiceAndDetail(req.ContractRegisterId)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取失败", "获取合同套餐信息失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result.ServiceList = serviceList
|
|
|
+
|
|
|
+ // 开票/到款信息
|
|
|
+ invoiceCond := `contract_register_id = ?`
|
|
|
+ invoicePars := make([]interface{}, 0)
|
|
|
+ invoicePars = append(invoicePars, req.ContractRegisterId)
|
|
|
+ invoiceList, e := fms.GetContractInvoiceItemList(invoiceCond, invoicePars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取失败", "获取合同开票/到款信息失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result.InvoiceList = make([]*fms.ContractInvoiceItem, 0)
|
|
|
+ result.PaymentList = make([]*fms.ContractInvoiceItem, 0)
|
|
|
+ for i := range invoiceList {
|
|
|
+ if invoiceList[i].InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
+ result.InvoiceList = append(result.InvoiceList, invoiceList[i])
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
+ result.InvoiceList = append(result.InvoiceList, invoiceList[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合同登记进度
|
|
|
+ logCond := `contract_register_id = ?`
|
|
|
+ logPars := make([]interface{}, 0)
|
|
|
+ logPars = append(logPars, req.ContractRegisterId)
|
|
|
+ logList, e := fms.GetContractRegisterLogItemList(logCond, logPars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取失败", "获取合同登记进度失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result.Logs = logList
|
|
|
|
|
|
+ resp.OkData("获取成功", result, c)
|
|
|
}
|
|
|
|
|
|
// UpdateStatus
|
|
@@ -453,11 +575,6 @@ func (rg *RegisterController) UpdateStatus(c *gin.Context) {
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|
|
|
|
|
|
-// 导出
|
|
|
-func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
// Invoice
|
|
|
// @Title 开票/到款登记
|
|
|
// @Description 开票/到款登记
|
|
@@ -515,6 +632,9 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 校验金额-是否修改状态
|
|
|
+ go fmsService.CheckContractRegisterAmount(req.ContractRegisterId)
|
|
|
+
|
|
|
// 操作日志
|
|
|
go func() {
|
|
|
opData := ""
|
|
@@ -541,3 +661,8 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
|
|
|
}()
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|
|
|
+
|
|
|
+// 导出
|
|
|
+func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
+
|
|
|
+}
|