|
@@ -33,6 +33,14 @@ type CourseManage struct {
|
|
|
orderDetail xweb.Mapper `xweb:"/manage/courseOrder/detail/(\\w+)"` //课程订单详情
|
|
|
orderList xweb.Mapper `xweb:"/manage/courseOrder/list"` //请求课程订单列表
|
|
|
getDetail xweb.Mapper `xweb:"/manage/courseOrder/getDetail"` //请求课程订单详情
|
|
|
+
|
|
|
+ //线上课程
|
|
|
+ onLineIndex xweb.Mapper `xweb:"/manage/course/onLineIndex"` //线上课程首页
|
|
|
+ createOnLineApi xweb.Mapper `xweb:"/manage/course/OnLineRequest"` //线上课程新增、修改
|
|
|
+ onLineClickTradeRate xweb.Mapper `xweb:"/manage/course/OnLineClickTradeRate"` //线上课程点击量、购买量
|
|
|
+ onLineList xweb.Mapper `xweb:"/manage/course/OnLineList"` //线上课程列表
|
|
|
+ onLineChangeStatus xweb.Mapper `xweb:"/manage/course/OnLineChangeStatus"` //上线or下线
|
|
|
+ onLineDetail xweb.Mapper `xweb:"/manage/course/OnLineDetail/(\\w+)/(\\w+)"` //课程详情
|
|
|
}
|
|
|
|
|
|
type FuncResult struct {
|
|
@@ -190,8 +198,8 @@ func (this *CourseManage) OrderList() {
|
|
|
c_type := this.GetString("strSel2") //请求类型 0:订单编号 1:课程名称 2:联系人(订单表中 user_nickname 暂存联系人信息) 3:联系人手机号
|
|
|
c_content := this.GetString("strCont")
|
|
|
var sql = ``
|
|
|
- var c_sql = `SELECT order_status,order_code,pay_time,filter,applybill_status,pay_money,order_money,course_status,pay_way FROM dataexport_order WHERE product_type = '招投标课程' and `
|
|
|
- var c_sql_c = `SELECT count(*) FROM dataexport_order WHERE product_type = '招投标课程' and `
|
|
|
+ var c_sql = `SELECT order_status,order_code,pay_time,filter,applybill_status,pay_money,order_money,course_status,pay_way FROM dataexport_order WHERE product_type in ('招投标课程','线上课程') and `
|
|
|
+ var c_sql_c = `SELECT count(*) FROM dataexport_order WHERE product_type in ('招投标课程','线上课程') and `
|
|
|
if c_status != "" {
|
|
|
sql += `order_status =` + fmt.Sprint(c_status)
|
|
|
} else {
|
|
@@ -257,6 +265,10 @@ func (this *CourseManage) List() {
|
|
|
if queryStr != "" {
|
|
|
query["s_name"] = bson.M{"$regex": queryStr}
|
|
|
}
|
|
|
+ //课程类型不等于3
|
|
|
+ query1 := map[string]int32{}
|
|
|
+ query1["$ne"] = 3
|
|
|
+ query["i_type"] = query1
|
|
|
rData := mongodb.Find("jy_course", query, `{"l_publishtime":-1}`, `{"_id":1,"i_type":1,"s_address":1,"i_status":1,"s_name":1,"l_publishtime":1}`, false, (currentPage-1)*perPage, perPage)
|
|
|
count := mongodb.Count("jy_course", query)
|
|
|
this.ServeJson(map[string]interface{}{
|
|
@@ -474,3 +486,325 @@ func (this *CourseManage) ChangeStatus() {
|
|
|
}
|
|
|
this.ServeJson(r.Format())
|
|
|
}
|
|
|
+
|
|
|
+func (this *CourseManage) CreateOnLineApi() {
|
|
|
+ c_type, _ := this.GetInteger("type") //课程类型:线下课程(1招标管理课程、2投标实物课程)、3线上课程
|
|
|
+ name := this.GetString("name")//课程名称
|
|
|
+ picUrl := this.GetString("picUrl")//头图
|
|
|
+ price := this.GetString("price")//课程金额
|
|
|
+ if price == "" {
|
|
|
+ price = "0"
|
|
|
+ }
|
|
|
+ price2 := fmt.Sprintf("%.2f", qutil.Float64All(price))
|
|
|
+ pos := strings.Index(price2, ".")
|
|
|
+ price3 := qutil.Int64All(price2[:pos] + price2[pos+1:])
|
|
|
+ videoUrl := this.GetString("videoUrl")//课程视频
|
|
|
+ fileUrl := this.GetString("fileUrl")//课件
|
|
|
+ s_publishtime := this.GetString("publishtime")//发布时间/上线时间
|
|
|
+ d_content := this.GetString("content")//课程详情
|
|
|
+ Dotype := this.GetString("dotype") //新增add or 修改edit
|
|
|
+ //status := this.GetString("status") //1上线、0草稿、-1未发布
|
|
|
+ courseDate := this.GetString("courseDate")//课程时长
|
|
|
+ endTime := this.GetString("endTime")//课程有效截止时间
|
|
|
+ associatedCourses := this.GetString("associatedCourses")//关联课程
|
|
|
+ //updateTime := this.GetString("updateTime")//课程内容更新时间
|
|
|
+ //createTime := time.Now().Unix()
|
|
|
+ //clickRate := 0//点击量默认0次
|
|
|
+ //tradeRate := 0//购买量默认0次
|
|
|
+
|
|
|
+ r := func() *FuncResult {
|
|
|
+ //数据校验
|
|
|
+ if name == "" || picUrl == "" || videoUrl == "" || c_type != 3 ||
|
|
|
+ courseDate == "" || endTime == "" {
|
|
|
+ return &FuncResult{false, errors.New("参数不完整"), nil}
|
|
|
+ }
|
|
|
+ publishtime, err := time.ParseInLocation(qutil.Date_Full_Layout, s_publishtime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return &FuncResult{false, errors.New("发布时间异常"), nil}
|
|
|
+ }
|
|
|
+ l_endTime, err := time.ParseInLocation(qutil.Date_Full_Layout, endTime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return &FuncResult{false, errors.New("课程截止时间异常"), nil}
|
|
|
+ }
|
|
|
+ //
|
|
|
+ d1_content, err := url.QueryUnescape(d_content)
|
|
|
+ if err != nil {
|
|
|
+ return &FuncResult{false, errors.New("课程内容解析异常"), nil}
|
|
|
+ }
|
|
|
+ content, err := url.QueryUnescape(d1_content)
|
|
|
+ if err != nil {
|
|
|
+ return &FuncResult{false, errors.New("课程内容解析异常"), nil}
|
|
|
+ }
|
|
|
+ /*if err1 != nil {
|
|
|
+ return &FuncResult{false, errors.New("课程金额异常"), nil}
|
|
|
+ }*/
|
|
|
+ //数据校验
|
|
|
+ mData := map[string]interface{}{
|
|
|
+ "s_name": name,
|
|
|
+ "i_type": c_type,
|
|
|
+ "s_picUrl": picUrl,
|
|
|
+ "s_videoUrl": videoUrl,
|
|
|
+ "s_fileUrl": fileUrl,
|
|
|
+ "i_price": price3,
|
|
|
+ "l_publishtime": publishtime.Unix(),
|
|
|
+ //"l_createtime": createTime,
|
|
|
+ "l_endtime": l_endTime.Unix(),
|
|
|
+ "s_content": content,
|
|
|
+ "s_courseDate": courseDate,
|
|
|
+ "s_associatedCourses": associatedCourses,
|
|
|
+ //"i_clickRate": clickRate,
|
|
|
+ //"i_tradeRate": tradeRate,
|
|
|
+ }
|
|
|
+ if Dotype == "add" || Dotype == "copy" {
|
|
|
+ mData["i_clickRate"] = 0
|
|
|
+ mData["i_tradeRate"] = 0
|
|
|
+ flag := this.GetString("flag") //保存 or 立即发布
|
|
|
+ if flag == "publish" {
|
|
|
+ mData["i_status"] = 1 //立即发布
|
|
|
+ if time.Now().After(l_endTime) {
|
|
|
+ return &FuncResult{false, errors.New("课程截止时间已到,禁止发布"), nil}
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mData["i_status"] = 0 //暂时保存
|
|
|
+ }
|
|
|
+ mData["l_createTime"] = time.Now().Unix()
|
|
|
+ if mongodb.Save("jy_course", mData) == "" {
|
|
|
+ return &FuncResult{false, errors.New("增加课程失败"), nil}
|
|
|
+ } else {
|
|
|
+ return &FuncResult{true, nil, nil}
|
|
|
+ }
|
|
|
+ } else if Dotype == "edit" {
|
|
|
+ id := this.GetString("_id")
|
|
|
+ if id == "" {
|
|
|
+ return &FuncResult{false, errors.New("操作课程信息id为空"), nil}
|
|
|
+ }
|
|
|
+ flag := this.GetString("flag") //保存 or 立即发布
|
|
|
+ if flag == "publish" {
|
|
|
+ mData["i_status"] = 1 //立即发布
|
|
|
+ if time.Now().After(l_endTime) {
|
|
|
+ return &FuncResult{false, errors.New("课程截止时间已到,禁止发布"), nil}
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mData["i_status"] = 0 //暂时保存
|
|
|
+ }
|
|
|
+ mData["l_updateTime"] = time.Now().Unix()
|
|
|
+ updateFlag := mongodb.Update("jy_course", &map[string]interface{}{
|
|
|
+ "_id": qutil.StringTOBsonId(id),
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$set": mData,
|
|
|
+ }, false, false)
|
|
|
+ if !updateFlag {
|
|
|
+ return &FuncResult{false, errors.New("修改课程失败"), nil}
|
|
|
+ } else {
|
|
|
+ return &FuncResult{true, nil, nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return &FuncResult{false, errors.New("未知操作"), nil}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("CreateApi err:%v\n", r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
+}
|
|
|
+func (this *CourseManage) OnLineClickTradeRate() {
|
|
|
+ _id := this.GetString("_id")//课程id
|
|
|
+ s_type := this.GetString("type")//类型click:点击量、trade:购买量
|
|
|
+ r := func() *FuncResult {
|
|
|
+ if _id != "" {
|
|
|
+ rData := mongodb.FindById("jy_course", _id, `"i_status":1,"l_starttime":1`)
|
|
|
+ if rData == nil || len(*rData) == 0 {
|
|
|
+ return &FuncResult{false, errors.New("未知信息_id"), nil}
|
|
|
+ }
|
|
|
+ if (*rData)["i_status"] == -1 {
|
|
|
+ return &FuncResult{false, errors.New("当状态下的信息不能增加购买量或点击量"), nil}
|
|
|
+ }
|
|
|
+ if s_type == "click" {
|
|
|
+ ok := mongodb.Update("jy_course", &map[string]interface{}{
|
|
|
+ "_id": qutil.StringTOBsonId(_id),
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$inc": bson.M{"i_clickRate": 1},
|
|
|
+ }, false, false)
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ return &FuncResult{true, nil, nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if s_type == "trade" {
|
|
|
+ ok := mongodb.Update("jy_course", &map[string]interface{}{
|
|
|
+ "_id": qutil.StringTOBsonId(_id),
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$inc": bson.M{"i_tradeRate": 1},
|
|
|
+ }, false, false)
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ return &FuncResult{true, nil, nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return &FuncResult{false, errors.New("课程id不能为空"), nil}
|
|
|
+ }
|
|
|
+ return &FuncResult{false, errors.New("未知操作"), nil}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("CreateApi err:%v\n", r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
+}
|
|
|
+
|
|
|
+func (this *CourseManage) OnLineList() {
|
|
|
+ currentPage, _ := this.GetInteger("currentPage")
|
|
|
+ perPage, _ := this.GetInteger("perPage")
|
|
|
+ queryStr := this.GetString("query")
|
|
|
+ flag := this.GetString("flag")
|
|
|
+ query := map[string]interface{}{}
|
|
|
+ if queryStr != "" {
|
|
|
+ query["s_name"] = bson.M{"$regex": queryStr}
|
|
|
+ }
|
|
|
+ if flag == "gl" {
|
|
|
+ now := time.Now().Unix()
|
|
|
+ query["i_status"] = 1
|
|
|
+ query["l_publishtime"] = bson.M{"$lt":now}
|
|
|
+ query["l_endtime"] = bson.M{"$gt":now}
|
|
|
+ }
|
|
|
+ query["i_type"] = 3
|
|
|
+ rData := mongodb.Find("jy_course", query, `{"l_publishtime":-1}`, `{"_id":1,"s_courseDate":1,"i_price":1,"i_status":1,"s_name":1,"l_publishtime":1}`, false, (currentPage-1)*perPage, perPage)
|
|
|
+ count := mongodb.Count("jy_course", query)
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "currentPage": currentPage,
|
|
|
+ "data": rData,
|
|
|
+ "totalRows": count,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (this *CourseManage) OnLineChangeStatus() {
|
|
|
+ flag := this.GetString("flag")
|
|
|
+ _id := this.GetString("id")
|
|
|
+ r := func() *FuncResult {
|
|
|
+ if !(flag == "off" || flag == "on") {
|
|
|
+ return &FuncResult{false, errors.New("未知操作"), nil}
|
|
|
+ }
|
|
|
+ if _id == "" {
|
|
|
+ return &FuncResult{false, errors.New("未获取到信息_id"), nil}
|
|
|
+ }
|
|
|
+ rData := mongodb.FindById("jy_course", _id, `"i_status":1,"l_endtime":1`)
|
|
|
+ if rData == nil || len(*rData) == 0 {
|
|
|
+ return &FuncResult{false, errors.New("未知信息_id"), nil}
|
|
|
+ }
|
|
|
+ if (*rData)["i_status"] == -2 {
|
|
|
+ return &FuncResult{false, errors.New("当前信息状态不能更改"), nil}
|
|
|
+ }
|
|
|
+ if flag == "off" { //下线
|
|
|
+ if (*rData)["i_status"] == 1 {
|
|
|
+ ok := mongodb.Update("jy_course", &map[string]interface{}{
|
|
|
+ "_id": qutil.StringTOBsonId(_id),
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$set": bson.M{"i_status": -1},
|
|
|
+ }, false, false)
|
|
|
+ //通过课程id查询该课程相关的订单
|
|
|
+ var updateSql = `UPDATE dataexport_order SET order_status = -2 WHERE order_status = 0 AND product_type = '招投标课程' AND filter_id = '` + _id + `'`
|
|
|
+ go cutil.Mysql.UpdateOrDeleteBySql(updateSql)
|
|
|
+ if ok {
|
|
|
+ return &FuncResult{true, nil, nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if flag == "on" { //发布
|
|
|
+ //校验开课时间是否已到
|
|
|
+ if time.Unix(qutil.Int64All((*rData)["l_endtime"]), 0).Before(time.Now()) {
|
|
|
+ return &FuncResult{false, errors.New("课程截止时间已到,禁止上线"), nil}
|
|
|
+ }
|
|
|
+ if (*rData)["i_status"] == 0 || (*rData)["i_status"] == -1{
|
|
|
+ ok := mongodb.Update("jy_course", &map[string]interface{}{
|
|
|
+ "_id": qutil.StringTOBsonId(_id),
|
|
|
+ }, &map[string]interface{}{
|
|
|
+ "$set": bson.M{"i_status": 1},
|
|
|
+ }, false, false)
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ return &FuncResult{true, nil, nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return &FuncResult{false, errors.New("信息状态修改非法"), nil}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("CreateApi err:%v\n", r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
+}
|
|
|
+
|
|
|
+func (this *CourseManage) OnLineDetail(flag, id string) error{
|
|
|
+ if flag == "edit" {
|
|
|
+ //获取文章详情
|
|
|
+ if id == "" {
|
|
|
+ return errors.New("请求参数有误")
|
|
|
+ }
|
|
|
+ rData := mongodb.FindById("jy_course", id, `{"_id":1,"i_status":1,"s_content":1,"s_name":1,"s_picUrl":1,"i_price":1,"l_publishtime":1,"l_endtime":1,"s_associatedCourses":1,"i_clickRate":1,"s_videoUrl":1,"s_fileUrl":1,"s_courseDate":1,"i_tradeRate":1}`)
|
|
|
+ this.T["picUrl"] = (*rData)["s_picUrl"]
|
|
|
+ this.T["name"] = (*rData)["s_name"]
|
|
|
+ this.T["videoUrl"] = (*rData)["s_videoUrl"]
|
|
|
+ this.T["fileUrl"] = (*rData)["s_fileUrl"]
|
|
|
+ this.T["price"] = fmt.Sprintf("%.2f", qutil.Float64All((*rData)["i_price"])/100)
|
|
|
+ this.T["endTime"] = time.Unix(qutil.Int64All((*rData)["l_endtime"]), 0).Format(qutil.Date_Full_Layout)
|
|
|
+ this.T["courseDate"] = (*rData)["s_courseDate"]
|
|
|
+ this.T["content"] = (*rData)["s_content"]
|
|
|
+ this.T["status"] = (*rData)["i_status"]
|
|
|
+ ids := (*rData)["s_associatedCourses"]
|
|
|
+ var idSlice []bson.ObjectId
|
|
|
+ if ids != "" {
|
|
|
+ arr := strings.Split(ids.(string), ",")
|
|
|
+ for _, as := range arr{
|
|
|
+ idSlice = append(idSlice, bson.ObjectIdHex(as))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ now := time.Now().Unix()
|
|
|
+ queryAbout := bson.M{"i_type": 3, "i_status": 1, "_id": bson.M{"$in":idSlice}, "l_publishtime": bson.M{"$lt":now}, "l_endtime": bson.M{"$gt":now}}
|
|
|
+ aboutList := mongodb.Find("jy_course", queryAbout, `{"l_publishtime":-1}`,
|
|
|
+ `{"_id":1,"s_name":1}`, false, 0, 0)
|
|
|
+ this.T["associatedCourses"] = aboutList
|
|
|
+ this.T["publishtime"] = time.Unix(qutil.Int64All((*rData)["l_publishtime"]), 0).Format(qutil.Date_Full_Layout)
|
|
|
+ this.T["id"] = id
|
|
|
+ }
|
|
|
+ this.T["doType"] = flag
|
|
|
+ this.Render("/manage/course/onLineContent.html")
|
|
|
+ return nil
|
|
|
+ /*_id := this.GetString("_id") //课程id
|
|
|
+ r := func() *FuncResult {
|
|
|
+ if _id == "" {
|
|
|
+ return &FuncResult{false, errors.New("信息id为空"), nil}
|
|
|
+ }
|
|
|
+ //课程基本信息
|
|
|
+ rData := mongodb.FindById("jy_course", _id, `{"_id":1,"s_content":1,"s_name":1,"s_picUrl":1,"i_price":1,"l_publishtime":1,"l_endtime":1,"s_associatedCourses":1,"i_clickRate":1,"s_videoUrl":1,"s_fileUrl":1,"s_courseDate":1,"i_tradeRate":1}`)
|
|
|
+ if rData == nil || len(*rData) == 0 {
|
|
|
+ return &FuncResult{false, errors.New("未找到此课程的信息"), nil}
|
|
|
+ }
|
|
|
+ resultMap := map[string]interface{}{}
|
|
|
+ (*rData)["l_starttime"] = time.Unix(qutil.Int64All((*rData)["l_publishtime"]), 0).Format("2006-01-02 15:04")
|
|
|
+ (*rData)["l_endtime"] = time.Unix(qutil.Int64All((*rData)["l_endtime"]), 0).Format(qutil.Date_Short_Layout)
|
|
|
+ resultMap["detail"] = rData
|
|
|
+
|
|
|
+ if (*rData)["s_associatedCourses"] != "" {
|
|
|
+ //相关课程信息
|
|
|
+ ids := (*rData)["s_associatedCourses"]
|
|
|
+ arr := strings.Split(ids.(string), ",")
|
|
|
+ var idSlice []bson.ObjectId
|
|
|
+ for _, as := range arr{
|
|
|
+ idSlice = append(idSlice, bson.ObjectIdHex(as))
|
|
|
+ }
|
|
|
+ now := time.Now().Unix()
|
|
|
+ queryAbout := bson.M{"i_type": 3, "i_status": 1, "_id": bson.M{"$in":idSlice}, "l_publishtime": bson.M{"$lt":now}, "l_endtime": bson.M{"$gt":now}}
|
|
|
+ aboutList := mongodb.Find("jy_course", queryAbout, `{"l_publishtime":-1}`,
|
|
|
+ `{"_id":1,"s_name":1}`, false, 0, 0)
|
|
|
+ resultMap["aboutList"] = aboutList
|
|
|
+ }
|
|
|
+ return &FuncResult{true, nil, resultMap}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf(" CourseContent err:%v\n", r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())*/
|
|
|
+}
|
|
|
+
|
|
|
+//线上课程首页
|
|
|
+func (this *CourseManage) OnLineIndex() error {
|
|
|
+ return this.Render("/manage/course/onLineIndex.html")
|
|
|
+}
|