|
@@ -2,12 +2,10 @@ package contract
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
- "context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
- jsoniter "github.com/json-iterator/go"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"github.com/tealeg/xlsx"
|
|
|
"hongze/fms_api/controller/resp"
|
|
@@ -219,6 +217,24 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
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
|
|
|
+ }
|
|
|
+
|
|
|
nowTime := time.Now().Local()
|
|
|
ob.ContractCode = req.ContractCode
|
|
|
ob.RelateContractCode = req.RelateContractCode
|
|
@@ -231,6 +247,8 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
ob.SellerName = req.SellerName
|
|
|
ob.ContractType = req.ContractType
|
|
|
ob.ContractAmount = req.ContractAmount
|
|
|
+ ob.CurrencyUnit = req.CurrencyUnit
|
|
|
+ ob.RMBRate = rate
|
|
|
ob.StartDate = startDate
|
|
|
ob.EndDate = endDate
|
|
|
ob.SignDate = signDate
|
|
@@ -350,6 +368,11 @@ func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
originHasPayment := item.HasPayment
|
|
|
+ // TODO:确认是否允许修改货币单位,若可修改货币单位则需要相应的处理开票到款
|
|
|
+ if req.CurrencyUnit != item.CurrencyUnit {
|
|
|
+ resp.Fail("暂不允许修改货币单位", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
updateCols := []string{
|
|
|
"ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
|
|
@@ -1072,7 +1095,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
for i := range otherService {
|
|
|
row2Title = append(row2Title, otherService[i].Title)
|
|
|
}
|
|
|
- row2Title = append(row2Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "约定付款时间", "签订日", "合同状态",
|
|
|
+ row2Title = append(row2Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "金额单位", "约定付款时间", "签订日", "合同状态",
|
|
|
"合同编号", "合规备注")
|
|
|
|
|
|
// 设置表头
|
|
@@ -1177,6 +1200,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
|
|
|
dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.StartDate)) // 开始时间
|
|
|
dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.EndDate)) // 到期时间
|
|
|
dataRow.AddCell().SetString(fmt.Sprint("¥", v.ContractAmount)) // 2022年合同金额
|
|
|
+ dataRow.AddCell().SetString(v.CurrencyUnit) // 货币单位
|
|
|
dataRow.AddCell().SetString(v.AgreedPayTime) // 约定付款时间
|
|
|
dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.SignDate)) // 签订日
|
|
|
dataRow.AddCell().SetString(fms.ContractStatusKeyNameMap[v.ContractStatus]) // 合同状态
|
|
@@ -1499,6 +1523,17 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
serviceTempNameMap[serviceTempList[i].Title] = serviceTempList[i]
|
|
|
}
|
|
|
|
|
|
+ // 获取货币列表及汇率(汇率为导入日的汇率)
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取货币列表及汇率失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rateMap := make(map[string]float64)
|
|
|
+ for i := range rateList {
|
|
|
+ rateMap[rateList[i].Code] = rateList[i].RMBRate
|
|
|
+ }
|
|
|
+
|
|
|
titleMap := make(map[int]string)
|
|
|
newIds := make([]int, 0)
|
|
|
newCompanyArr := []string{"0", "1"}
|
|
@@ -1751,13 +1786,24 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
rowRegister.ContractAmount = amount
|
|
|
continue
|
|
|
}
|
|
|
- // 约定付款日期
|
|
|
+ // 金额单位
|
|
|
if k == 37 {
|
|
|
+ rate := rateMap[v]
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.Fail(fmt.Sprintf("第%d行金额单位有误, 请按模板导入", i+1), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rowRegister.CurrencyUnit = v
|
|
|
+ rowRegister.RMBRate = rate
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 约定付款日期
|
|
|
+ if k == 38 {
|
|
|
rowRegister.AgreedPayTime = v
|
|
|
continue
|
|
|
}
|
|
|
// 签订日
|
|
|
- if k == 38 {
|
|
|
+ if k == 39 {
|
|
|
va := cell.Value
|
|
|
if va == "" {
|
|
|
continue
|
|
@@ -1779,7 +1825,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
continue
|
|
|
}
|
|
|
// 合同状态
|
|
|
- if k == 39 {
|
|
|
+ if k == 40 {
|
|
|
rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
|
|
|
if rowRegister.ContractStatus == 0 {
|
|
|
resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
|
|
@@ -1788,7 +1834,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
continue
|
|
|
}
|
|
|
// 合同编号
|
|
|
- if k == 40 {
|
|
|
+ if k == 41 {
|
|
|
rowContractCode := v
|
|
|
if rowContractCode == "" {
|
|
|
resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
|
|
@@ -1803,12 +1849,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
continue
|
|
|
}
|
|
|
// 合规备注
|
|
|
- if k == 41 {
|
|
|
+ if k == 42 {
|
|
|
rowRegister.Remark = v
|
|
|
continue
|
|
|
}
|
|
|
// 开票列表
|
|
|
- k2 := 41
|
|
|
+ k2 := 42
|
|
|
for ir := 0; ir < invoiceMax; ir++ {
|
|
|
n := ir + 1
|
|
|
// 开票日
|
|
@@ -1998,61 +2044,10 @@ func (rg *RegisterController) Import(c *gin.Context) {
|
|
|
// @Success 200 {object} fms.CurrencyUnitItem
|
|
|
// @router /contract/register/currency_list [get]
|
|
|
func (rg *RegisterController) CurrencyList(c *gin.Context) {
|
|
|
- // 货币列表
|
|
|
- ob := new(fms.CurrencyUnit)
|
|
|
- cond := `enable = 1`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- list, e := ob.List(cond, pars)
|
|
|
+ list, e := fmsService.GetTodayCurrencyRateList()
|
|
|
if e != nil {
|
|
|
- resp.FailData("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailData("获取失败", "获取今日货币汇率列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- rateMap := make(map[string]float64)
|
|
|
- rateList := make([]*fmsService.CurrencyRateItem, 0)
|
|
|
-
|
|
|
- // 读取缓存
|
|
|
- cacheJson, _ := global.Redis.Get(context.TODO(), utils.CURRENCY_RMB_RATE).Result()
|
|
|
- if cacheJson != "" {
|
|
|
- if e = jsoniter.UnmarshalFromString(cacheJson, &rateList); e != nil {
|
|
|
- resp.FailData("获取失败", "读取汇率缓存失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 请求汇率接口
|
|
|
- if cacheJson == "" {
|
|
|
- rateList, e = fmsService.GetCurrencyRateList()
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取失败", "请求汇率接口失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- newCache, e := jsoniter.MarshalToString(rateList)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取失败", "写入汇率缓存失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- now := time.Now()
|
|
|
- todayLast := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
|
|
|
- sub := todayLast.Sub(now)
|
|
|
- _ = global.Redis.SetEX(context.TODO(), utils.CURRENCY_RMB_RATE, newCache, sub)
|
|
|
- }
|
|
|
- for i := range rateList {
|
|
|
- rateMap[rateList[i].Code] = rateList[i].Rate
|
|
|
- }
|
|
|
-
|
|
|
- respList := make([]*fms.CurrencyUnitItem, 0)
|
|
|
- for i := range list {
|
|
|
- r := rateMap[list[i].Code]
|
|
|
- if list[i].Code == fms.BaseCurrencyCode {
|
|
|
- r = 1
|
|
|
- }
|
|
|
- respList = append(respList, &fms.CurrencyUnitItem{
|
|
|
- Name: list[i].Name,
|
|
|
- Code: list[i].Code,
|
|
|
- Enable: list[i].Enable,
|
|
|
- RMBRate: r,
|
|
|
- })
|
|
|
- }
|
|
|
- resp.OkData("获取成功", respList, c)
|
|
|
+ resp.OkData("获取成功", list, c)
|
|
|
}
|