huangchundi 2 päivää sitten
vanhempi
sitoutus
d944e9ae03
9 muutettua tiedostoa jossa 1106 lisäystä ja 17 poistoa
  1. BIN
      aice.exe~
  2. 390 0
      controllers/api/InviteListDirController.go
  3. 370 0
      controllers/services/InviteListDirService.go
  4. 2 2
      go.mod
  5. 12 6
      go.sum
  6. 11 9
      main.go
  7. 153 0
      models/aice_users.go
  8. 161 0
      models/invite_list.go
  9. 7 0
      routers/router.go

BIN
aice.exe~


+ 390 - 0
controllers/api/InviteListDirController.go

@@ -0,0 +1,390 @@
+package api
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+	"strconv"
+	"think-go/controllers/services"
+	"think-go/utils"
+	"time"
+
+	beego "github.com/beego/beego/v2/server/web"
+)
+
+type InviteListDirController struct {
+	beego.Controller
+}
+
+var inviteListDirService = &services.InviteListDirService{}
+
+type ExternalInviteResponse struct {
+	Code int `json:"code"`
+	Data struct {
+		InviteAmount int `json:"invite_amount"`
+		List         []struct {
+			CTime          int64  `json:"c_time"`
+			UserID         string `json:"userid"`
+			Username       string `json:"username"`
+			PromoteName    string `json:"promote_name"`
+			Sales          string `json:"sales"`
+			TeamSales      string `json:"team_sales"`
+			TodayTeamSales string `json:"today_team_sales"`
+			UserBV         string `json:"user_bv"`
+			SubStatus      int    `json:"sub_status"`
+		} `json:"list"`
+		Count int `json:"count"`
+	} `json:"data"`
+}
+
+// 假设路由为 /invite/list [post]
+func (c *InviteListDirController) GetExternalInviteList() {
+	// 1. 获取当前请求中的参数(可以根据业务从 c 中获取,例如 c.GetInt 等)
+	limit, _ := c.GetInt("limit", 10) // 默认每页10条
+	page, _ := c.GetInt("page", 1)    // 默认第一页
+	userid := c.GetString("userid")   // 假设从当前请求传入
+
+	// 2. 准备外部接口的请求参数(x-www-form-urlencoded)
+	data := url.Values{}
+	data.Set("limit", strconv.Itoa(limit))
+	data.Set("page", strconv.Itoa(page))
+	data.Set("userid", userid)
+
+	// 3. 构造 HTTP 请求
+	externalURL := "https://app-api.aiceanglobal1.com/api/v1/reward/inviteListDir" // 替换为真实地址
+	req, err := http.NewRequest("POST", externalURL, bytes.NewBufferString(data.Encode()))
+	if err != nil {
+		c.Data["json"] = map[string]interface{}{"code": 500, "msg": "请求构造失败"}
+		c.ServeJSON()
+		return
+	}
+
+	// 4. 设置 Headers
+	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+	// 假设 Authorization 是 Bearer token,从配置或环境变量获取
+	req.Header.Set("Authorization", "Bearer 3dddf3dd7ba5b83d0b7334601d0e08a6")
+	// 外部接口需要的 userid header(可能和 body 中的 userid 不同,按需设置)
+	req.Header.Set("userid", "04a0d628189644a1b918f14cde664610")
+
+	// 5. 发送请求
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		c.Data["json"] = map[string]interface{}{"code": 500, "msg": "请求外部接口失败"}
+		c.ServeJSON()
+		fmt.Println("errrr:", err)
+		return
+	}
+	defer resp.Body.Close()
+
+	// 6. 读取响应体
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		c.Data["json"] = map[string]interface{}{"code": 500, "msg": "读取响应失败"}
+		c.ServeJSON()
+		return
+	}
+
+	// 7. 解析 JSON
+	var externalResp ExternalInviteResponse
+	if err := json.Unmarshal(body, &externalResp); err != nil {
+		c.Data["json"] = map[string]interface{}{"code": 500, "msg": "解析响应失败"}
+		c.ServeJSON()
+		return
+	}
+
+	if err == nil {
+
+		// 遍历列表
+		for _, item := range externalResp.Data.List {
+			fmt.Printf("用户: %s, 用户名: %s, 销售额: %s\n",
+				item.UserID, item.Username, item.Sales)
+
+			// 取 count
+			info := &services.InviteListInfo{
+				ParentId:       userid,
+				UserId:         item.UserID,
+				Username:       item.Username,
+				PromoteName:    item.PromoteName,
+				Sales:          item.Sales,
+				TeamSales:      item.TeamSales,
+				TodayTeamSales: item.TodayTeamSales,
+				UserBv:         item.UserBV,
+				SubStatus:      strconv.Itoa(item.SubStatus),
+				CTime:          item.CTime,
+				IsYes:          1,
+			}
+
+			err := inviteListDirService.CreateInviteList(info)
+			if err != nil {
+				utils.JSON(&c.Controller, 500, err.Error(), nil)
+				return
+			}
+		}
+
+	} else {
+		fmt.Printf("JSON 序列化失败: %v\n", err)
+	}
+
+	// 8. 根据业务需要处理外部接口返回的数据,例如转换格式、添加额外字段等
+	// 这里直接透传给客户端,也可以重新封装
+	c.Data["json"] = externalResp
+	c.ServeJSON()
+}
+
+func (c *InviteListDirController) GetExternalInviteList002() {
+	// 外部循环 50 次
+	for i := 0; i < 50; i++ {
+		// 1. 查询数据库中待处理的用户
+		records, err := inviteListDirService.GetInviteListByIsYes()
+		if err != nil {
+			utils.JSON(&c.Controller, 500, "查询失败: "+err.Error(), nil)
+			return
+		}
+
+		// 如果本次查询没有数据,说明处理完了,直接跳出大循环
+		if len(records) == 0 {
+			break
+		}
+
+		// 2. 遍历用户
+		for _, record := range records {
+			// 注意:因为报错提示 mismatched types,说明 record 是值类型而非指针
+			// 所以这里不需要 if record == nil 的判断,直接使用即可
+
+			info := &services.InviteListInfo{
+				InviteListDirId: record.InviteListDirId,
+				ParentId:        record.ParentId,
+				UserId:          record.UserId,
+				Username:        record.Username,
+				PromoteName:     record.PromoteName,
+				Sales:           record.Sales,
+				TeamSales:       record.TeamSales,
+				TodayTeamSales:  record.TodayTeamSales,
+				UserBv:          record.UserBv,
+				SubStatus:       record.SubStatus,
+				CTime:           record.CTime,
+				IsYes:           1, // 标记为已处理
+			}
+
+			// 按照业务需求延迟 5 秒
+			time.Sleep(5 * time.Second)
+			fmt.Println("正在处理用户ID:", info.UserId)
+
+			// 3. 请求外部接口并存入数据库
+			inviteListDirService.GoRequestNetInfo(info.UserId)
+
+			// 4. 修改当前用户状态
+			err = inviteListDirService.UpdateInviteList(info)
+			if err != nil {
+				utils.JSON(&c.Controller, 500, "更新状态失败: "+err.Error(), nil)
+				return
+			}
+		}
+	}
+
+	// 5. 循环全部结束后,正常返回成功
+	// 此时 err 为空,所以不能调用 err.Error()
+	utils.JSON(&c.Controller, 200, "处理完成", nil)
+}
+
+// InviteListDir 获取邀请列表信息
+// @router /api/invite/list [get]
+func (c *InviteListDirController) InviteListDir() {
+	// 获取请求参数
+	userId, _ := utils.GetRequestString(&c.Controller, "userid")
+
+	// 如果提供了userId,则从数据库获取数据
+	if userId != "" {
+		record, err := inviteListDirService.GetInviteList(userId)
+		if err != nil {
+			utils.JSON(&c.Controller, 500, err.Error(), nil)
+			return
+		}
+		utils.JSON(&c.Controller, 200, "success", map[string]interface{}{
+			"username":         record.Username,
+			"user_id":          record.UserId,
+			"parent_id":        record.ParentId,
+			"promote_name":     record.PromoteName,
+			"sales":            record.Sales,
+			"team_sales":       record.TeamSales,
+			"today_team_sales": record.TodayTeamSales,
+			"user_bv":          record.UserBv,
+			"sub_status":       record.SubStatus,
+			"c_time":           record.CTime,
+			"is_yes":           record.IsYes,
+		})
+		return
+	}
+
+	// 如果没有提供userId,返回空数据
+	utils.JSON(&c.Controller, 200, "success", map[string]interface{}{
+		"message": "please provide userid parameter",
+	})
+}
+
+// CreateInviteList 创建邀请列表记录
+// @router /api/invite/create [post]
+func (c *InviteListDirController) CreateInviteList() {
+	parentId, _ := utils.GetRequestString(&c.Controller, "parent_id")
+	userId, _ := utils.GetRequestString(&c.Controller, "user_id")
+	username, _ := utils.GetRequestString(&c.Controller, "username")
+	promoteName, _ := utils.GetRequestString(&c.Controller, "promote_name")
+	sales, _ := utils.GetRequestString(&c.Controller, "sales")
+	teamSales, _ := utils.GetRequestString(&c.Controller, "team_sales")
+	todayTeamSales, _ := utils.GetRequestString(&c.Controller, "today_team_sales")
+	userBv, _ := utils.GetRequestString(&c.Controller, "user_bv")
+	subStatus, _ := utils.GetRequestString(&c.Controller, "sub_status")
+
+	cTimeStr := c.Ctx.Input.Query("c_time")
+	cTime := int64(0)
+	if cTimeStr != "" {
+		if ct, err := strconv.ParseInt(cTimeStr, 10, 64); err == nil {
+			cTime = ct
+		}
+	}
+
+	isYesStr := c.Ctx.Input.Query("is_yes")
+	isYes := 0
+	if isYesStr != "" {
+		if iy, err := strconv.Atoi(isYesStr); err == nil {
+			isYes = iy
+		}
+	}
+
+	info := &services.InviteListInfo{
+		ParentId:       parentId,
+		UserId:         userId,
+		Username:       username,
+		PromoteName:    promoteName,
+		Sales:          sales,
+		TeamSales:      teamSales,
+		TodayTeamSales: todayTeamSales,
+		UserBv:         userBv,
+		SubStatus:      subStatus,
+		CTime:          cTime,
+		IsYes:          isYes,
+	}
+
+	err := inviteListDirService.CreateInviteList(info)
+	if err != nil {
+		utils.JSON(&c.Controller, 500, err.Error(), nil)
+		return
+	}
+
+	utils.JSON(&c.Controller, 200, "create success", map[string]interface{}{
+		"message": "invite list record created successfully",
+	})
+}
+
+// UpdateInviteList 更新邀请列表记录
+// @router /api/invite/update [post]
+func (c *InviteListDirController) UpdateInviteList() {
+	parentId, _ := utils.GetRequestString(&c.Controller, "parent_id")
+	userId, _ := utils.GetRequestString(&c.Controller, "user_id")
+	username, _ := utils.GetRequestString(&c.Controller, "username")
+	promoteName, _ := utils.GetRequestString(&c.Controller, "promote_name")
+	sales, _ := utils.GetRequestString(&c.Controller, "sales")
+	teamSales, _ := utils.GetRequestString(&c.Controller, "team_sales")
+	todayTeamSales, _ := utils.GetRequestString(&c.Controller, "today_team_sales")
+	userBv, _ := utils.GetRequestString(&c.Controller, "user_bv")
+	subStatus, _ := utils.GetRequestString(&c.Controller, "sub_status")
+
+	cTimeStr := c.Ctx.Input.Query("c_time")
+	cTime := int64(0)
+	if cTimeStr != "" {
+		if ct, err := strconv.ParseInt(cTimeStr, 10, 64); err == nil {
+			cTime = ct
+		}
+	}
+
+	isYesStr := c.Ctx.Input.Query("is_yes")
+	isYes := 0
+	if isYesStr != "" {
+		if iy, err := strconv.Atoi(isYesStr); err == nil {
+			isYes = iy
+		}
+	}
+
+	info := &services.InviteListInfo{
+		ParentId:       parentId,
+		UserId:         userId,
+		Username:       username,
+		PromoteName:    promoteName,
+		Sales:          sales,
+		TeamSales:      teamSales,
+		TodayTeamSales: todayTeamSales,
+		UserBv:         userBv,
+		SubStatus:      subStatus,
+		CTime:          cTime,
+		IsYes:          isYes,
+	}
+
+	err := inviteListDirService.UpdateInviteList(info)
+	if err != nil {
+		utils.JSON(&c.Controller, 500, err.Error(), nil)
+		return
+	}
+
+	utils.JSON(&c.Controller, 200, "update success", map[string]interface{}{
+		"message": "invite list record updated successfully",
+	})
+}
+
+// GetAllInviteLists 获取所有邀请列表记录(分页)
+// @router /api/invite/listAll [get]
+func (c *InviteListDirController) GetAllInviteLists() {
+	// 获取分页参数
+	pageStr := c.Ctx.Input.Query("page")
+	pageSizeStr := c.Ctx.Input.Query("pageSize")
+
+	page := 1
+	pageSize := 10
+
+	if pageStr != "" {
+		if p, err := strconv.Atoi(pageStr); err == nil && p > 0 {
+			page = p
+		}
+	}
+
+	if pageSizeStr != "" {
+		if ps, err := strconv.Atoi(pageSizeStr); err == nil && ps > 0 {
+			pageSize = ps
+		}
+	}
+
+	offset := int64((page - 1) * pageSize)
+	limit := int64(pageSize)
+
+	records, total, err := inviteListDirService.GetAllInviteLists(offset, limit)
+	if err != nil {
+		utils.JSON(&c.Controller, 500, err.Error(), nil)
+		return
+	}
+
+	utils.JSON(&c.Controller, 200, "success", map[string]interface{}{
+		"list":     records,
+		"total":    total,
+		"page":     page,
+		"pageSize": pageSize,
+	})
+}
+
+// DeleteInviteList 删除邀请列表记录
+// @router /api/invite/delete [post]
+func (c *InviteListDirController) DeleteInviteList() {
+	userId, _ := utils.GetRequestString(&c.Controller, "user_id")
+
+	err := inviteListDirService.DeleteInviteList(userId)
+	if err != nil {
+		utils.JSON(&c.Controller, 500, err.Error(), nil)
+		return
+	}
+
+	utils.JSON(&c.Controller, 200, "success", map[string]interface{}{
+		"message": "invite list record deleted successfully",
+	})
+}

