|
|
@@ -0,0 +1,119 @@
|
|
|
+package summary_model
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "fohow.com/apps/models/order_model"
|
|
|
+
|
|
|
+ // "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "fohow.com/cache"
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "github.com/astaxie/beego/orm"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ user_perfomances_tablename = "user_perfomances"
|
|
|
+)
|
|
|
+
|
|
|
+type UserPerfomance struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ WxUserId int64 `orm:"column(wx_user_id);null" 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
|
|
|
+ OrderPerfomance int64 `orm:"column(order_perfomance);null" json:"-"` // int(11)
|
|
|
+ ShopOrderPerfomance int64 `orm:"column(shop_order_perfomance);null" json:"-"` // int(11)
|
|
|
+ ShopPerfomance int64 `orm:"column(shop_perfomance);null" json:"-"` // int(11)
|
|
|
+ BalancePerfomance int64 `orm:"column(balance_perfomance);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 *UserPerfomance) TableName() string {
|
|
|
+ return user_perfomances_tablename
|
|
|
+}
|
|
|
+
|
|
|
+//获取检索条件
|
|
|
+func GetPerfomanceById(id int64, useCache bool) *UserPerfomance {
|
|
|
+ k := fmt.Sprintf("summary_model.GetStaticById.(%d)", id)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).(*UserPerfomance); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item := new(UserPerfomance)
|
|
|
+ if err := orm.NewOrm().QueryTable(item).Filter("id", id).One(item); err != nil {
|
|
|
+ beego.BeeLogger.Error("get perfomance by id=[%d] err=[%s]", id, err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ cache.Cache.Put(k, item, 5*time.Minute)
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
+func (self *UserPerfomance) Save() error {
|
|
|
+ if _, err := orm.NewOrm().Update(self); err != nil {
|
|
|
+ beego.BeeLogger.Error("Save perfomance id=[%d] .err=[%s]", self.Id, err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//获取某会员订单业绩
|
|
|
+func GetSumOrderPerfomance(wxUserId, orderType, beginTime, endTime int64) int64 {
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ Count int64
|
|
|
+ }
|
|
|
+ ret := &Ret{}
|
|
|
+ o := orm.NewOrm()
|
|
|
+ tbn := "orders"
|
|
|
+ sql := fmt.Sprintf("SELECT sum(`paied_price`-`freight`) as count FROM `%s` WHERE paied_at >? and paied_at<? and status in (?, ?, ?) ) and wx_user_id=? and order_type=?;", tbn)
|
|
|
+ err := o.Raw(sql, beginTime, endTime, order_model.STATUS_PROCESSING, order_model.STATUS_DISPATCH, order_model.STATUS_COMPLETE, wxUserId, orderType).QueryRow(ret)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("GetSumOrderPerfomance err=[%s]", err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret.Count
|
|
|
+}
|
|
|
+
|
|
|
+//获取某会员开店业绩
|
|
|
+func GetSumShopPerfomance(wxUserId, beginTime, endTime int64) int64 {
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ Count int64
|
|
|
+ }
|
|
|
+ ret := &Ret{}
|
|
|
+ o := orm.NewOrm()
|
|
|
+ tbn := "shop_applications"
|
|
|
+ sql := fmt.Sprintf("SELECT sum(`total`) as count FROM `%s` WHERE UNIX_TIMESTAMP(pass_time)>? and UNIX_TIMESTAMP(pass_time)<? and status=? and wx_user_id=? ;", tbn)
|
|
|
+ err := o.Raw(sql, beginTime, endTime, 1, wxUserId).QueryRow(ret)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("GetSumShopPerfomance err=[%s]", err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret.Count
|
|
|
+}
|
|
|
+
|
|
|
+//获取某会员充值订单业绩
|
|
|
+func GetSumBalancePerfomance(wxUserId, beginTime, endTime int64) int64 {
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ Count int64
|
|
|
+ }
|
|
|
+ ret := &Ret{}
|
|
|
+ o := orm.NewOrm()
|
|
|
+ tbn := "balance_orders"
|
|
|
+ sql := fmt.Sprintf("SELECT sum(`paied_price`) as count FROM `%s` WHERE paied_at>? and paied_at<? and status=? and wx_user_id=? ;", tbn)
|
|
|
+ err := o.Raw(sql, beginTime, endTime, 1, wxUserId).QueryRow(ret)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("GetSumBalancePerfomance err=[%s]", err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret.Count
|
|
|
+}
|