1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package logic
- import (
- "app.yhyue.com/moapp/jyResourcesCenter/entity"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/config"
- "context"
- "encoding/json"
- "time"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/svc"
- "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type EntAccountGivenLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewEntAccountGivenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EntAccountGivenLogic {
- return &EntAccountGivenLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // EntAccountGiven 权益分配
- func (l *EntAccountGivenLogic) EntAccountGiven(in *resourcesCenter.EntOperateReq) (*resourcesCenter.Response, error) {
- eCode, msg := func() (int64, string) {
- if config.ConfigJson.ProductMap[in.ResourceType] == nil || in.CompanyId == 0 || in.OperateAccountId == "" || in.EmpowerId == 0 {
- return entity.ErrorCode, "参数异常"
- }
- waitBalance := &entity.Balance{} //等待分配的数量
- orm := entity.Engine.NewSession()
- _, err := orm.Table(AccountResources).Where("companyId=? AND resourceType=? AND empowerId=? AND number>0 AND endTime>= ? AND accountId like 'wait_%'", in.CompanyId, in.ResourceType, in.EmpowerId, time.Now().Format("2006-01-02")).OrderBy("id asc").Limit(1).Get(waitBalance)
- if err != nil || waitBalance == nil || waitBalance.Id == 0 {
- return entity.ErrorCode, "账户查询异常"
- }
- if err = orm.Begin(); err != nil {
- return entity.ErrorCode, "数据库操作异常"
- }
- updateNumb, err := orm.Table(AccountResources).Cols("accountId").
- Where(" id=?", waitBalance.Id).
- Update(&map[string]interface{}{
- "accountId": in.OperateAccountId,
- })
- if err != nil || updateNumb <= 0 {
- _ = orm.Rollback()
- return entity.ErrorCode, "权益分配异常"
- }
- jsonData, _ := json.Marshal(map[string]interface{}{"describe": "权益分配", "source": waitBalance.AccountId})
- updateNumb, err = orm.Table(ConsumeRecord).Insert(entity.Detailed{
- AccountId: in.OperateAccountId,
- CompanyId: waitBalance.CompanyId,
- EmpowerId: in.EmpowerId,
- ResourceType: waitBalance.ResourceType,
- Number: waitBalance.Number,
- CreateTime: time.Now().Local(),
- UserType: 6,
- Remarks: string(jsonData),
- UserId: in.OperateAccountId,
- Name: waitBalance.Name,
- })
- if err != nil || updateNumb <= 0 {
- _ = orm.Rollback()
- return entity.ErrorCode, "新增流水异常"
- }
- _ = orm.Commit()
- return entity.SuccessCode, "操作成功"
- }()
- return &resourcesCenter.Response{
- Code: eCode,
- Message: msg,
- }, nil
- }
|