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.
63 lines
1.4 KiB
63 lines
1.4 KiB
package pc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/logger"
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/utils/code"
|
|
"time"
|
|
)
|
|
|
|
type WsCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
// ws doc
|
|
func (t *WsCtl) Ops() {
|
|
customerId := t.MustGetUID()
|
|
activityId, _ := t.GetInt64("activity_id")
|
|
customer := new(models.Customer)
|
|
exist, err := models.Get(customer, customerId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
|
|
|
|
op := new(models.CustomerOperation)
|
|
if customer.Pid == 0 {
|
|
exist, err = op.GetOpByActivityId(activityId)
|
|
} else {
|
|
exist, err = op.GetOpByCustomerId(customer.Pid)
|
|
}
|
|
t.CheckErr(err)
|
|
if !exist {
|
|
t.JSON(map[string]interface{}{
|
|
"operations": []*models.CustomerOperation{},
|
|
})
|
|
}
|
|
|
|
var m = make(map[string]interface{})
|
|
err = json.Unmarshal([]byte(op.ExtraData), &m)
|
|
t.CheckErr(err)
|
|
|
|
op.OtherData = m
|
|
t.JSON(map[string]interface{}{
|
|
"operations": []*models.CustomerOperation{op},
|
|
})
|
|
}
|
|
|
|
// ws doc
|
|
func (t *WsCtl) SaveOp() {
|
|
customerId := t.MustGetInt64("customer_id")
|
|
extraData := t.Default("extra_data", "")
|
|
op := &models.CustomerOperation{
|
|
CustomerId: customerId,
|
|
ExtraData: extraData,
|
|
UpdatedAt: time.Now(),
|
|
CreatedAt: time.Now(),
|
|
}
|
|
if row := op.SaveCustomerOperation(); row != 1 {
|
|
logger.Error("save customer_operation出现错误")
|
|
t.ERROR("customer operation格式错误", code.MSG_ERR)
|
|
}
|
|
t.SUCCESS("success")
|
|
}
|