Exemplo n.º 1
0
// 获取最近的提现描述
func (this *memberService) GetLatestApplyCashText(memberId int) string {
	var latestInfo string
	latestApplyInfo := this.GetLatestApplyCash(memberId)
	if latestApplyInfo != nil {
		var sText string
		switch latestApplyInfo.State {
		case 0:
			sText = "已申请"
		case 1:
			sText = "已审核,等待打款"
		case 2:
			sText = "被退回"
		case 3:
			sText = "已完成"
		}
		if latestApplyInfo.Amount < 0 {
			latestApplyInfo.Amount = -latestApplyInfo.Amount
		}
		latestInfo = fmt.Sprintf(`<b>最近提现:</b>%s&nbsp;申请提现%s ,状态:<span class="status">%s</span>。`,
			time.Unix(latestApplyInfo.CreateTime, 0).Format("2006-01-02 15:04"),
			format.FormatFloat(latestApplyInfo.Amount),
			sText)
	}
	return latestInfo
}
Exemplo n.º 2
0
// 获取商品详情
func (this *saleService) GetGoodsDetails(mchId, goodsId, mLevel int) (*valueobject.Goods, map[string]string) {
	sl := this._rep.GetSale(mchId)
	var goods sale.IGoods = sl.GoodsManager().GetGoods(goodsId)
	gv := goods.GetPackedValue()
	proMap := goods.GetPromotionDescribe()
	if b, price := goods.GetLevelPrice(mLevel); b {
		gv.PromPrice = price
		proMap["会员专享"] = fmt.Sprintf("会员优惠,仅需<b>¥%s</b>",
			format.FormatFloat(price))
	}
	return gv, proMap
}
Exemplo n.º 3
0
func backCashForMember(m member.IMember, order *order.Order,
	fee int, refName string) error {
	//更新账户
	acc := m.GetAccount()
	acv := acc.GetValue()
	bFee := float32(fee)
	acv.PresentBalance += bFee // 更新赠送余额
	acv.TotalPresentFee += bFee
	acv.UpdateTime = time.Now().Unix()
	_, err := acc.Save()

	if err == nil {
		tit := fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s",
			format.FormatFloat(bFee), order.OrderNo, refName)
		err = acc.PresentBalance(tit, order.OrderNo, float32(fee))
	}
	return err
}
Exemplo n.º 4
0
// 解析模板中的参数
func compile(tpl string, param map[string]interface{}) string {
	var str string
	for k, v := range param {
		switch v.(type) {
		case string:
			str = v.(string)
		case int, int32, int64:
			str = strconv.Itoa(v.(int))
		case float32, float64:
			str = format.FormatFloat(v.(float32))
		case bool:
			str = strconv.FormatBool(v.(bool))
		default:
			str = "unknown"
		}
		tpl = strings.Replace(tpl, "{"+k+"}", str, -1)
	}
	return tpl
}
Exemplo n.º 5
0
// 转入(业务放在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("暂时无法提供服务")
}
Exemplo n.º 6
0
// 转入
func (this *riseInfo) TransferIn(amount float32,
	w personfinance.TransferWith) (err error) {
	if this._v == nil {
		//判断会员是否存在
		if _, err = this.Value(); err != nil {
			return err
		}
	}

	if amount <= 0 {
		return personfinance.ErrIncorrectAmount
	}

	if amount < personfinance.RiseMinTransferInAmount {
		return errors.New(fmt.Sprintf(personfinance.ErrLessThanMinTransferIn.Error(),
			format.FormatFloat(personfinance.RiseMinTransferInAmount)))
	}

	dt := time.Now()
	this._v.TransferIn += amount
	this._v.TotalAmount += amount
	this._v.UpdateTime = dt.Unix()
	if err = this.Save(); err == nil {
		//保存并记录日志
		_, err = this._rep.SaveRiseLog(&personfinance.RiseLog{
			PersonId:     this.GetDomainId(),
			Title:        "[转入]从" + personfinance.TransferInWithText(w) + "转入",
			Amount:       amount,
			Type:         personfinance.RiseTypeTransferIn,
			TransferWith: int(w),
			State:        personfinance.RiseStateDefault,
			UnixDate:     tool.GetStartDate(dt).Unix(),
			LogTime:      this._v.UpdateTime,
			UpdateTime:   this._v.UpdateTime,
		})
	}
	return err
}
Exemplo n.º 7
0
// 转出,w为转出方式(如银行,余额等),state为日志的状态,某些操作
// 需要确认,有些不需要.通过state来传入
func (this *riseInfo) TransferOut(amount float32,
	w personfinance.TransferWith, state int) (err error) {
	if this._v == nil {
		//判断会员是否存在
		if _, err = this.Value(); err != nil {
			return err
		}
	}
	if amount <= 0 {
		return personfinance.ErrIncorrectAmount
	}

	if amount > this._v.Balance {
		//超出账户金额
		return personfinance.ErrOutOfBalance
	}

	// 低于最低转出金额,且不是全部转出.返回错误. 若转出到余额则无限制
	if amount != this._v.Balance && //非全部转出
		w != personfinance.TransferOutWithBalance && //非转出余额
		amount < personfinance.RiseMinTransferOutAmount {
		if this._v.Balance > personfinance.RiseMinTransferOutAmount {
			//金额大于转出金额
			return errors.New(fmt.Sprintf(personfinance.ErrLessThanMinTransferOut.Error(),
				format.FormatFloat(personfinance.RiseMinTransferOutAmount)))
		} else {
			//金额小于转出金额
			return errors.New(fmt.Sprintf(personfinance.ErrMustAllTransferOut.Error(),
				format.FormatFloat(personfinance.RiseMinTransferOutAmount)))
		}
	}

	dt := time.Now()
	this._v.UpdateTime = dt.Unix()
	this._v.Balance -= amount
	this._v.SettlementAmount -= amount

	if this._v.SettlementAmount < 0 {
		//提现超出结算金额
		this._v.SettlementAmount = 0
	}

	if this._v.Balance == 0 {
		//若全部提出,则理财收益和结算金额清零
		this._v.Rise = 0
		this._v.SettlementAmount = 0
	}

	if err = this.Save(); err == nil {
		//保存并记录日志
		_, err = this._rep.SaveRiseLog(&personfinance.RiseLog{
			PersonId:     this.GetDomainId(),
			Title:        "[转出]转出到" + personfinance.TransferOutWithText(w),
			Amount:       amount,
			Type:         personfinance.RiseTypeTransferOut,
			TransferWith: int(w),
			State:        state,
			UnixDate:     tool.GetStartDate(dt).Unix(),
			LogTime:      this._v.UpdateTime,
			UpdateTime:   this._v.UpdateTime,
		})
	}
	//todo: 新增操作记录,如审核,打款,完成等
	return err
}