|
|
@@ -2,13 +2,9 @@ package account
|
|
|
|
|
|
import (
|
|
|
"dashoo.cn/micro_libary/request"
|
|
|
- "database/sql"
|
|
|
- "errors"
|
|
|
- "github.com/gogf/gf/frame/g"
|
|
|
+ "fmt"
|
|
|
"github.com/gogf/gf/os/gtime"
|
|
|
- "github.com/gogf/gf/util/gconv"
|
|
|
dao "lims_adapter/dao/account"
|
|
|
- "lims_adapter/model"
|
|
|
account "lims_adapter/model/account"
|
|
|
"strconv"
|
|
|
)
|
|
|
@@ -24,176 +20,50 @@ type AccountService struct {
|
|
|
Tenant string
|
|
|
}
|
|
|
|
|
|
-// NewSrv 服务初始化
|
|
|
-func NewSrv(tenant string) Service {
|
|
|
- return Service{Dao: dao.NewSettleAccountMainDao(tenant), Tenant: tenant}
|
|
|
-}
|
|
|
-
|
|
|
func NewAccountSrv(tenant string) AccountService {
|
|
|
return AccountService{Dao: dao.NewBaseAccountDao(tenant), Tenant: tenant}
|
|
|
}
|
|
|
|
|
|
-// 结算明细分页 代码已弃用
|
|
|
-func (s Service) SettleAccountList(req model.ListReq, info request.UserInfo) ([]account.SettleAccountMain, int, error) {
|
|
|
- entityModel := s.Dao.DB.Model("settle_account_main s").
|
|
|
- LeftJoin("appointment a", "s.AppointId = a.Id").
|
|
|
- LeftJoin("Instrument i").
|
|
|
- Fields("s.Id, s.BillId, s.AppointUser, s.MainUser, s.FeeType, s.TotalPrice, ").
|
|
|
- Where("MainUserId = ?", info.Id)
|
|
|
- if req.Entity != nil {
|
|
|
- entity := new(account.SettleAccountMainReq)
|
|
|
- gconv.Struct(req.Entity, entity)
|
|
|
- //if strconv.Itoa(entity.AppointUserId) != "" {
|
|
|
- // entityModel = entityModel.WhereLike(s.Dao.Columns.AppointUserId, "%"+strconv.Itoa(entity.AppointUserId)+"%")
|
|
|
- //}
|
|
|
- //if strconv.Itoa(entity.RelevanceId) != "" {
|
|
|
- // entityModel = entityModel.WhereLike("RelevanceId", "%"+strconv.Itoa(entity.RelevanceId)+"%")
|
|
|
- //}
|
|
|
- }
|
|
|
- total, err := entityModel.Count()
|
|
|
- if err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- if total == 0 {
|
|
|
- return nil, 0, nil
|
|
|
- }
|
|
|
- return nil, 0, nil
|
|
|
- res, err := entityModel.Page(req.Current, req.Size).FindAll()
|
|
|
- if err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- list := make([]account.SettleAccountMain, 0)
|
|
|
- res.Structs(&list)
|
|
|
- return list, total, nil
|
|
|
-}
|
|
|
-
|
|
|
-// 新增结算明细主表、明细子表 代码已弃用
|
|
|
-func (s Service) AddCountMainDetail(mobAppoint account.AppointInfoReq) error {
|
|
|
- contractBreach := 1.0
|
|
|
- paymentType := 1
|
|
|
- // TODO 如果是已取消预约,则计算违约费用
|
|
|
- if mobAppoint.Appointment.Appoint.Status == 4 {
|
|
|
- contractBreachEntity := model.ContractBreach{}
|
|
|
- // 计算取消时间与实验开始时间差,选择相应违约规则
|
|
|
- startTime := mobAppoint.Appointment.Appoint.StartTime
|
|
|
- cancelTime := mobAppoint.Appointment.Appoint.UpdateAt
|
|
|
- totalMinute := (startTime.Hour()-cancelTime.Hour())*60 + (startTime.Minute() - cancelTime.Minute())
|
|
|
- if err := s.Dao.DB.Model("contract_breach").
|
|
|
- Where("MinPoint <= ? and MaxPoint >= ?", totalMinute, totalMinute).Scan(&contractBreachEntity); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- contractBreach = contractBreachEntity.Persent
|
|
|
- paymentType = 2
|
|
|
- }
|
|
|
- // 通过设备、用户查询优惠状态
|
|
|
- var result account.AppointInfo
|
|
|
- isDiscount := false
|
|
|
- err := s.Dao.DB.Model("base_equipment_qualification").Fields("Qualification as IsPreferential").
|
|
|
- Where("EquipmentId = " + strconv.Itoa(mobAppoint.Appointment.Instr.Id) + " and Qualification = 3 " +
|
|
|
- " and UserId = " + strconv.Itoa(mobAppoint.Appointment.User.Id)).Scan(&result.User)
|
|
|
- // 如果没有数据,则没有权限
|
|
|
- if err == sql.ErrNoRows {
|
|
|
- // TODO
|
|
|
- } else {
|
|
|
- if result.User.IsPreferential == "3" {
|
|
|
- isDiscount = true
|
|
|
- }
|
|
|
- }
|
|
|
- // 计算实际实验时长、费用,目前为一条明细子表数据,后期可能扩展为多条数据子表数据
|
|
|
- totalMinutes := 0.0
|
|
|
- //signInTime := mobAppoint.Appointment.Appoint.SignInTime
|
|
|
- //hour := mobAppoint.SignOutTime.Hour() - signInTime.Hour()
|
|
|
- //minute := mobAppoint.SignOutTime.Minute() - signInTime.Minute()
|
|
|
- //totalMinute += hour * 60 + minute
|
|
|
- totalMinutes += mobAppoint.Appointment.Appoint.RealityUseDuration * 60
|
|
|
- unitCount := float64(mobAppoint.Appointment.Instr.UnitCount)
|
|
|
- // 有优惠权,则按照优惠计费
|
|
|
- if isDiscount {
|
|
|
- unitCount = unitCount * float64(mobAppoint.Appointment.Instr.UnitCount) / 100
|
|
|
- }
|
|
|
- totalPrice := totalMinutes / 60 * unitCount
|
|
|
-
|
|
|
- // 生成结算明细主表
|
|
|
+// AddAccount 添加财务账号
|
|
|
+func (s AccountService) Save(req *account.BaseAccount, user request.UserInfo) error {
|
|
|
now := gtime.Now()
|
|
|
- var mainEntity = g.Map{
|
|
|
- "AppointId": mobAppoint.Appointment.Appoint.Id,
|
|
|
- "AppointUserId": mobAppoint.Appointment.User.Id,
|
|
|
- "AppointUser": mobAppoint.Appointment.User.Realname,
|
|
|
- "SettleStatus": 1,
|
|
|
- "TotalPrice": totalPrice * contractBreach,
|
|
|
- "CreateUserId": mobAppoint.Appointment.User.Id,
|
|
|
- "CreateBy": mobAppoint.Appointment.User.Realname,
|
|
|
- "CreateOn": now,
|
|
|
- }
|
|
|
- id, err := s.Dao.DB.Model("settle_account_main").InsertAndGetId(mainEntity)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- } else {
|
|
|
- // 生成结算明细子表
|
|
|
- // TODO 判断正常支出或是违约
|
|
|
- var detailEntity = g.Map{
|
|
|
- "pid": id,
|
|
|
- "UnitPrice": unitCount,
|
|
|
- "Minutes": totalMinutes,
|
|
|
- "PaymentType": paymentType,
|
|
|
- "PaymentAccount": totalPrice * contractBreach,
|
|
|
- "CreateUserId": mobAppoint.Appointment.User.Id,
|
|
|
- "CreateBy": mobAppoint.Appointment.User.Realname,
|
|
|
- "CreateOn": now,
|
|
|
- }
|
|
|
- _, err := s.Dao.DB.Model("settle_account_detail").Insert(detailEntity)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
+ if req.Id == 0 {
|
|
|
+ req.CreateUserId = int(user.Id)
|
|
|
+ req.CreateBy = user.RealName
|
|
|
+ req.CreateOn = now
|
|
|
+ }
|
|
|
+ req.UpdateUserId = int(user.Id)
|
|
|
+ req.UpdateBy = user.RealName
|
|
|
+ req.UpdateOn = now
|
|
|
|
|
|
-// AddAccount 添加财务账号
|
|
|
-func (s Service) AddAccount(req *account.BaseAccount) error {
|
|
|
- count, err := s.Dao.DB.Model("base_account").Where("Account = ?", req.Account).Count()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- if count > 0 {
|
|
|
- return errors.New("该账号已存在,请重新输入!")
|
|
|
- }
|
|
|
- _, err = s.Dao.DB.Model("base_account").Insert(req)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- return nil
|
|
|
+ _, err := s.Dao.Save(req)
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
// AccountList 财务账号分页查询
|
|
|
-func (s Service) AccountList(req *account.AccountReq) (infos account.BaseAccountRsp, err error) {
|
|
|
+func (s AccountService) AccountList(req *account.AccountReq) (infos account.BaseAccountRsp, err error) {
|
|
|
current := req.PageNun
|
|
|
size := req.PageSize
|
|
|
- model := s.Dao.DB.Model("base_account a").
|
|
|
- LeftJoin("user_account_bind b", "a.Id = b.AccountId").
|
|
|
- LeftJoin("base_user c", "b.UserId = c.Id")
|
|
|
+ model := s.Dao.DB.Model("base_account a")
|
|
|
if req.Account != "" {
|
|
|
- model = model.WhereLike("Account", req.Account)
|
|
|
+ model = model.WhereLike("Account", "%" + req.Account + "%")
|
|
|
}
|
|
|
if req.RealName != "" {
|
|
|
- model = model.WhereLike("RealName", req.RealName)
|
|
|
+ model = model.WhereLike("MainUser", "%" + req.RealName + "%")
|
|
|
}
|
|
|
if req.AccountName != "" {
|
|
|
- model = model.Where("AccountName", req.AccountName)
|
|
|
+ model = model.WhereLike("AccountName", "%" + req.AccountName + "%")
|
|
|
}
|
|
|
infos.Total, err = model.Count()
|
|
|
if err != nil {
|
|
|
return infos, err
|
|
|
}
|
|
|
- err = model.Fields("a.Id, a.Account,a.AccountName,A.Surplus,a.Available,a.Limit,a.Advance,c.Id UserId,c.RealName").Page(current, size).Scan(&infos.Records)
|
|
|
+ err = model.Fields("a.*").Page(current, size).Scan(&infos.Records)
|
|
|
return infos, nil
|
|
|
}
|
|
|
|
|
|
// DepositAccount 充值账户
|
|
|
func (s AccountService) DepositAccount(req *account.BaseAccountResp) error {
|
|
|
- _, err := s.Dao.M.Update("Surplus = "+strconv.Itoa(req.Surplus), "Id = "+strconv.Itoa(req.Id))
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- return nil
|
|
|
+ _, err := s.Dao.M.Update(fmt.Sprintf("Surplus='%v',Available='%v'", req.Surplus, req.Available), "Id = "+strconv.Itoa(req.Id))
|
|
|
+ return err
|
|
|
}
|