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.
95 lines
2.3 KiB
95 lines
2.3 KiB
package pc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/logger"
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/utils/code"
|
|
"hudongzhuanjia/utils/define"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type WsCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
// ws doc
|
|
func (t *WsCtl) Ops() {
|
|
customerId := t.GetAccountId()
|
|
activityId, _ := t.GetInt("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.MustGetInt("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")
|
|
}
|
|
|
|
func (t *WsCtl) CheckToken() {
|
|
token := t.MustGet("token")
|
|
tokens := strings.SplitN(token, ":", 2)
|
|
if tokens[0] == define.TYPE_USER { // h5用户
|
|
user := &models.User{}
|
|
err := user.GetByToken(tokens[1])
|
|
t.CheckErr(err)
|
|
t.AccountId = user.Id
|
|
t.AccountType = tokens[0]
|
|
} else if tokens[0] == define.TYPE_CUSTOMER { // 客户
|
|
customer := &models.Customer{}
|
|
err := customer.GetByToken(tokens[1])
|
|
t.CheckErr(err)
|
|
t.AccountId = customer.Id
|
|
t.AccountType = tokens[0]
|
|
} else if tokens[0] == define.TYPE_ENTRYPEOPLE { // 录入人员
|
|
entry := &models.OrderEntryPerson{}
|
|
err := entry.GetByToken(tokens[1])
|
|
t.CheckErr(err)
|
|
t.AccountId = entry.Id
|
|
t.AccountType = tokens[0]
|
|
} else {
|
|
t.ERROR("token失效", code.MSG_ERR_Authority)
|
|
}
|
|
t.JSON(map[string]interface{}{
|
|
"account_id": t.AccountId,
|
|
"account_type": t.AccountType,
|
|
})
|
|
}
|