package backstage_api

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gconv"
	"net/http"
	"youngmini_server/app/model/backstage_model"
	"youngmini_server/app/service/backstage_service"
	"youngmini_server/library/response"
)

var Finance = financeApi{}

type financeApi struct {
}

// FindAll  账户查询所有信息接口
func (account *financeApi) FindAll(r *ghttp.Request) {
	var apiReq *backstage_model.FinanceFind
	if err := r.ParseForm(&apiReq); err != nil {
		response.JsonExit(r, http.StatusBadRequest, err.Error())
	}
	res, num, err := backstage_service.Finance.FindAllFinance(apiReq)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	var result []*backstage_model.FinanceFindAll
	err = gconv.Structs(res, &result)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	response.JsonExit(r, http.StatusOK, "数据返回成功", g.Map{
		"result": result, "num": num,
	})
}

// ChangeListStatus 批量打款成功
func (account *financeApi) ChangeListStatus(r *ghttp.Request) {
	var apiReq *backstage_model.ChangeMoneyListStatus
	if err := r.ParseForm(&apiReq); err != nil {
		response.JsonExit(r, http.StatusBadRequest, err.Error())
	}
	err := backstage_service.Finance.ChangeListStatus(apiReq)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	response.JsonExit(r, http.StatusOK, "0")
}
