Browse Source

fix(账单): 已出账单金额改为实时查询

likai 4 years ago
parent
commit
c114e5d7a2

+ 2 - 2
model/account/internal/settle_account_bill.go

@@ -12,8 +12,8 @@ import (
 type SettleAccountBill struct {
 	Id                     int         `orm:"Id,primary"             json:"id"`                       // 主键
 	Code                   string      `orm:"Code"                   json:"code"`                     // 账单号
-	TotalCount             float64     `orm:"TotalCount"             json:"total_count"`              // 计费总额
-	SettleTime             *gtime.Time `orm:"SettleTime"             json:"settle_time"`              // 结算时间
+	TotalCount             float64     `orm:"TotalCount"             json:"total_count"`              // 计费总额(弃用,改为实时查询)
+	SettleTime             *gtime.Time `orm:"SettleTime"             json:"settle_time"`              // 结算时间(弃用)
 	StartDate              *gtime.Time `orm:"StartDate"              json:"start_date"`               // 账单开始时间
 	EndDate                *gtime.Time `orm:"EndDate"                json:"end_date"`                 // 账单结束时间
 	Status                 string      `orm:"Status"                 json:"status"`                   // 账单状态 0未确认 1已确认 2已结算 3已扣款

+ 5 - 0
model/account/settle_account_bill.go

@@ -32,4 +32,9 @@ type AccountBillSettleReq struct {
 
 type AccountBillConfirmReq struct {
 	BillId  int `json:"billId"`
+}
+
+type BillInfo struct {
+	SettleAccountBill
+	TotalAmount             float64     `orm:"TotalAmount"             json:"total_amount"`              // 计费总额
 }

+ 10 - 10
service/settle_account_bill/settle_account_bill.go

@@ -26,7 +26,7 @@ func NewService(tenant string) Service {
 }
 
 // List 会议室列表
-func (s Service)  List(req model.ListReq, user request.UserInfo) ([]accountModel.SettleAccountBill, int, error) {
+func (s Service)  List(req model.ListReq, user request.UserInfo) ([]accountModel.BillInfo, int, error) {
 	entityModel := s.Dao.M
 	where := "1=1"
 
@@ -37,28 +37,28 @@ func (s Service)  List(req model.ListReq, user request.UserInfo) ([]accountModel
 			return nil, 0, err
 		}
 		if entity.MainUserId != 0 {
-			where += fmt.Sprintf(" AND MainUserId='%v'", entity.MainUserId)
+			where += fmt.Sprintf(" AND settle_account_bill.MainUserId='%v'", entity.MainUserId)
 		}
 		if entity.Status != "" {
-			where += fmt.Sprintf(" AND Status='%v'", entity.Status)
+			where += fmt.Sprintf(" AND settle_account_bill.Status='%v'", entity.Status)
 		}
 		if entity.SettleDate != "" {
 			timelist := strings.Split(entity.SettleDate,",")
 			if len(timelist) == 2 {
-				where += fmt.Sprintf(" AND SettleDate>='%v' AND SettleDate<='%v'", timelist[0],timelist[1])
+				where += fmt.Sprintf(" AND settle_account_bill.SettleDate>='%v' AND settle_account_bill.SettleDate<='%v'", timelist[0],timelist[1])
 			}
 		}
 		if entity.SettleUser != "" {
-			where += fmt.Sprintf(" AND SettleUser LIKE '%%%v%%'", entity.SettleUser)
+			where += fmt.Sprintf(" AND settle_account_bill.SettleUser LIKE '%%%v%%'", entity.SettleUser)
 		}
 		if entity.MainUser != "" {
-			where += fmt.Sprintf(" AND MainUser LIKE '%%%v%%'", entity.MainUser)
+			where += fmt.Sprintf(" AND settle_account_bill.MainUser LIKE '%%%v%%'", entity.MainUser)
 		}
 		if entity.StartDate != "" && entity.EndDate != "" {
-			where += fmt.Sprintf(" AND StartDate>='%v' AND EndDate<='%v'", entity.StartDate, entity.EndDate)
+			where += fmt.Sprintf(" AND settle_account_bill.StartDate>='%v' AND settle_account_bill.EndDate<='%v'", entity.StartDate, entity.EndDate)
 		}
 		if entity.IsSelf != "1" {  // 1 查看全部;其他 查看自己
-			where += fmt.Sprintf(" AND MainUserId='%v'", user.Id)
+			where += fmt.Sprintf(" AND settle_account_bill.MainUserId='%v'", user.Id)
 		}
 	}
 	entityModel = entityModel.Where(where)
@@ -70,7 +70,7 @@ func (s Service)  List(req model.ListReq, user request.UserInfo) ([]accountModel
 		return nil, 0, nil
 	}
 
-	res, err := entityModel.Page(req.Current, req.Size).Order("settle_account_bill.Id DESC").Fields("settle_account_bill.*").FindAll()
+	res, err := entityModel.InnerJoin("settle_account_main", "settle_account_bill.Id=settle_account_main.BillId").Group("settle_account_bill.Id").Page(req.Current, req.Size).Order("settle_account_bill.Id DESC").Fields("settle_account_bill.*, SUM(settle_account_main.TotalPrice) TotalAmount").FindAll()
 	if err != nil {
 		return nil, 0, err
 	}
@@ -78,7 +78,7 @@ func (s Service)  List(req model.ListReq, user request.UserInfo) ([]accountModel
 		return nil, 0, nil
 	}
 
-	list := make([]accountModel.SettleAccountBill, 0)
+	list := make([]accountModel.BillInfo, 0)
 	err = res.Structs(&list)
 	if err != nil {
 		return nil, 0, err