123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854 |
- package manage
- import (
- "encoding/json"
- "fmt"
- "net/url"
- "qfw/coreconfig"
- cutil "qfw/coreutil"
- qutil "qfw/util"
- "qfw/util/mongodb"
- "strconv"
- "strings"
- "time"
- "github.com/go-xweb/log"
- "github.com/go-xweb/xweb"
- "github.com/pkg/errors"
- "gopkg.in/mgo.v2/bson"
- )
- //招投标课程相关接口
- type CourseManage struct {
- *xweb.Action
- index xweb.Mapper `xweb:"/manage/course/index"` //课程首页
- list xweb.Mapper `xweb:"/manage/course/list"` //请求课程列表
- createPage xweb.Mapper `xweb:"/manage/course/page/(\\w+)/(\\w+)"` //课程三级页
- createApi xweb.Mapper `xweb:"/manage/course/doRequest"` //课程三级页接口
- changeStatus xweb.Mapper `xweb:"/manage/course/changeStatus"` //上线or下线
- preview xweb.Mapper `xweb:"/manage/course/preview/(\\w+)/(\\w+)"` //课程预览
- previewGetDate xweb.Mapper `xweb:"/manage/course/previewGetDate"` //课程预览
- //课程订单
- orderIndex xweb.Mapper `xweb:"/manage/courseOrder/index"` //课程订单列表
- 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 {
- Success bool //是否成功
- Err error //错误
- Data map[string]interface{}
- }
- func (f *FuncResult) Format() *map[string]interface{} {
- errStr := ""
- if f.Err != nil {
- errStr = f.Err.Error()
- }
- return &map[string]interface{}{
- "success": f.Success,
- "errMsg": errStr,
- "data": f.Data,
- }
- }
- func init() {
- xweb.AddAction(&CourseManage{})
- }
- func (this *CourseManage) Preview(flag string, id string) {
- this.T["id"] = id
- if flag == "mobile" {
- this.Render("/manage/course/preview/course_detail_mobile.html")
- } else {
- this.Render("/manage/course/preview/course_detail_pc.html")
- }
- }
- func (this *CourseManage) PreviewGetDate() {
- _id := this.GetString("_id") //课程id
- showAbout := this.GetString("aboutFlag") //是否需要相关课程
- r := func() *FuncResult {
- if _id == "" {
- return &FuncResult{false, errors.New("信息id为空"), nil}
- }
- //课程基本信息
- rData := mongodb.FindById("jy_course", _id, `{"i_type":1,"s_address":1,"i_status":1,"s_name":1,"i_price":1,"l_starttime":1,"l_endtime":1,"s_content":1,"s_discountPlan":1,"_id":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_starttime"]), 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
- i_type := qutil.IntAll((*rData)["i_type"])
- if showAbout != "" {
- //相关课程信息
- s_name := (*rData)["s_name"]
- queryAbout := bson.M{"i_type": i_type, "s_name": s_name, "i_status": bson.M{"$in": []int{1, -1}}, "_id": bson.M{"$ne": bson.ObjectIdHex(_id)}} //查询已发布or已结束的课程
- aboutList := mongodb.Find("jy_course", queryAbout, `{"l_publishtime":-1}`,
- `{"_id":1,"i_type":1,"s_address":1,"i_status":1,"s_name":1,"i_price":1,"l_starttime":1}`, false, 0, 3)
- for _, v := range *aboutList {
- v["l_starttime"] = time.Unix(qutil.Int64All(v["l_starttime"]), 0).Format(qutil.Date_Short_Layout)
- v["l_endtime"] = time.Unix(qutil.Int64All(v["l_endtime"]), 0).Format(qutil.Date_Short_Layout)
- v["l_publishtime"] = time.Unix(qutil.Int64All(v["l_publishtime"]), 0).Format(qutil.Date_Short_Layout)
- v["_id"] = qutil.EncodeArticleId2ByCheck(qutil.BsonIdToSId(v["_id"]))
- }
- 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) GetDetail() error {
- orderCode := this.GetString("orderCode")
- if orderCode != "" {
- dotype := this.GetString("rt")
- qMap := map[string]interface{}{}
- qMap["order_code"] = orderCode
- res := cutil.Mysql.FindOne("dataexport_order", qMap, "", "create_time desc")
- log.Println("res:", (*res)["filter"])
- var filter = qutil.ObjToMap((*res)["filter"])
- if dotype == "1" { //获取订单信息
- if len(*res) > 0 {
- resInv := cutil.Mysql.FindOne("apply_invoice", map[string]interface{}{"order_id": (*res)["id"]}, "", "apply_date desc")
- pay_way := (*res)["pay_way"]
- var dataBase = "ali_pay"
- if strings.Index(pay_way.(string), "wx") > -1 {
- dataBase = "weixin_pay"
- }
- payMap := map[string]interface{}{}
- payMap["out_trade_no"] = (*res)["out_trade_no"]
- payInfo := cutil.Mysql.FindOne(dataBase, payMap, "", "create_time desc")
- if payInfo != nil {
- (*res)["transaction_id"] = (*payInfo)["transaction_id"]
- }
- filter_id := qutil.ObjToString((*res)["filter_id"])
- if strings.Contains(filter_id, "ABC") {
- filter_id = qutil.DecodeArticleId2ByCheck(filter_id)[0]
- }
- resCour := mongodb.FindById("jy_course", filter_id, nil)
- this.ServeJson(map[string]interface{}{
- "res": res,
- "resInv": resInv,
- "resCour": resCour,
- })
- }
- } else if dotype == "2" { //确认退款
- nw := time.Now().Unix()
- (*filter)["adminRefundTime"] = qutil.FormatDateByInt64(&nw, qutil.Date_Full_Layout)
- datailMsg, _ := json.Marshal(*filter)
- id := cutil.Mysql.UpdateOrDeleteBySql("UPDATE dataexport_order SET course_status = 6,filter='" + string(datailMsg) + "' WHERE order_code = " + orderCode)
- this.ServeJson(map[string]interface{}{
- "id": id,
- })
- } else if dotype == "3" { //审核凭证提交
- nw := time.Now().Unix()
- agreeN := this.GetString("agreeN")
- order_status := "0"
- course_status := "2"
- if agreeN == "1" { //不通过
- course_status = "3"
- } else {
- course_status = "4"
- order_status = "1"
- }
- (*filter)["adminTransferVTime"] = qutil.FormatDateByInt64(&nw, qutil.Date_Full_Layout)
- datailMsg, _ := json.Marshal(*filter)
- updateSql := "UPDATE dataexport_order SET course_status = " + course_status + ",filter_publishtime=" + strconv.FormatInt(nw, 10) + ",order_status=" + order_status
- updateSql += ",filter = '" + string(datailMsg) + "'"
- if agreeN == "2" {
- updateSql += ",pay_time='" + qutil.FormatDateByInt64(&nw, qutil.Date_Full_Layout) + "'"
- }
- updateSql += " WHERE order_code = " + orderCode
- id := cutil.Mysql.UpdateOrDeleteBySql(updateSql)
- this.ServeJson(map[string]interface{}{
- "id": id,
- "pay_time": qutil.FormatDateByInt64(&nw, qutil.Date_Full_Layout),
- })
- }
- }
- return nil
- }
- //课程订单详情
- func (this *CourseManage) OrderDetail(orderCode string) error {
- this.T["orderCode"] = orderCode
- return this.Render("/manage/course/order_detail.html")
- }
- //课程订单列表
- func (this *CourseManage) OrderIndex() error {
- return this.Render("/manage/course/order_index.html")
- }
- //课程首页
- func (this *CourseManage) Index() error {
- return this.Render("/manage/course/index.html")
- }
- //请求课程列表
- func (this *CourseManage) OrderList() {
- currentPage, _ := this.GetInteger("currentPage")
- perPage, _ := this.GetInteger("perPage")
- c_status := this.GetString("strSel1") //订单状态 0:未支付 1:已支付 -1:已删除 -2:已取消
- 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 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 {
- c_status = "-1"
- sql += `order_status !=` + fmt.Sprint(c_status)
- }
- if c_type == "1" {
- query := map[string]interface{}{
- "s_name": c_content,
- }
- res := mongodb.Find("jy_course", query, `{"l_publishtime":-1}`, `{"_id":1}`, false, -1, -1)
- log.Println("res:", *res)
- var a_id = ""
- for _, v := range *res {
- if a_id != "" {
- a_id += ","
- }
- a_id += "'" + qutil.BsonIdToSId(v["_id"]) + "'"
- }
- sql += ` and filter_id in (` + a_id + `)`
- } else if c_type == "0" {
- sql += ` and order_code ='` + c_content + `'`
- } else if c_type == "2" {
- sql += ` and filter like '%"name":"` + c_content + `"%'`
- } else if c_type == "3" {
- sql += ` and user_phone ='` + c_content + `'`
- }
- c_sql = c_sql + sql
- c_sql += ` order by create_time desc limit ` + fmt.Sprint((currentPage-1)*perPage) + `,` + fmt.Sprint(perPage)
- log.Println("sql:", c_sql)
- rData := cutil.Mysql.SelectBySql(c_sql)
- if len(*rData) > 0 {
- for _, v := range *rData {
- filter := qutil.ObjToMap(v["filter"])
- v["courseType"] = (*filter)["courseType"]
- }
- }
- c_sql_c = c_sql_c + sql
- count := cutil.Mysql.CountBySql(c_sql_c)
- this.ServeJson(map[string]interface{}{
- "currentPage": currentPage,
- "data": rData,
- "totalRows": count,
- })
- }
- //请求课程列表
- func (this *CourseManage) List() {
- currentPage, _ := this.GetInteger("currentPage")
- perPage, _ := this.GetInteger("perPage")
- c_status := this.GetString("strSel1") //报名状态 1 报名中 2 结束 0未发布
- c_type := this.GetString("strSel2") //课程类型 1 招标 2 投标
- queryStr := this.GetString("query")
- query := map[string]interface{}{}
- if c_status != "" {
- query["i_status"] = qutil.IntAll(c_status)
- }
- if c_type != "" {
- query["i_type"] = qutil.IntAll(c_type)
- }
- 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{}{
- "currentPage": currentPage,
- "data": rData,
- "totalRows": count,
- })
- }
- //课程三级页
- func (this *CourseManage) CreatePage(flag, id string) error {
- if flag == "edit" || flag == "copy" {
- //获取文章详情
- if id == "" {
- return errors.New("请求参数有误")
- }
- rData := mongodb.FindById("jy_course", id, "")
- this.T["type"] = (*rData)["i_type"]
- this.T["name"] = (*rData)["s_name"]
- this.T["address"] = (*rData)["s_address"]
- this.T["price"] = (*rData)["i_price"]
- this.T["publishtime"] = time.Unix(qutil.Int64All((*rData)["l_publishtime"]), 0).Format(qutil.Date_Full_Layout)
- this.T["starttime"] = time.Unix(qutil.Int64All((*rData)["l_starttime"]), 0).Format(qutil.Date_Full_Layout)
- this.T["endtime"] = time.Unix(qutil.Int64All((*rData)["l_endtime"]), 0).Format(qutil.Date_Full_Layout)
- this.T["content"] = (*rData)["s_content"]
- this.T["status"] = (*rData)["i_status"]
- this.T["id"] = id
- }
- this.T["doType"] = flag
- this.Render("/manage/course/content.html")
- return nil
- }
- func (this *CourseManage) CreateApi() {
- c_type, _ := this.GetInteger("c_type") //课程类型
- name := this.GetString("name")
- address := this.GetString("address")
- price, _ := this.GetInt("price")
- s_starttime := this.GetString("starttime")
- s_endtime := this.GetString("endtime")
- s_publishtime := this.GetString("publishtime")
- d_content := this.GetString("content")
- Dotype := this.GetString("dotype") //克隆 or 新增 or 修改
- courseName := "招标管理课程"
- if c_type == 2 {
- courseName = "投标实务课程"
- }
- log.Println(coreconfig.DiscountConfig)
- dplan := coreconfig.DiscountConfig
- var pmap []map[string]interface{}
- if dplan != nil {
- pmap = qutil.ObjArrToMapArr(dplan[courseName].([]interface{}))
- } else {
- log.Println("添加优惠信息有误")
- }
- // discountPlan := this.GetString("discountPlan")
- // err := json.Unmarshal([]byte(discountPlan), &pmap)
- // if err != nil {
- // log.Println("err:", err)
- // }
- r := func() *FuncResult {
- //数据校验
- if name == "" || address == "" || d_content == "" || Dotype == "" || c_type == 0 ||
- price == 0 || s_publishtime == "" || s_starttime == "" || s_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}
- }
- log.Println("start:", s_starttime)
- starttime, err := time.ParseInLocation(qutil.Date_Full_Layout, s_starttime, time.Local)
- if err != nil {
- return &FuncResult{false, errors.New("课程时间异常"), nil}
- }
- log.Println("s_endtime:", s_endtime)
- endtime, err := time.ParseInLocation(qutil.Date_Full_Layout, s_endtime, time.Local)
- if err != nil {
- return &FuncResult{false, errors.New("课程时间异常"), nil}
- }
- if endtime.Before(starttime) {
- 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 !(price > 0) {
- return &FuncResult{false, errors.New("课程金额异常"), nil}
- }
- //数据校验
- mData := map[string]interface{}{
- "s_name": name,
- "i_type": c_type,
- "s_address": address,
- "i_price": price,
- "l_publishtime": publishtime.Unix(),
- "l_starttime": starttime.Unix(),
- "l_endtime": endtime.Unix(),
- "s_content": content,
- "s_discountPlan": pmap, //课程优惠内容
- }
- if Dotype == "add" || Dotype == "copy" {
- flag := this.GetString("flag") //保存 or 立即发布
- if flag == "publish" {
- mData["i_status"] = 1 //立即发布
- if time.Now().After(starttime) {
- return &FuncResult{false, errors.New("开课时间已到,禁止发布"), nil}
- }
- } else {
- mData["i_status"] = 0 //暂时保存
- }
- 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}
- }
- 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) ChangeStatus() {
- flag := this.GetString("flag")
- _id := this.GetString("id")
- r := func() *FuncResult {
- if !(flag == "off" || flag == "on" || flag == "del") {
- 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_starttime":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_starttime"]), 0).Before(time.Now()) {
- return &FuncResult{false, errors.New("开课时间已到,禁止发布"), nil}
- }
- if (*rData)["i_status"] == 0 {
- 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}
- }
- }
- } else if flag == "del" {
- status := []int{0, -1} //只能删除已下线或者未发布的
- ok := mongodb.Update("jy_course", &map[string]interface{}{
- "_id": qutil.StringTOBsonId(_id),
- "i_status": bson.M{"$in": status},
- }, &map[string]interface{}{
- "$set": bson.M{"i_status": -2},
- }, 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}
- }
- }
- 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) 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}
- }
- /*if picUrl != "" {
- //生成访问地址
- b, _, m := cutil.FileRedis(picUrl,"img")
- if b == false{
- return &FuncResult{false, errors.New(fmt.Sprintf("%s", m)), nil}
- }
- }
- if videoUrl != "" {
- //生成访问地址
- b, _, m := cutil.FileRedis(videoUrl,"")
- if b == false{
- return &FuncResult{false, errors.New(fmt.Sprintf("%s", m)), nil}
- }
- }
- if fileUrl != "" {
- //生成访问地址
- b, _, m := cutil.FileRedis(fileUrl,"file")
- if b == false{
- return &FuncResult{false, errors.New(fmt.Sprintf("%s", m)), nil}
- }
- }*/
- if videoUrl != "" {
- //生成访问地址
- b, st := cutil.SetTxVideoRedis(videoUrl)
- if b == false{
- return &FuncResult{false, errors.New(fmt.Sprintf("%s", st)), nil}
- }
- }
- publishtime, err := time.ParseInLocation(qutil.Date_Full_Layout, s_publishtime, time.Local)
- if err != nil {
- //return &FuncResult{false, errors.New("发布时间异常"), nil}
- publishtime , err = time.ParseInLocation(qutil.Date_Full_Layout, time.Now().Format("2006-01-02 15:04:05"), time.Local)
- }
- 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")
- infoId := this.GetString("infoId")
- 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}
- if infoId != ""{
- query["_id"] = bson.M{"$ne": bson.ObjectIdHex(infoId)}
- }
- }
- 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")
- }
|