hsun 2 vuotta sitten
vanhempi
commit
6f1f5932e4

+ 35 - 1
controller/contract/register.go

@@ -1117,7 +1117,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		fms.ContractTypePlus:     3, // 补充协议
 	}
 	for _, v := range list {
-		k := -1	// 套餐匹配用
+		k := -1 // 套餐匹配用
 		dataRow := sheet.AddRow()
 		dataRow.SetHeight(20)
 		k += 4
@@ -1989,3 +1989,37 @@ func (rg *RegisterController) Import(c *gin.Context) {
 
 	resp.Ok("操作成功", c)
 }
+
+// CurrencyList
+// @Title 货币单位列表
+// @Description 货币单位列表
+// @Success 200 {object} fms.ContractRegisterItem
+// @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)
+	if e != nil {
+		resp.FailData("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
+		return
+	}
+
+	rateMap := make(map[string]float64)
+
+	// TODO:从缓存中读取汇率
+
+	// TODO:请求汇率接口
+
+	respList := make([]*fms.CurrencyUnitItem, 0)
+	for i := range list {
+		respList = append(respList, &fms.CurrencyUnitItem{
+			Name:    list[i].Name,
+			Code:    list[i].Code,
+			Enable:  list[i].Enable,
+			RMBRate: rateMap[list[i].Code],
+		})
+	}
+	resp.OkData("获取成功", respList, c)
+}

+ 31 - 0
models/fms/currency_unit.go

@@ -0,0 +1,31 @@
+package fms
+
+import "hongze/fms_api/global"
+
+// CurrencyUnit 货币单位表
+type CurrencyUnit struct {
+	CurrencyUnitId int    `gorm:"primaryKey;column:currency_unit_id" json:"-" description:"货币ID"`
+	Name           string `gorm:"column:name" json:"name" description:"货币名称"`
+	Code           string `gorm:"code" json:"code" description:"国际代码"`
+	Enable         int    `gorm:"enable" json:"enable" description:"状态: 0-禁用; 1-启用"`
+}
+
+func (m *CurrencyUnit) TableName() string {
+	return "currency_unit"
+}
+
+func (m *CurrencyUnit) List(condition string, pars []interface{}) (list []*CurrencyUnit, err error) {
+	list = make([]*CurrencyUnit, 0)
+	query := global.DEFAULT_MYSQL.Model(m).
+		Where(condition, pars...).
+		Order("currency_unit_id ASC")
+	err = query.Find(&list).Error
+	return
+}
+
+type CurrencyUnitItem struct {
+	Name    string  `json:"name" description:"货币名称"`
+	Code    string  `json:"code" description:"国际代码"`
+	Enable  int     `json:"enable" description:"状态: 0-禁用; 1-启用"`
+	RMBRate float64 `json:"rmb_rate" description:"当日对人民币汇率"`
+}

+ 1 - 0
routers/contract.go

@@ -22,6 +22,7 @@ func InitContract(rg *gin.RouterGroup) {
 	crGroup.GET("invoice_list", cr.InvoiceList)
 	crGroup.GET("invoice_export", cr.InvoiceExport)
 	crGroup.POST("import", cr.Import)
+	crGroup.GET("currency_list", cr.CurrencyList)
 
 	// 合同套餐
 	sr := new(contract.ServiceController)

+ 34 - 0
services/fms/currency_rate.go

@@ -0,0 +1,34 @@
+package fms
+
+import "time"
+
+// TODO:汇率
+
+const CurrencyRateApiAppCode = "ABC123"
+
+type CurrencyRateApiResp struct {
+	Status int                         `json:"status" description:"状态码"`
+	Msg    string                      `json:"msg" description:"响应信息"`
+	Result []CurrencyRateApiRespResult `json:"result" description:"响应数据"`
+}
+
+type CurrencyRateApiRespResult struct {
+	Currency string `json:"currency"`
+	Name     string `json:"name"`
+	List     map[string]CurrencyRateApiRespResultList
+}
+
+type CurrencyRateApiRespResultList struct {
+	Name       string    `json:"name"`
+	Rate       string    `json:"rate"`
+	UpdateTime time.Time `json:"updatetime"`
+}
+
+func CurlRateApi() {
+
+}
+
+// GetRMBRate 获取人民币汇率
+func GetRMBRate() (err error) {
+	return
+}