// 生成会员账户人工单据 func (this *memberService) NewBalanceTicket(merchantId int, memberId int, kind int, tit string, amount float32) (string, error) { var err error var tradeNo string if amount == 0 { return "", member.ErrIncorrectAmount } m := this._rep.GetMember(memberId) if m == nil { return "", member.ErrNoSuchMember } acc := m.GetAccount() var tit2 string if kind == member.KindBalancePresent { tradeNo = domain.NewTradeNo(merchantId) if amount > 0 { //增加奖金 tit2 = "[KF]客服调整-" + variable.AliasPresentAccount if len(tit) > 0 { tit2 = tit2 + "(" + tit + ")" } err = acc.PresentBalance(tit2, tradeNo, amount) } else { //扣减奖金 tit2 = "[KF]客服扣减-" + variable.AliasPresentAccount if len(tit) > 0 { tit2 = tit2 + "(" + tit + ")" } err = acc.DiscountPresent(tit2, tradeNo, -amount, false) } } if kind == member.KindBalanceCharge { tradeNo = domain.NewTradeNo(merchantId) if amount > 0 { tit2 = "[KF]客服充值卡" if len(tit) > 0 { tit2 = tit2 + "(" + tit + ")" } err = acc.ChargeBalance(member.TypeBalanceServiceCharge, tit2, tradeNo, amount) } else { tit2 = "[KF]客服扣减" if len(tit) > 0 { tit2 = tit2 + "(" + tit + ")" } err = acc.DiscountBalance(tit2, tradeNo, -amount) } } return tradeNo, err }
// 转入(业务放在service,是为person_finance解耦) func (this *personFinanceService) RiseTransferIn(personId int, transferWith personfinance.TransferWith, amount float32) (err error) { pf := this._rep.GetPersonFinance(personId) r := pf.GetRiseInfo() if amount < personfinance.RiseMinTransferInAmount { //金额不足最低转入金额 return errors.New(fmt.Sprintf(personfinance.ErrLessThanMinTransferIn.Error(), format.FormatFloat(personfinance.RiseMinTransferInAmount))) } m := this._accRep.GetMember(personId) if m == nil { return member.ErrNoSuchMember } acc := m.GetAccount() if transferWith == personfinance.TransferFromWithBalance { //从余额转入 if err = acc.DiscountBalance("理财转入", domain.NewTradeNo(10000), amount); err != nil { return err } if err = r.TransferIn(amount, transferWith); err != nil { //转入 return err } return pf.SyncToAccount() //同步到会员账户 } if transferWith == personfinance.TransferFromWithPresent { //从奖金转入 if err := acc.DiscountPresent("理财转入", domain.NewTradeNo(10000), amount, true); err != nil { return err } if err = r.TransferIn(amount, transferWith); err != nil { //转入 return err } return pf.SyncToAccount() //同步到会员账户 } return errors.New("暂时无法提供服务") }
// 请求提现,返回info_id,交易号及错误 func (this *accountImpl) RequestApplyCash(applyType int, title string, amount float32, commission float32) (int, string, error) { if amount <= 0 { return 0, "", member.ErrIncorrectAmount } if this._value.PresentBalance < amount { return 0, "", member.ErrOutOfBalance } tradeNo := domain.NewTradeNo(00000) csnAmount := amount * commission finalAmount := amount - csnAmount if finalAmount > 0 { finalAmount = -finalAmount } v := &member.BalanceInfo{ Kind: member.KindBalanceApplyCash, Type: applyType, Title: title, TradeNo: tradeNo, Amount: finalAmount, CsnAmount: csnAmount, State: member.StateApplySubmitted, } // 提现至余额 if applyType == member.TypeApplyCashToCharge { this._value.Balance += amount v.State = member.StateApplyOver } id, err := this.SaveBalanceInfo(v) if err == nil { this._value.PresentBalance -= amount _, err = this.Save() } return id, tradeNo, err }
// 转出 func (this *personFinanceService) RiseTransferOut(personId int, transferWith personfinance.TransferWith, amount float32) (err error) { pf := this._rep.GetPersonFinance(personId) r := pf.GetRiseInfo() m := this._accRep.GetMember(personId) if m == nil { return member.ErrNoSuchMember } acc := m.GetAccount() if transferWith == personfinance.TransferOutWithBalance { //转入余额 if err = r.TransferOut(amount, transferWith, personfinance.RiseStateOk); err == nil { err = acc.ChargeBalance(member.TypeBalanceServiceCharge, "理财转出", domain.NewTradeNo(10000), amount) if err != nil { log.Println("[ TransferOut][ Error]:", err.Error()) } err = pf.SyncToAccount() } return err } if transferWith == personfinance.TransferOutWithBank { if b := m.Profile().GetBank(); !b.Right() || !b.Locked() { return member.ErrNoSuchBankInfo } if err = r.TransferOut(amount, transferWith, personfinance.RiseStateOk); err == nil { err = pf.SyncToAccount() } return err } return errors.New("暂时无法提供服务") }