180 lines
8.5 KiB
Go
180 lines
8.5 KiB
Go
package service
|
||
|
||
import (
|
||
"encoding/json"
|
||
"net/http"
|
||
)
|
||
|
||
type GetCourseListRequest struct {
|
||
SearchContent *string `json:"search_content,omitempty"` // 课程名字模糊搜索
|
||
OrderBy *string `json:"order_by,omitempty"` // 是否需要根据创建时间排序(是:modify,否:'')
|
||
OrderType *int `json:"order_type,omitempty"` // 排序类型(1:降序,2:升序)
|
||
PageIndex *int `json:"page_index,omitempty"` // 当前页
|
||
PageSize *int `json:"page_size,omitempty"` // 每页条数(1~50条)
|
||
SaleStatus *int `json:"sale_status,omitempty"` // 上架状态(-1:全部 0 :下架 1:上架 2:待上架)
|
||
CreatedSource *int `json:"created_source,omitempty"` // 课程创建来源(0:全部,1:课程,2:圈子)
|
||
Tags []string `json:"tags,omitempty"` // 商品分组id数组
|
||
}
|
||
|
||
type Course struct {
|
||
ResourceId string `json:"resource_id"` // 课程id
|
||
ResourceType int `json:"resource_type"` // 资源种类(此接口返回必定是50,表示鹅课程)
|
||
Title string `json:"title"` // 课程名称
|
||
ImgUrl string `json:"img_url"` // 课程封面图
|
||
ImgUrlCompressed string `json:"img_url_compressed"` // 课程封面压缩图
|
||
UserCount int `json:"user_count"` // 用户数
|
||
ResourceCnt int `json:"resource_cnt"` // 内容数
|
||
InteractiveCnt int `json:"interactive_cnt"` // 互动数
|
||
LastUpdatedAt string `json:"last_updated_at"` // 最新修改时间
|
||
CurriculumTime string `json:"curriculum_time"` // 开课时间
|
||
CurriculumEndTime string `json:"curriculum_end_time"` // 开课结束时间
|
||
CreatedSource int `json:"created_source"` // 创建来源 1-课程 2-圈子
|
||
Price int `json:"price"` // 商品价格
|
||
LinePrice int `json:"line_price"` // 划线价格
|
||
IsFree int `json:"is_free"` // 是否免费(0-收费 1-免费)
|
||
IsPublic int `json:"is_public"` // 是否公开售卖(0-不公开 1-公开)
|
||
IsPassword int `json:"is_password"` // 是否加密(0-不加密 1--加密)
|
||
IsStopSell int `json:"is_stop_sell"` // 是否停售:0否 1是
|
||
IsDisplay int `json:"is_display"` // 是否显示:0否(隐藏状态) 1是(显示状态)
|
||
SellType int `json:"sell_type"` // 售卖方式:1 = 独立售卖,2 = 关联售卖(商品放入专栏/会员/训练营中售卖)
|
||
SaleAt string `json:"sale_at"` // 上架时间
|
||
SaleStatus int `json:"sale_status"` // 上架状态: 0下架 1上架 2(定时上架还未上架阶段)待上架
|
||
CanSoldStart string `json:"can_sold_start"` // 可售开始时间
|
||
CanSoldEnd string `json:"can_sold_end"` // 可售结束时间
|
||
GoodsType int `json:"goods_type"` // 商品种类(1免费2付费3加密4指派5非单卖)
|
||
IsBan int `json:"is_ban"` // 商品是否被封禁:0 = 否,1 = 是
|
||
Position int `json:"position"` // 在列表中所在的位置
|
||
IsJoinMarketAct bool `json:"is_join_market_act"` // 是否参与营销活动
|
||
CreatedByResourceInfo CreatedByResourceInfo `json:"created_by_resource_info"` // 创建来源的信息
|
||
Period Period `json:"period"` // 有效期
|
||
}
|
||
|
||
type CreatedByResourceInfo struct {
|
||
ResourceId string `json:"resource_id"` // 创建来源资源id
|
||
ResourceType int `json:"resource_type"` // 创建来源资源种类
|
||
Title string `json:"title"` // 创建来源资源名称
|
||
}
|
||
|
||
type Period struct {
|
||
PeriodType int `json:"period_type"` // 有效期的种类(-1永久有效,大于等于0是真实有效期)
|
||
PeriodValue string `json:"period_value"` // 有效期的值(单位是s)
|
||
}
|
||
|
||
type GetCourseListResponseData struct {
|
||
List []Course `json:"list"`
|
||
Total int `json:"total"`
|
||
}
|
||
|
||
type GetCourseListResponse struct {
|
||
BaseResponse
|
||
Data GetCourseListResponseData `json:"data"`
|
||
}
|
||
|
||
type GetSubCourseListRequest struct {
|
||
CourseId string `json:"course_id"` // 必填,父课程id
|
||
Page *int `json:"page,omitempty"` // 可选,当前页,不传或0则不分页
|
||
PageSize *int `json:"page_size,omitempty"` // 可选,每页条数(1~50),不传或0则不分页
|
||
}
|
||
|
||
type GetSubCourseListResponseData struct {
|
||
SubCourseId string `json:"sub_course_id"` // 子课程id
|
||
ChapterTitle string `json:"chapter_title"` // 子课程名称
|
||
SubCourseImg string `json:"sub_course_img"` // 子课程封面图
|
||
SortValue int `json:"sort_value"` // 排序值(升序排序)
|
||
TaskCount int `json:"task_count"` // 小节数
|
||
SectionCount int `json:"section_count"` // 章节数
|
||
}
|
||
|
||
type GetSubCourseListResponse struct {
|
||
BaseResponse
|
||
|
||
Data []GetSubCourseListResponseData `json:"data"`
|
||
}
|
||
|
||
type GetCourseChapterListRequest struct {
|
||
CourseId string `json:"course_id"` // 课程id
|
||
}
|
||
|
||
type CourseChapter struct {
|
||
ChapterId string `json:"chapter_id"` // 章节id
|
||
ChapterTitle string `json:"chapter_title"` // 章节名称
|
||
ChapterType int `json:"chapter_type"` // 章节类型 0-无 1-章 2-节
|
||
ResourceType int `json:"resource_type"` // 关联资源种类
|
||
Children []CourseChapter `json:"children"` // 子章节集合
|
||
Id int `json:"id"` // 主键id
|
||
IsElective int `json:"is_elective"` // 是否选修:0-非选修;1-选修
|
||
IsTry int `json:"is_try"` // 是否在目录中设置试看 0-否 1-是
|
||
PId string `json:"p_id"` // 父id(所属章节id)
|
||
SectionNum int `json:"section_num"` // 子小节数
|
||
SortValue int `json:"sort_value"` // 排序值(升序排序)
|
||
SubCourseId string `json:"sub_course_id"` // 所属子课程id
|
||
SubCourseSortValue int `json:"sub_course_sort_value"` // 所属子课程排序值(升序排序)
|
||
}
|
||
type GetCourseChapterListResponseData struct {
|
||
List []CourseChapter `json:"list"`
|
||
Total int `json:"total"`
|
||
}
|
||
|
||
type GetCourseChapterListResponse struct {
|
||
BaseResponse
|
||
|
||
Data GetCourseChapterListResponseData `json:"data"`
|
||
}
|
||
|
||
// MARK 获取课程列表
|
||
func (client *Client) GetCourseList(req *GetCourseListRequest) (*GetCourseListResponse, error) {
|
||
paramsMap, err := ToMap(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
respByte, err := client.CurlDo(http.MethodPost, GetCourseListUrl, paramsMap)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
resp := GetCourseListResponse{}
|
||
err = json.Unmarshal(respByte, &resp)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &resp, nil
|
||
}
|
||
|
||
// MARK 获取子课程列表
|
||
func (client *Client) GetSubCourseList(req *GetSubCourseListRequest) (*GetSubCourseListResponse, error) {
|
||
paramsMap, err := ToMap(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
respByte, err := client.CurlDo(http.MethodPost, GetSubCourseListUrl, paramsMap)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
resp := GetSubCourseListResponse{}
|
||
err = json.Unmarshal(respByte, &resp)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &resp, nil
|
||
}
|
||
|
||
// MARK 获取课程章节列表
|
||
func (client *Client) GetCourseChapterList(req *GetCourseChapterListRequest) (*GetCourseChapterListResponse, error) {
|
||
paramsMap, err := ToMap(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
respByte, err := client.CurlDo(http.MethodPost, GetCourseChapterListUrl, paramsMap)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
resp := GetCourseChapterListResponse{}
|
||
err = json.Unmarshal(respByte, &resp)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &resp, nil
|
||
}
|