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.
|
|
package pc
import ( "encoding/json" "hudongzhuanjia/controllers" "hudongzhuanjia/logger" "hudongzhuanjia/models" "hudongzhuanjia/utils/code" "time" )
type WsCtl struct { controllers.AuthorCtl }
// ws doc
// @Summary ws
// @Description get current operation
// @Tags ws
// @Accept json
// @Produce json
// @Param activity_id query int true "Activity ID"
// @Success 0 {array} models.CustomerOperation
// @Failure 503 {string} string "参数不存在"
// @Failure 504 {object} string "用户不存在"
// @Router /Pc/WsCtl/ops [get]
func (t *WsCtl) Ops() { customerId := t.MustGetUID() activityId, _ := t.GetInt64("activity_id") customer := new(models.Customer) exist, err := models.GetById(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
// @Summary ws
// @Description save operation
// @Tags ws
// @Accept json
// @Produce json
// @Param operation query string true "操作内容"
// @Success 0 {string} string "success"
// @Failure 503 {string} string "参数不存在"
// @Failure 504 {object} string "用户不存在"
// @Router /Pc/WsCtl/saveOp [post]
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.Sugar.Debugf("save customer_operation出现错误") t.ERROR("customer operation格式错误", code.MSG_ERR) } t.STRING("success") }
|