+ 370 - 0
controllers/services/InviteListDirService.go

@@ -0,0 +1,370 @@
+package services
+
+import (
+	"bytes"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+	"strconv"
+	"think-go/models"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type InviteListDirService struct{}
+
+// InviteListInfo represents the invite list information
+type InviteListInfo struct {
+	InviteListDirId int    `json:"invite_list_dir_id"`
+	ParentId        string `json:"parent_id"`
+	UserId          string `json:"user_id"`
+	Username        string `json:"username"`
+	PromoteName     string `json:"promote_name"`
+	Sales           string `json:"sales"`
+	TeamSales       string `json:"team_sales"`
+	TodayTeamSales  string `json:"today_team_sales"`
+	UserBv          string `json:"user_bv"`
+	SubStatus       string `json:"sub_status"`
+	CTime           int64  `json:"c_time"`
+	IsYes           int    `json:"is_yes"`
+}
+
+// GetInviteList retrieves invite list information by user_id
+func (s *InviteListDirService) GetInviteList(userId string) (*InviteListInfo, error) {
+	if userId == "" {
+		return nil, errors.New("user_id is required")
+	}
+
+	o := orm.NewOrm()
+	record := &models.InviteList{UserId: userId}
+	err := o.Read(record, "UserId")
+	if err != nil {
+		if err == orm.ErrNoRows {
+			return nil, errors.New("invite list record not found")
+		}
+		return nil, err
+	}
+
+	return &InviteListInfo{
+		InviteListDirId: record.InviteListDirId,
+		ParentId:        record.ParentId,
+		UserId:          record.UserId,
+		Username:        record.Username,
+		PromoteName:     record.PromoteName,
+		Sales:           record.Sales,
+		TeamSales:       record.TeamSales,
+		TodayTeamSales:  record.TodayTeamSales,
+		UserBv:          record.UserBv,
+		SubStatus:       record.SubStatus,
+		CTime:           record.CTime,
+		IsYes:           record.IsYes,
+	}, nil
+}
+
+type ExternalInviteResponse struct {
+	Code int `json:"code"`
+	Data struct {
+		InviteAmount int `json:"invite_amount"`
+		List         []struct {
+			CTime          int64  `json:"c_time"`
+			UserID         string `json:"userid"`
+			Username       string `json:"username"`
+			PromoteName    string `json:"promote_name"`
+			Sales          string `json:"sales"`
+			TeamSales      string `json:"team_sales"`
+			TodayTeamSales string `json:"today_team_sales"`
+			UserBV         string `json:"user_bv"`
+			SubStatus      int    `json:"sub_status"`
+		} `json:"list"`
+		Count int `json:"count"`
+	} `json:"data"`
+}
+
+func (s *InviteListDirService) GoRequestNetInfo(userId string) {
+	svc := &InviteListDirService{}
+	// 2. 准备外部接口的请求参数(x-www-form-urlencoded)
+	data := url.Values{}
+	data.Set("limit", strconv.Itoa(1000))
+	data.Set("page", strconv.Itoa(1))
+	data.Set("userid", userId)
+
+	// 3. 构造 HTTP 请求
+	externalURL := "https://app-api.aiceanglobal1.com/api/v1/reward/inviteListDir" // 替换为真实地址
+	req, err := http.NewRequest("POST", externalURL, bytes.NewBufferString(data.Encode()))
+	if err != nil {
+
+		return
+	}
+
+	// 4. 设置 Headers
+	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+	// 假设 Authorization 是 Bearer token,从配置或环境变量获取
+	req.Header.Set("Authorization", "Bearer 590d13fe9d0ea64df44c00c02ce8dd23")
+	// 外部接口需要的 userid header(可能和 body 中的 userid 不同,按需设置)
+	req.Header.Set("userid", "04a0d628189644a1b918f14cde664610")
+
+	// 5. 发送请求
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+
+		fmt.Println("errrr:", err)
+		return
+	}
+	defer resp.Body.Close()
+
+	// 6. 读取响应体
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+
+		return
+	}
+
+	// 7. 解析 JSON
+	var externalResp ExternalInviteResponse
+	if err := json.Unmarshal(body, &externalResp); err != nil {
+
+		return
+	}
+
+	if err == nil {
+
+		// 遍历列表
+		for _, item := range externalResp.Data.List {
+			// 取 count
+			info := &InviteListInfo{
+				ParentId:       userId,
+				UserId:         item.UserID,
+				Username:       item.Username,
+				PromoteName:    item.PromoteName,
+				Sales:          item.Sales,
+				TeamSales:      item.TeamSales,
+				TodayTeamSales: item.TodayTeamSales,
+				UserBv:         item.UserBV,
+				SubStatus:      strconv.Itoa(item.SubStatus),
+				CTime:          item.CTime,
+				IsYes:          0,
+			}
+
+			err := svc.CreateInviteList(info)
+			if err != nil {
+				return
+			}
+		}
+
+	} else {
+		fmt.Printf("JSON 序列化失败: %v\n", err)
+	}
+
+}
+func (s *InviteListDirService) GetInviteListByIsYes() ([]InviteListInfo, error) {
+
+	query := make(map[string]string)
+	query["is_yes"] = strconv.Itoa(0)
+	fields := []string{"InviteListDirId", "ParentId", "UserId", "Username", "PromoteName", "Sales", "TeamSales", "TodayTeamSales", "UserBv", "SubStatus", "CTime", "IsYes"}
+	sortby := []string{"InviteListDirId"}
+	order := []string{"desc"}
+
+	ml, err := models.GetAllInviteList(query, fields, sortby, order, 0, 100)
+	if err != nil {
+		return nil, err
+	}
+
+	//fmt.Printf("ml------:", ml)
+	result := make([]InviteListInfo, 0, len(ml))
+
+	for _, item := range ml {
+		// 断言 item 是 map[string]interface{}
+		m, ok := item.(map[string]interface{})
+		if !ok {
+			// 类型不匹配,跳过或记录错误
+			continue
+		}
+
+		// 从 map 中安全提取字段(注意字段名与 JSON 标签一致)
+		info := InviteListInfo{
+			InviteListDirId: getInt(m, "InviteListDirId"), // 根据实际字段名调整
+			ParentId:        getString(m, "ParentId"),
+			UserId:          getString(m, "UserId"),
+			Username:        getString(m, "Username"),
+			PromoteName:     getString(m, "PromoteName"),
+			Sales:           getString(m, "Sales"),
+			TeamSales:       getString(m, "TeamSales"),
+			TodayTeamSales:  getString(m, "TodayTeamSales"),
+			UserBv:          getString(m, "UserBv"),
+			SubStatus:       getString(m, "SubStatus"),
+			CTime:           getInt64(m, "CTime"),
+			IsYes:           getInt(m, "IsYes"),
+		}
+		result = append(result, info)
+	}
+
+	return result, err
+}
+
+// CreateInviteList creates a new invite list record
+func (s *InviteListDirService) CreateInviteList(info *InviteListInfo) error {
+	if info.UserId == "" {
+		return errors.New("user_id is required")
+	}
+
+	// Check if record already exists
+	o := orm.NewOrm()
+	record := &models.InviteList{UserId: info.UserId}
+	err := o.Read(record, "UserId")
+	if err == nil {
+		return errors.New("invite list record already exists")
+	}
+
+	record = &models.InviteList{
+		ParentId:       info.ParentId,
+		UserId:         info.UserId,
+		Username:       info.Username,
+		PromoteName:    info.PromoteName,
+		Sales:          info.Sales,
+		TeamSales:      info.TeamSales,
+		TodayTeamSales: info.TodayTeamSales,
+		UserBv:         info.UserBv,
+		SubStatus:      info.SubStatus,
+		CTime:          info.CTime,
+		IsYes:          info.IsYes,
+	}
+
+	_, err = models.AddInviteList(record)
+	return err
+}
+
+// UpdateInviteList updates an existing invite list record
+func (s *InviteListDirService) UpdateInviteList(info *InviteListInfo) error {
+	if info.UserId == "" {
+		return errors.New("user_id is required")
+	}
+
+	o := orm.NewOrm()
+	record := &models.InviteList{UserId: info.UserId}
+	err := o.Read(record, "UserId")
+	if err != nil {
+		if err == orm.ErrNoRows {
+			return errors.New("invite list record not found")
+		}
+		return err
+	}
+
+	// Update fields
+	record.ParentId = info.ParentId
+	record.Username = info.Username
+	record.PromoteName = info.PromoteName
+	record.Sales = info.Sales
+	record.TeamSales = info.TeamSales
+	record.TodayTeamSales = info.TodayTeamSales
+	record.UserBv = info.UserBv
+	record.SubStatus = info.SubStatus
+	record.CTime = info.CTime
+	record.IsYes = info.IsYes
+
+	return models.UpdateInviteListById(record)
+}
+
+// GetAllInviteLists retrieves all invite list records with pagination
+func (s *InviteListDirService) GetAllInviteLists(offset, limit int64) ([]InviteListInfo, int64, error) {
+	query := make(map[string]string)
+	fields := []string{"InviteListDirId", "ParentId", "UserId", "Username", "PromoteName", "Sales", "TeamSales", "TodayTeamSales", "UserBv", "SubStatus", "CTime", "IsYes"}
+	sortby := []string{"InviteListDirId"}
+	order := []string{"desc"}
+
+	ml, err := models.GetAllInviteList(query, fields, sortby, order, offset, limit)
+	if err != nil {
+		return nil, 0, err
+	}
+
+	result := make([]InviteListInfo, 0, len(ml))
+	for _, item := range ml {
+		if record, ok := item.(models.InviteList); ok {
+			result = append(result, InviteListInfo{
+				InviteListDirId: record.InviteListDirId,
+				ParentId:        record.ParentId,
+				UserId:          record.UserId,
+				Username:        record.Username,
+				PromoteName:     record.PromoteName,
+				Sales:           record.Sales,
+				TeamSales:       record.TeamSales,
+				TodayTeamSales:  record.TodayTeamSales,
+				UserBv:          record.UserBv,
+				SubStatus:       record.SubStatus,
+				CTime:           record.CTime,
+				IsYes:           record.IsYes,
+			})
+		}
+	}
+
+	// Get total count
+	o := orm.NewOrm()
+	count, err := o.QueryTable(new(models.InviteList)).Count()
+	if err != nil {
+		return result, 0, err
+	}
+
+	return result, count, nil
+}
+
+// DeleteInviteList deletes an invite list record by user_id
+func (s *InviteListDirService) DeleteInviteList(userId string) error {
+	if userId == "" {
+		return errors.New("user_id is required")
+	}
+
+	o := orm.NewOrm()
+	record := &models.InviteList{UserId: userId}
+	err := o.Read(record, "UserId")
+	if err != nil {
+		if err == orm.ErrNoRows {
+			return errors.New("invite list record not found")
+		}
+		return err
+	}
+
+	return models.DeleteInviteList(record.InviteListDirId)
+}
+
+// 从 map 中安全获取 string 值
+func getString(m map[string]interface{}, key string) string {
+	if v, ok := m[key]; ok {
+		if s, ok := v.(string); ok {
+			return s
+		}
+	}
+	return ""
+}
+
+// 从 map 中安全获取 int 值(兼容 float64)
+func getInt(m map[string]interface{}, key string) int {
+	if v, ok := m[key]; ok {
+		switch val := v.(type) {
+		case int:
+			return val
+		case float64:
+			return int(val)
+		case int64:
+			return int(val)
+		}
+	}
+	return 0
+}
+
+// 从 map 中安全获取 int64 值(兼容 float64)
+func getInt64(m map[string]interface{}, key string) int64 {
+	if v, ok := m[key]; ok {
+		switch val := v.(type) {
+		case int64:
+			return val
+		case float64:
+			return int64(val)
+		case int:
+			return int64(val)
+		}
+	}
+	return 0
+}

