| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package settle_account_bill
- import (
- "dashoo.cn/micro_libary/request"
- "errors"
- "fmt"
- "github.com/gogf/gf/os/gtime"
- "github.com/gogf/gf/util/gconv"
- "lims_adapter/dao/account"
- "lims_adapter/model"
- accountModel "lims_adapter/model/account"
- )
- // Service 会议室服务
- type Service struct {
- Dao *account.SettleAccountBillDao
- Tenant string
- }
- // NewSrv 服务初始化
- func NewService(tenant string) Service {
- return Service{Dao: account.NewSettleAccountBillDao(tenant), Tenant: tenant}
- }
- // List 会议室列表
- func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountBill, int, error) {
- entityModel := s.Dao.M
- where := "1=1"
- if req.Entity != nil {
- entity := new(accountModel.SettleAccountBillReq)
- err := gconv.Struct(req.Entity, entity)
- if err != nil {
- return nil, 0, err
- }
- if entity.MainUserId != 0 {
- where += fmt.Sprintf(" AND MainUserId='%v'", entity.MainUserId)
- }
- if entity.Status != "" {
- where += fmt.Sprintf(" AND Status='%v'", entity.Status)
- }
- }
- entityModel = entityModel.Where(where)
- total, err := entityModel.Count()
- if err != nil {
- return nil, 0, err
- }
- if total == 0 {
- return nil, 0, nil
- }
- res, err := entityModel.Page(req.Current, req.Size).Order("settle_account_bill.CreateOn DESC").Fields("settle_account_bill.*").FindAll()
- if err != nil {
- return nil, 0, err
- }
- if res.IsEmpty() {
- return nil, 0, nil
- }
- list := make([]accountModel.SettleAccountBill, 0)
- err = res.Structs(&list)
- if err != nil {
- return nil, 0, err
- }
- return list, total, nil
- }
- // 结算
- func (s Service) Settle(req accountModel.AccountBillSettleReq, user request.UserInfo) error {
- if req.BillId == 0 || req.Amount == 0 {
- return errors.New("参数缺失")
- }
- tx, err := s.Dao.DB.Begin()
- if err != nil {
- return err
- }
-
- _, err = tx.Update("settle_account_bill", fmt.Sprintf("Status='2',SettleUserId='%v',SettleUser='%v',SettleDate='%v'", user.Id, user.RealName, gtime.Now()), fmt.Sprintf("Id='%v'", req.BillId))
- if err != nil {
- tx.Rollback()
- return err
- }
- _, err = tx.Update("base_account", fmt.Sprintf("Surplus=Surplus-%v", req.Amount), fmt.Sprintf("Id='%v'", req.Amount))
- if err != nil {
- tx.Rollback()
- return err
- }
- return tx.Commit()
- }
- // 结算
- func (s Service) GenerateBill() error {
- return nil
- }
|