func coreAccountTransfer(args map[string]interface{}, result *Result) {
	payerid := args["payerid"].(float64)
	payeeid := args["payeeid"].(float64)
	amount := args["amount"].(float64)
	t, err := account.NewTransfer(int64(payerid), int64(payeeid), int64(amount))
	if err != nil {
		result.Res = 0
		result.Error = fmt.Sprintf("%v", err)
		result.Time = time.Now().Unix()
	} else {
		result.Res = 1
		result.Data = map[string]int64{"id": t.Id}
		result.Time = time.Now().Unix()
	}
}
func (r *Receivables) Create() error {
	if r.Id > 0 {
		return setError("已经存在此收款信息")
	}

	ins, err := doDb.Prepare("INSERT INTO " + mysql.PreTable + "receivables SET " +
		"transfer_id=?, " +
		"payee_account_id=?, " +
		"payer_account_id=?, " +
		"amount=?, " +
		"type=?, " +
		"status=?, " +
		"currency=?, " +
		"enabled=?, " +
		"create_time=?, " +
		"update_time=?")
	if err != nil {
		return err
	}

	now := time.Now().Unix()
	r.CreateTime = now
	r.UpdateTime = now
	res, err := ins.Exec(
		r.TransferId,
		r.PayeeAccountId,
		r.PayerAccountId,
		r.Amount,
		r.Type,
		r.Status,
		r.Currency,
		r.Enabled,
		r.CreateTime,
		r.UpdateTime,
	)
	if err != nil {
		return err
	}

	rid, err := res.LastInsertId()
	r.Id = rid
	rl := &ReceivablesLog{
		ReceivablesId: r.Id,
		Amount:        r.Amount,
		TypeCode:      r.Type,
		Type:          "",
		StatusCode:    r.Status,
		Status:        "成功",
		CurrencyCode:  r.Currency,
		Currency:      "人民币",
		Memo:          "新建:",
	}

	_, err = rl.Create()
	if err != nil {
		return err
	} else {
		r.Enabled = 1
		_, err := r.Update()
		if err != nil {
			return err
		}
	}

	t := &Transaction{
		TriggerId:      r.Id,
		PayerAccountId: r.PayerAccountId,
		PayeeAccountId: r.PayeeAccountId,
		Method:         2,
		PayMethod:      1,
		Amount:         r.Amount,
		Type:           r.Type,
		Status:         r.Status,
		SettleMethod:   1,
		SettleStatus:   1,
		StartTime:      now,
		EndTime:        (now + 7*24*60*60),
	}

	err = t.Create()

	if err != nil {
		return err
	}

	transfer, err := account.NewTransfer(r.PayerAccountId, r.PayeeAccountId, r.Amount)
	if err != nil {
		return err
	}

	r.TransferId = transfer.Id
	_, err = r.Update()
	if err != nil {
		return err
	}

	return nil
}
示例#3
0
func (p *Payment) Create() error {
	if p.Id > 0 {
		return setError("已经存在此付款信息")
	}

	ins, err := doDb.Prepare("INSERT INTO " + mysql.PreTable + "payment SET " +
		"transfer_id=?, " +
		"payer_account_id=?, " +
		"payee_account_id=?, " +
		"amount=?, " +
		"type=?, " +
		"status=?, " +
		"currency=?, " +
		"enabled=?, " +
		"create_time=?, " +
		"update_time=?")
	if err != nil {
		return err
	}

	now := time.Now().Unix()
	p.CreateTime = now
	p.UpdateTime = now
	res, err := ins.Exec(
		p.TransferId,
		p.PayerAccountId,
		p.PayeeAccountId,
		p.Amount,
		p.Type,
		p.Status,
		p.Currency,
		p.Enabled,
		p.CreateTime,
		p.UpdateTime,
	)
	if err != nil {
		return err
	}

	pid, err := res.LastInsertId()
	p.Id = pid
	pl := &PaymentLog{
		PaymentId:    p.Id,
		Amount:       p.Amount,
		TypeCode:     p.Type,
		Type:         "",
		StatusCode:   p.Status,
		Status:       "成功",
		CurrencyCode: p.Currency,
		Currency:     "人民币",
		Memo:         "新建:",
	}

	_, err = pl.Create()
	if err != nil {
		return err
	} else {
		p.Enabled = 1
		_, err := p.Update()
		if err != nil {
			return err
		}
	}

	t := &Transaction{
		TriggerId:      p.Id,
		PayerAccountId: p.PayerAccountId,
		PayeeAccountId: p.PayeeAccountId,
		Method:         1,
		PayMethod:      1,
		Amount:         p.Amount,
		Type:           p.Type,
		Status:         p.Status,
		SettleMethod:   1,
		SettleStatus:   1,
		StartTime:      now,
		EndTime:        (now + 7*24*60*60),
	}

	err = t.Create()
	if err != nil {
		return err
	}

	transfer, err := account.NewTransfer(p.PayerAccountId, p.PayeeAccountId, p.Amount)
	if err != nil {
		return err
	}

	p.TransferId = transfer.Id
	_, err = p.Update()
	if err != nil {
		return err
	}

	return nil
}