|
@@ -8,6 +8,10 @@ import (
|
|
|
"hongze/fms_api/global"
|
|
|
"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"
|
|
|
)
|
|
|
|
|
|
// // RegisterController 合同登记
|
|
@@ -17,8 +21,8 @@ type PrePaymentController struct{}
|
|
|
// @Title 到款预登记列表
|
|
|
// @Description 到款预登记列表
|
|
|
// @Param Keyword query string false "关键词"
|
|
|
-// @Param StartDate query string false "合同开始日期"
|
|
|
-// @Param EndDate query string false "合同结束日期"
|
|
|
+// @Param StartDate query string false "约定开始时间"
|
|
|
+// @Param EndDate query string false "约定结束时间"
|
|
|
// @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
|
|
|
// @Success 200 {object} fms.ContractRegisterItem
|
|
|
// @router /contract/pre_pay/list [get]
|
|
@@ -36,11 +40,11 @@ func (rg *PrePaymentController) List(c *gin.Context) {
|
|
|
|
|
|
cond := `1 = 1`
|
|
|
pars := make([]interface{}, 0)
|
|
|
- // 合同编号/客户姓名/销售/实际使用方
|
|
|
+ // 客户姓名/销售
|
|
|
if req.Keyword != "" {
|
|
|
kw := "%" + req.Keyword + "%"
|
|
|
- cond += ` AND (company_name LIKE ? OR contract_code LIKE ? OR seller_name LIKE ? OR actual_company_name LIKE ?)`
|
|
|
- pars = append(pars, kw, kw, kw, kw)
|
|
|
+ cond += ` AND (company_name LIKE ? OR seller_name LIKE ? )`
|
|
|
+ pars = append(pars, kw, kw)
|
|
|
}
|
|
|
if req.StartDate != "" && req.EndDate != "" {
|
|
|
st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
@@ -49,74 +53,273 @@ func (rg *PrePaymentController) List(c *gin.Context) {
|
|
|
pars = append(pars, st, ed)
|
|
|
}
|
|
|
|
|
|
+ // 货币列表
|
|
|
+ currencyOB := new(fms.CurrencyUnit)
|
|
|
+ currencyCond := `enable = 1`
|
|
|
+ currencyPars := make([]interface{}, 0)
|
|
|
+ currencyList, e := currencyOB.List(currencyCond, currencyPars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ unitMap := make(map[string]string)
|
|
|
+ for i := range currencyList {
|
|
|
+ unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
+ }
|
|
|
|
|
|
page := new(base.Page)
|
|
|
page.SetPageSize(req.PageSize)
|
|
|
page.SetCurrent(req.Current)
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
|
|
|
+ sortTypeMap := map[int]bool{0: false, 1: true, 2: false}
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: sortTypeMap[req.SortType]})
|
|
|
|
|
|
- total, list, e := fms.GetContractRegisterItemPageList(page, cond, pars)
|
|
|
+ total, list, e := fms.GetPrePayItemPageList(page, cond, pars)
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取合同登记列表失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("获取失败", "获取预登记列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- registerIds := make([]int, 0)
|
|
|
for i := range list {
|
|
|
- registerIds = append(registerIds, list[i].ContractRegisterId)
|
|
|
+ list[i].UnitName = unitMap[list[i].CurrencyUnit]
|
|
|
}
|
|
|
|
|
|
- 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)
|
|
|
+ page.SetTotal(total)
|
|
|
+ baseData := new(base.BaseData)
|
|
|
+ baseData.SetPage(page)
|
|
|
+ baseData.SetList(list)
|
|
|
+ resp.OkData("获取成功", baseData, c)
|
|
|
+}
|
|
|
+
|
|
|
+// Add
|
|
|
+// @Title 新增到款预登记
|
|
|
+// @Description 新增到款预登记
|
|
|
+// @Param request body fms.PrepayAddReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/pre_pay/add [post]
|
|
|
+func (rg *PrePaymentController) Add(c *gin.Context) {
|
|
|
+ req := new(fms.PrepayAddReq)
|
|
|
+ err := c.ShouldBind(&req)
|
|
|
+ if err != nil {
|
|
|
+ errs, ok := err.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- for i := range servicesNameList {
|
|
|
- serviceMap[servicesNameList[i].ContractRegisterId] = servicesNameList[i].ServicesName
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ // 货币及汇率
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var rate float64
|
|
|
+ for i := range rateList {
|
|
|
+ if req.CurrencyUnit == rateList[i].Code {
|
|
|
+ rate = rateList[i].RMBRate
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ob := new(fms.ContractPrePayment)
|
|
|
+ ob.CompanyName = req.CompanyName
|
|
|
+ ob.SellerId = req.SellerId
|
|
|
+ ob.SellerName = req.SellerName
|
|
|
+ ob.CurrencyUnit = req.CurrencyUnit
|
|
|
+ ob.StartDate = startDate
|
|
|
+ ob.EndDate = endDate
|
|
|
+ ob.AdminId = int(adminInfo.AdminId)
|
|
|
+ ob.AdminName = adminInfo.AdminName
|
|
|
+ ob.Amount = req.Amount / rate
|
|
|
+ ob.OriginAmount = req.Amount
|
|
|
+ ob.CurrencyUnit = req.CurrencyUnit
|
|
|
+ ob.Remark = req.Remark
|
|
|
+ ob.NewCompany = req.NewCompany
|
|
|
+ ob.Set()
|
|
|
+
|
|
|
+
|
|
|
+ // 新增合同及套餐
|
|
|
+ if e = ob.Create(); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //// 开票到款汇总
|
|
|
+ //nowTime := time.Now().Local()
|
|
|
+ //v := new(fms.InvoicePaymentSummary)
|
|
|
+ //v.CreateTime = nowTime
|
|
|
+ //v.ModifyTime = nowTime
|
|
|
+ //v.PrePayid = ob.PrePayId
|
|
|
+ //
|
|
|
+ //if e = v.Create(); e != nil {
|
|
|
+ // err = fmt.Errorf("新增汇总数据失败, Err: %s", e.Error())
|
|
|
+ //}
|
|
|
+
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+// Edit
|
|
|
+// @Title 编辑到款预登记
|
|
|
+// @Description 编辑到款预登记
|
|
|
+// @Param request body fms.ContractRegisterEditReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/pre_pay/edit [post]
|
|
|
+func (rg *PrePaymentController) Edit(c *gin.Context) {
|
|
|
+ req := new(fms.PrepayEditReq)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ // 货币及汇率
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var rate float64
|
|
|
+ for i := range rateList {
|
|
|
+ if req.CurrencyUnit == rateList[i].Code {
|
|
|
+ rate = rateList[i].RMBRate
|
|
|
+ break
|
|
|
}
|
|
|
+ }
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // 获取开票/到款列表
|
|
|
- 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)
|
|
|
+ ob := new(fms.ContractPrePayment)
|
|
|
+
|
|
|
+ item, e := ob.Fetch(req.PrePayId)
|
|
|
+ if e != nil {
|
|
|
+ if e == utils.ErrNoRow {
|
|
|
+ resp.Fail("预到款登记记录不存在或已被删除", 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])
|
|
|
- }
|
|
|
+ resp.FailMsg("操作失败", "获取预到款登记信息失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.CompanyName = req.CompanyName
|
|
|
+ item.SellerId = req.SellerId
|
|
|
+ item.SellerName = req.SellerName
|
|
|
+ item.CurrencyUnit = req.CurrencyUnit
|
|
|
+ item.StartDate = startDate
|
|
|
+ item.EndDate = endDate
|
|
|
+ item.AdminId = int(adminInfo.AdminId)
|
|
|
+ item.AdminName = adminInfo.AdminName
|
|
|
+ item.Amount = req.Amount / rate
|
|
|
+ item.OriginAmount = req.Amount
|
|
|
+ item.CurrencyUnit = req.CurrencyUnit
|
|
|
+ item.Remark = req.Remark
|
|
|
+ item.NewCompany = req.NewCompany
|
|
|
+ item.ModifyTime = time.Now().Local()
|
|
|
+
|
|
|
+ updateCols := []string{
|
|
|
+ "ContractCode", "CompanyName", "SellerId", "SellerName", "Amount", "StartDate", "EndDate",
|
|
|
+ "Remark", "ModifyTime","NewCompany", "OriginAmount", "CurrencyUnit",
|
|
|
+ }
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新到预款登记失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+// Del
|
|
|
+// @Title 删除到款预登记
|
|
|
+// @Description 删除到款预登记
|
|
|
+// @Param request body fms.ContractRegisterDelReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /contract/pre_pay/del [post]
|
|
|
+func (rg *PrePaymentController) Del(c *gin.Context) {
|
|
|
+ req := new(fms.PrepayDelReq)
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
|
- respList := make([]*fms.ContractRegisterList, 0)
|
|
|
- for i := range list {
|
|
|
- v := new(fms.ContractRegisterList)
|
|
|
- v.ContractRegisterItem = list[i]
|
|
|
- v.ServicesName = serviceMap[list[i].ContractRegisterId]
|
|
|
- v.InvoiceList = invoiceMap[list[i].ContractRegisterId]
|
|
|
- v.PaymentList = paymentMap[list[i].ContractRegisterId]
|
|
|
- respList = append(respList, v)
|
|
|
+ ob := new(fms.ContractPrePayment)
|
|
|
+ item, e := ob.Fetch(req.PrePayId)
|
|
|
+ if e != nil {
|
|
|
+ if e == utils.ErrNoRow {
|
|
|
+ resp.Fail("合同登记不存在或已被删除", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailMsg("获取合同登记失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e = item.Delete()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("删除记录失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- page.SetTotal(total)
|
|
|
- baseData := new(base.BaseData)
|
|
|
- baseData.SetPage(page)
|
|
|
- baseData.SetList(respList)
|
|
|
- resp.OkData("获取成功", baseData, c)
|
|
|
+ // 操作日志
|
|
|
+ //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.RealName
|
|
|
+ // logItem.OpData = opData
|
|
|
+ // logItem.OpType = fms.ContractRegisterOpTypeDel
|
|
|
+ // logItem.CreateTime = nowTime
|
|
|
+ // if e = logItem.Create(); e != nil {
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //}()
|
|
|
+
|
|
|
+ resp.Ok("操作成功", c)
|
|
|
}
|