互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.5 KiB

package models
import (
"hudongzhuanjia/logger"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
// 用户操作, 主从账号同步信息
// 拔河/摇红包/摇奖券/订单/上墙/霸屏/抽奖/投票/竞拍/打赏/会务
type CustomerOperation struct {
Id int64 `json:"id"`
CustomerId int64 `json:"customer_id" description:"客户id"`
ActivityId int64 `json:"activity_id" description:"主活动id"`
AreaId int64 `json:"area_id" description:"地区id"`
ModuleActivityId int64 `json:"module_activity_id" description:"具体活动id"`
ModuleActivityType string `json:"module_activity_type" description:"具体活动类型"`
Operation string `json:"operation" description:"操作内容"`
OtherData interface{} `json:"other_data" xorm:"-" description:"额外的字段"`
ExtraData string `json:"-" xorm:"text" description:"额外信息"`
IsDelete bool `json:"is_delete" xorm:"default(0)"`
CreatedAt time.Time `json:"created_at" xorm:"created"`
UpdatedAt time.Time `json:"updated_at" xorm:"updated"`
}
func (op *CustomerOperation) SaveCustomerOperation() int64 {
row, err := core.GetXormAuto().InsertOne(op)
if err != nil {
logger.Error("customer operation insert failed. error: %v; content: %s", err, op.ExtraData)
return 0
}
return row
}
func (op *CustomerOperation) GetOpsByCustomerId(customerId int64, areaId int64) []*CustomerOperation {
ops := make([]*CustomerOperation, 0)
var err error
if areaId == 0 {
err = core.GetXormAuto().Where("customer_id=?", customerId).OrderBy("created_at desc").Find(&ops)
} else {
err = core.GetXormAuto().Where("customer_id=? and area_id=?", customerId, areaId).OrderBy("created_at asc").Find(&ops)
}
if err != nil {
logger.Error("customer_operation find failed. error: %v", err)
return nil
}
return ops
}
func (op *CustomerOperation) GetOpByCustomerId(customerId int64) (bool, error) {
return core.GetXormAuto().Where("customer_id=? and is_delete=0", customerId).OrderBy("created_at desc").Get(op)
}
func (op *CustomerOperation) GetOpByActivityId(activityId int64) (bool, error) {
return core.GetXormAuto().Where("activity_id=? and is_delete=0", activityId).OrderBy("created_at desc").Get(op)
}
func (op *CustomerOperation) GetOpByCustomerIdAndActivityId(pid, activityId int64) (bool, error) {
return core.GetXormAuto().Where("customer_id=? and activity_id=?", pid, activityId).OrderBy("created_at desc").Get(op)
}