package Account

import (
	"FollowUp_Notice/lib"
	"FollowUp_Notice/logs"
	"fmt"
	"github.com/beego/beego/v2/adapter/orm"
	"time"
)

// 用户支付订单
type UserPayOrder struct {
	Id         int       `orm:"column(ID);size(11);auto;pk"`
	T_uid      int       `orm:"index;size(256);"`                                      // User.Id
	T_type     string    `orm:"size(256)"`                                             // 微信
	T_title    string    `orm:"type(text)"`                                            // 标题
	T_total    float64   `orm:"digits(12);decimals(2)"`                                // 金额
	T_order_no string    `orm:"size(256)"`                                             // 支付订单
	T_status   string    `orm:"size(256)"`                                             // 支付状态
	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
}

func (t *UserPayOrder) TableName() string {
	return "user_pay_order" // 数据库名称   // ************** 替换 DesignDeviceNotice **************
}

func init() {
	//注册模型
	orm.RegisterModel(new(UserPayOrder))
}

func Add_UserPayOrder(r UserPayOrder) (id int64, err error) {
	o := orm.NewOrm()
	id, err = o.Insert(&r)
	if err != nil {
		logs.Error(lib.FuncName(), err)
		return
	}
	return
}

// 修改
func Update_UserPayOrder(m UserPayOrder, cols ...string) error {
	o := orm.NewOrm()
	num, err := o.Update(&m, cols...)
	if err != nil {
		logs.Error(lib.FuncName(), err)
		return err
	}
	fmt.Println("Number of records updated in database:", num)
	return nil
}

// 获取 ByT_order_no
func Get_UserPayOrder_ByT_order_no(T_order_no string) (r UserPayOrder, err error) {
	o := orm.NewOrm()
	qs := o.QueryTable(new(UserPayOrder))
	err = qs.Filter("T_order_no", T_order_no).One(&r)
	if err != nil {
		logs.Error(lib.FuncName(), err)
	}
	return
}
