12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package accounting
- import (
- "context"
- "gd_management/apis"
- "gd_management/common.in/utils"
- "gd_management/consts"
- "gd_management/errors"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- )
- func ChargeList(ctx context.Context, req *apis.ChargeListReq, reply *apis.ChargeListReply) error {
- if req.PageNumber > 0 {
- req.PageNumber -= 1
- } else {
- req.PageNumber = 0
- }
- o := orm.NewOrm()
- sql := "select t1.* ,t2.merchant_name from t_gd_bill as t1 left join t_gd_merchants as t2 on t1.merchant_id=t2.id where t1.bill_type=1"
- where := ""
- if req.MerchantId != 0 {
- where = fmt.Sprintf("%s and t1.merchant_id=%d", where, req.MerchantId)
- }
- if req.StartTime != "" {
- if len(req.StartTime) > consts.DayLen {
- req.StartTime = req.StartTime[0:consts.DayLen]
- }
- where = fmt.Sprintf("%s and t1.bill_create_time>='%s'", where, req.StartTime)
- }
- if req.EndTime != "" {
- if len(req.EndTime) > consts.DayLen {
- req.EndTime = req.EndTime[0:consts.DayLen]
- }
- where = fmt.Sprintf("%s and t1.bill_create_time<='%s'", where, req.EndTime)
- }
- sql = sql + where
- sql = fmt.Sprintf("%s order by t1.id desc", sql)
- sql = sql + " LIMIT ? OFFSET ?"
- countSql := `select count(1) from t_gd_bill as t1 where t1.bill_type=1` + where
- err := o.Raw(countSql).QueryRow(&reply.Total)
- if err != nil {
- l.Error("func",
- zap.String("call", "ChargeList"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- if reply.Total == 0 {
- reply.PageSize = PAGESIZE
- return nil
- }
- _, err = o.Raw(sql, PAGESIZE, req.PageNumber*PAGESIZE).QueryRows(&reply.List)
- if err != nil {
- l.Error("func",
- zap.String("call", "ChargeList"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- for index, _ := range reply.List {
- if reply.List[index].Remark != "" {
- json.Unmarshal([]byte(reply.List[index].Remark), &reply.List[index].RemarkList)
- }
- }
- reply.PageSize = PAGESIZE
- reply.PageNumber = req.PageNumber + 1
- return nil
- }
|