+ 2 - 2
go.mod

@@ -1,11 +1,12 @@
 module think-go
 
-go 1.26
+go 1.25
 
 require github.com/beego/beego/v2 v2.1.0
 
 require (
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
+	github.com/go-redis/redis/v8 v8.11.5
 	github.com/go-sql-driver/mysql v1.9.3
 	github.com/smartystreets/goconvey v1.6.4
 )
@@ -15,7 +16,6 @@ require (
 	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/cespare/xxhash/v2 v2.3.0 // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
-	github.com/go-redis/redis/v8 v8.11.5 // indirect
 	github.com/golang/protobuf v1.5.3 // indirect
 	github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
 	github.com/hashicorp/golang-lru v0.5.4 // indirect

+ 12 - 6
go.sum

@@ -4,8 +4,6 @@ github.com/beego/beego/v2 v2.1.0 h1:Lk0FtQGvDQCx5V5yEu4XwDsIgt+QOlNjt5emUa3/ZmA=
 github.com/beego/beego/v2 v2.1.0/go.mod h1:6h36ISpaxNrrpJ27siTpXBG8d/Icjzsc7pU1bWpp0EE=
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
-github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
-github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
 github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
@@ -17,6 +15,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
 github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
 github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
+github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
+github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
 github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
 github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
 github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
@@ -47,6 +47,12 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk
 github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
 github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
 github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
+github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
+github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
+github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
+github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
+github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
+github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -59,8 +65,6 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI
 github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
 github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
 github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
-github.com/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs=
-github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0=
 github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
 github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
@@ -71,8 +75,6 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
-go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
-go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
@@ -95,5 +97,9 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 11 - 9
main.go

@@ -109,20 +109,22 @@ func init() {
 
 // CORSFilter 用于处理跨域请求
 func CORSFilter(ctx *bcontext.Context) {
-	// 设置CORS响应头
-	ctx.Output.Header("Access-Control-Allow-Origin", "*")
-	ctx.Output.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD")
-	ctx.Output.Header("Access-Control-Allow-Headers", "*")
-	ctx.Output.Header("Access-Control-Max-Age", "86400")
+	origin := ctx.Input.Header("Origin")
+	if origin != "" {
+		ctx.Output.Header("Access-Control-Allow-Origin", origin)
+	}
+
 	ctx.Output.Header("Access-Control-Allow-Credentials", "true")
-	ctx.Output.Header("Access-Control-Expose-Headers", "*")
+	ctx.Output.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD")
 
-	// 移除引荐来源网址政策限制
-	ctx.Output.Header("Referrer-Policy", "no-referrer")
+	// 建议把前端 fetch 用到的所有 Header 都加上
+	ctx.Output.Header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With, Accept, Origin")
+	ctx.Output.Header("Access-Control-Max-Age", "86400")
 
-	// 处理预检请求
 	if ctx.Input.Method() == "OPTIONS" {
 		ctx.Output.SetStatus(200)
+		// 显式结束请求,防止进入后续逻辑
+		return
 	}
 }
 

+ 153 - 0
models/aice_users.go

@@ -0,0 +1,153 @@
+package models
+
+import (
+	"errors"
+	"fmt"
+	"reflect"
+	"strings"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type AiceUsers struct {
+	Id       int    `orm:"column(userid);pk"`
+	Email    string `orm:"column(email);size(255);null"`
+	Token    string `orm:"column(token);size(255);null"`
+	Username string `orm:"column(username);size(255);null"`
+	Address  string `orm:"column(address);size(255);null"`
+}
+
+func (t *AiceUsers) TableName() string {
+	return "aice_users"
+}
+
+func init() {
+	orm.RegisterModel(new(AiceUsers))
+}
+
+// AddAiceUsers insert a new AiceUsers into database and returns
+// last inserted Id on success.
+func AddAiceUsers(m *AiceUsers) (id int64, err error) {
+	o := orm.NewOrm()
+	id, err = o.Insert(m)
+	return
+}
+
+// GetAiceUsersById retrieves AiceUsers by Id. Returns error if
+// Id doesn't exist
+func GetAiceUsersById(id int) (v *AiceUsers, err error) {
+	o := orm.NewOrm()
+	v = &AiceUsers{Id: id}
+	if err = o.Read(v); err == nil {
+		return v, nil
+	}
+	return nil, err
+}
+
+// GetAllAiceUsers retrieves all AiceUsers matches certain condition. Returns empty list if
+// no records exist
+func GetAllAiceUsers(query map[string]string, fields []string, sortby []string, order []string,
+	offset int64, limit int64) (ml []interface{}, err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(AiceUsers))
+	// query k=v
+	for k, v := range query {
+		// rewrite dot-notation to Object__Attribute
+		k = strings.Replace(k, ".", "__", -1)
+		if strings.Contains(k, "isnull") {
+			qs = qs.Filter(k, (v == "true" || v == "1"))
+		} else {
+			qs = qs.Filter(k, v)
+		}
+	}
+	// order by:
+	var sortFields []string
+	if len(sortby) != 0 {
+		if len(sortby) == len(order) {
+			// 1) for each sort field, there is an associated order
+			for i, v := range sortby {
+				orderby := ""
+				if order[i] == "desc" {
+					orderby = "-" + v
+				} else if order[i] == "asc" {
+					orderby = v
+				} else {
+					return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
+				}
+				sortFields = append(sortFields, orderby)
+			}
+			qs = qs.OrderBy(sortFields...)
+		} else if len(sortby) != len(order) && len(order) == 1 {
+			// 2) there is exactly one order, all the sorted fields will be sorted by this order
+			for _, v := range sortby {
+				orderby := ""
+				if order[0] == "desc" {
+					orderby = "-" + v
+				} else if order[0] == "asc" {
+					orderby = v
+				} else {
+					return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
+				}
+				sortFields = append(sortFields, orderby)
+			}
+		} else if len(sortby) != len(order) && len(order) != 1 {
+			return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
+		}
+	} else {
+		if len(order) != 0 {
+			return nil, errors.New("Error: unused 'order' fields")
+		}
+	}
+
+	var l []AiceUsers
+	qs = qs.OrderBy(sortFields...)
+	if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
+		if len(fields) == 0 {
+			for _, v := range l {
+				ml = append(ml, v)
+			}
+		} else {
+			// trim unused fields
+			for _, v := range l {
+				m := make(map[string]interface{})
+				val := reflect.ValueOf(v)
+				for _, fname := range fields {
+					m[fname] = val.FieldByName(fname).Interface()
+				}
+				ml = append(ml, m)
+			}
+		}
+		return ml, nil
+	}
+	return nil, err
+}
+
+// UpdateAiceUsers updates AiceUsers by Id and returns error if
+// the record to be updated doesn't exist
+func UpdateAiceUsersById(m *AiceUsers) (err error) {
+	o := orm.NewOrm()
+	v := AiceUsers{Id: m.Id}
+	// ascertain id exists in the database
+	if err = o.Read(&v); err == nil {
+		var num int64
+		if num, err = o.Update(m); err == nil {
+			fmt.Println("Number of records updated in database:", num)
+		}
+	}
+	return
+}
+
+// DeleteAiceUsers deletes AiceUsers by Id and returns error if
+// the record to be deleted doesn't exist
+func DeleteAiceUsers(id int) (err error) {
+	o := orm.NewOrm()
+	v := AiceUsers{Id: id}
+	// ascertain id exists in the database
+	if err = o.Read(&v); err == nil {
+		var num int64
+		if num, err = o.Delete(&AiceUsers{Id: id}); err == nil {
+			fmt.Println("Number of records deleted in database:", num)
+		}
+	}
+	return
+}

+ 161 - 0
models/invite_list.go

@@ -0,0 +1,161 @@
+package models
+
+import (
+	"errors"
+	"fmt"
+	"reflect"
+	"strings"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+// 安置图谱列表
+type InviteList struct {
+	InviteListDirId int    `orm:"column(invite_list_dir_id);auto" description:"安置图谱"`
+	ParentId        string `orm:"column(parent_id);size(11);null" description:"上级id"`
+	UserId          string `orm:"column(user_id);size(0);null"`
+	Username        string `orm:"column(username);size(255);null"`
+	PromoteName     string `orm:"column(promote_name);size(255);null" description:"级别"`
+	Sales           string `orm:"column(sales);size(255);null" description:"入仓金额"`
+	TeamSales       string `orm:"column(team_sales);size(255);null" description:"社区业绩"`
+	TodayTeamSales  string `orm:"column(today_team_sales);size(255);null" description:"今天业绩"`
+	UserBv          string `orm:"column(user_bv);size(255);null"`
+	SubStatus       string `orm:"column(sub_status);size(255);null"`
+	CTime           int64  `orm:"column(c_time);null"`
+	IsYes           int    `orm:"column(is_yes);null" description:"默认0:待抓取"`
+}
+
+func (t *InviteList) TableName() string {
+	return "invite_list"
+}
+
+func init() {
+	orm.RegisterModel(new(InviteList))
+}
+
+// AddInviteList insert a new InviteList into database and returns
+// last inserted Id on success.
+func AddInviteList(m *InviteList) (id int64, err error) {
+	o := orm.NewOrm()
+	id, err = o.Insert(m)
+	return
+}
+
+// GetInviteListById retrieves InviteList by Id. Returns error if
+// Id doesn't exist
+func GetInviteListById(id int) (v *InviteList, err error) {
+	o := orm.NewOrm()
+	v = &InviteList{InviteListDirId: id}
+	if err = o.Read(v); err == nil {
+		return v, nil
+	}
+	return nil, err
+}
+
+// GetAllInviteList retrieves all InviteList matches certain condition. Returns empty list if
+// no records exist
+func GetAllInviteList(query map[string]string, fields []string, sortby []string, order []string,
+	offset int64, limit int64) (ml []interface{}, err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(InviteList))
+	// query k=v
+	for k, v := range query {
+		// rewrite dot-notation to Object__Attribute
+		k = strings.Replace(k, ".", "__", -1)
+		if strings.Contains(k, "isnull") {
+			qs = qs.Filter(k, (v == "true" || v == "1"))
+		} else {
+			qs = qs.Filter(k, v)
+		}
+	}
+	// order by:
+	var sortFields []string
+	if len(sortby) != 0 {
+		if len(sortby) == len(order) {
+			// 1) for each sort field, there is an associated order
+			for i, v := range sortby {
+				orderby := ""
+				if order[i] == "desc" {
+					orderby = "-" + v
+				} else if order[i] == "asc" {
+					orderby = v
+				} else {
+					return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
+				}
+				sortFields = append(sortFields, orderby)
+			}
+			qs = qs.OrderBy(sortFields...)
+		} else if len(sortby) != len(order) && len(order) == 1 {
+			// 2) there is exactly one order, all the sorted fields will be sorted by this order
+			for _, v := range sortby {
+				orderby := ""
+				if order[0] == "desc" {
+					orderby = "-" + v
+				} else if order[0] == "asc" {
+					orderby = v
+				} else {
+					return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
+				}
+				sortFields = append(sortFields, orderby)
+			}
+		} else if len(sortby) != len(order) && len(order) != 1 {
+			return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
+		}
+	} else {
+		if len(order) != 0 {
+			return nil, errors.New("Error: unused 'order' fields")
+		}
+	}
+
+	var l []InviteList
+	qs = qs.OrderBy(sortFields...)
+	if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
+		if len(fields) == 0 {
+			for _, v := range l {
+				ml = append(ml, v)
+			}
+		} else {
+			// trim unused fields
+			for _, v := range l {
+				m := make(map[string]interface{})
+				val := reflect.ValueOf(v)
+				for _, fname := range fields {
+					m[fname] = val.FieldByName(fname).Interface()
+				}
+				ml = append(ml, m)
+			}
+		}
+		return ml, nil
+	}
+	return nil, err
+}
+
+// UpdateInviteList updates InviteList by Id and returns error if
+// the record to be updated doesn't exist
+func UpdateInviteListById(m *InviteList) (err error) {
+	o := orm.NewOrm()
+	v := InviteList{InviteListDirId: m.InviteListDirId}
+	// ascertain id exists in the database
+	if err = o.Read(&v); err == nil {
+		var num int64
+		if num, err = o.Update(m); err == nil {
+			fmt.Println("Number of records updated in database:", num)
+		}
+	}
+	return
+}
+
+// DeleteInviteList deletes InviteList by Id and returns error if
+// the record to be deleted doesn't exist
+func DeleteInviteList(id int) (err error) {
+	o := orm.NewOrm()
+	v := InviteList{InviteListDirId: id}
+	// ascertain id exists in the database
+	if err = o.Read(&v); err == nil {
+		var num int64
+		if num, err = o.Delete(&InviteList{InviteListDirId: id}); err == nil {
+			fmt.Println("Number of records deleted in database:", num)
+		}
+	}
+	return
+}

+ 7 - 0
routers/router.go

@@ -21,6 +21,13 @@ func init() {
 	)
 	nsApi := beego.NewNamespace("/api",
 		beego.NSRouter("/inter/sycdata", &api.InterceptController{}, "post:Sycdata"),
+		beego.NSRouter("/invite/list", &api.InviteListDirController{}, "get:InviteListDir"),
+		beego.NSRouter("/invite/create", &api.InviteListDirController{}, "post:CreateInviteList"),
+		beego.NSRouter("/invite/update", &api.InviteListDirController{}, "post:UpdateInviteList"),
+		beego.NSRouter("/invite/listAll", &api.InviteListDirController{}, "get:GetAllInviteLists"),
+		beego.NSRouter("/invite/delete", &api.InviteListDirController{}, "post:DeleteInviteList"),
+		beego.NSRouter("/invite/getInviteList", &api.InviteListDirController{}, "post:GetExternalInviteList"),
+		beego.NSRouter("/invite/GetExternalInviteList002", &api.InviteListDirController{}, "post:GetExternalInviteList002"),
 	)
 	beego.AddNamespace(nsAdmin)
 	beego.AddNamespace(nsApi)