|
|
@@ -0,0 +1,97 @@
|
|
|
+package order_static_model
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ // "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "fohow.com/cache"
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "github.com/astaxie/beego/orm"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ order_statics_tablename = "order_statics"
|
|
|
+ order_static_details_tablename = "order_static_details"
|
|
|
+)
|
|
|
+
|
|
|
+type OrderStatic struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ BeginDate time.Time `orm:"column(begin_date);null;type(datetime)" json:"-"` // datetime
|
|
|
+ EndDate time.Time `orm:"column(end_date);null;type(datetime)" json:"-"` // datetime
|
|
|
+ State string `orm:"column(state);null" json:"-"` // tinyint(1)
|
|
|
+ IsSend bool `orm:"column(is_send);null" json:"-"` // tinyint(1)
|
|
|
+ CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
+ UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)" json:"-"` // datetime
|
|
|
+}
|
|
|
+
|
|
|
+type OrderStaticDetail struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ StaticId int64 `orm:"column(static_id)" json:"-"` // int(11)
|
|
|
+ BeginDate time.Time `orm:"column(begin_date);null;type(datetime)" json:"-"` // datetime
|
|
|
+ EndDate time.Time `orm:"column(end_date);null;type(datetime)" json:"-"` // datetime
|
|
|
+ State string `orm:"column(state);null" json:"-"` // tinyint(1)
|
|
|
+ IsSend bool `orm:"column(is_send);null" json:"-"` // tinyint(1)
|
|
|
+ ProductId int64 `orm:"column(product_id);null" json:"-"` // int(11)
|
|
|
+ ProductName string `orm:"column(product_name);null" json:"-"` // tinyint(1)
|
|
|
+ Nums int64 `orm:"column(nums);null" json:"-"` // int(11)
|
|
|
+ Total int64 `orm:"column(total);null" json:"-"` // int(11)
|
|
|
+ CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
+ UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)" json:"-"` // datetime
|
|
|
+}
|
|
|
+
|
|
|
+func (self *OrderStaticDetail) TableName() string {
|
|
|
+ return order_static_details_tablename
|
|
|
+}
|
|
|
+
|
|
|
+func (self *OrderStatic) TableName() string {
|
|
|
+ return order_statics_tablename
|
|
|
+}
|
|
|
+
|
|
|
+//获取检索条件
|
|
|
+func GetStaticById(id int64, useCache bool) *OrderStatic {
|
|
|
+ k := fmt.Sprintf("order_static_model.GetStaticById.(%d)", id)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).(*OrderStatic); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item := new(OrderStatic)
|
|
|
+ if err := orm.NewOrm().QueryTable(item).Filter("id", id).One(item); err != nil {
|
|
|
+ beego.BeeLogger.Error("get static by id=[%d] err=[%s]", id, err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ cache.Cache.Put(k, item, 5*time.Minute)
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
+//创建订单
|
|
|
+func (self *OrderStaticDetail) Create(staticId, pid, totalPrice, nums int64, pdName, state string, isSend bool, bDate, eDate time.Time) *OrderStaticDetail {
|
|
|
+ staticDetail := &OrderStaticDetail{
|
|
|
+ StaticId: staticId,
|
|
|
+ BeginDate: bDate,
|
|
|
+ EndDate: eDate,
|
|
|
+ State: state,
|
|
|
+ IsSend: isSend,
|
|
|
+ ProductId: pid,
|
|
|
+ ProductName: pdName,
|
|
|
+ Nums: nums,
|
|
|
+ Total: totalPrice,
|
|
|
+ }
|
|
|
+ id, err := orm.NewOrm().Insert(staticDetail)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("insert order static detail err=[%s]", err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ staticDetail.Id = id
|
|
|
+ return staticDetail
|
|
|
+}
|
|
|
+
|
|
|
+func (self *OrderStaticDetail) Save() error {
|
|
|
+ if _, err := orm.NewOrm().Update(self); err != nil {
|
|
|
+ beego.BeeLogger.Error("SaveOrderStaticDetail id=[%d] .err=[%s]", self.Id, err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|