123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/models/order"
- "hongze/hongze_mfyx/services"
- "hongze/hongze_mfyx/utils"
- "strings"
- "time"
- )
- // 订单
- type OrderController struct {
- BaseAuthController
- }
- // @Title 通过文章创建订单
- // @Description 通过文章创建订单接口
- // @Param request body models.ActivitySingnupRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /addByArticle [post]
- func (this *OrderController) AddByArticle() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req order.CygxOrderAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- goodsId := req.GoodsId
- sourceId := req.SourceId
- if goodsId == 0 {
- br.Msg = "支付失败"
- br.ErrMsg = "支付失败,goodsId 信息错误Err:" + err.Error()
- return
- }
- goodsDetail, err := order.GetCygxGoodsDetailByGoodsId(goodsId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- var title string
- oldOrderCode := services.GetHaverEquallyOrderByUser10Min(uid, goodsId) //获取用户十分钟之内是否有相同的订单信息
- articleDetail, err := models.GetArticleDetailById(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- title = articleDetail.Title
- item := new(order.CygxOrder)
- item.OrderCode = utils.GetOrdernum()
- item.OutTradeNo = "TRADE" + item.OrderCode
- item.GoodsName = goodsDetail.GoodsName
- item.GoodsId = goodsId
- item.GoodsMoney = goodsDetail.Price
- item.OrderMoney = goodsDetail.CurrentPrice
- item.SourceId = sourceId
- item.Source = utils.CYGX_OBJ_ARTICLE
- item.SourceTitle = title
- item.UserId = user.UserId
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.RealName = user.RealName
- item.SellerName, item.SellerId = services.GetSellerName(user) // 销售姓名
- item.ShareName, item.ShareId = services.GetAdminByInviteShareCode(req.InviteShareCode) // 分享人信息
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- item.OrderType = 1
- //如果十分钟之内有相同的订单就修改,没有就新增
- if oldOrderCode == "" {
- err = order.AddCygxOrder(item)
- } else {
- item.OrderCode = oldOrderCode
- err = order.UpdateCygxOrder(item, oldOrderCode)
- }
- if err != nil {
- br.Msg = "创建订单信息失败"
- br.ErrMsg = "创建订单信息失败,Err:" + err.Error()
- return
- }
- JsapiApiResp, err := services.ExampleJsapiApiServicePrepay(item, user.UnionId)
- if err != nil {
- br.Msg = "创建订单信息失败"
- br.ErrMsg = "创建订单信息失败,ExampleJsapiApiServicePrepayErr:" + err.Error()
- return
- }
- resp := new(order.WxJsapiApiResp)
- resp.Detail = JsapiApiResp
- resp.OrderCode = item.OrderCode
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 通过活动创建订单
- // @Description 通过活动创建订单接口
- // @Param request body models.ActivitySingnupRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /addByActivity [post]
- func (this *OrderController) AddByActivity() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req order.CygxOrderAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- goodsId := req.GoodsId
- sourceId := req.SourceId
- source := req.Source
- if goodsId == 0 {
- br.Msg = "支付失败"
- br.ErrMsg = "支付失败,goodsId 信息错误Err:" + err.Error()
- return
- }
- goodsDetail, err := order.GetCygxGoodsDetailByGoodsId(goodsId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- activityDetail, err := models.GetAddActivityInfoById(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- var title string
- var oldOrderCode string
- var payTimeCountdown int
- //var _ int
- item := new(order.CygxOrder)
- if source == "ActivityVivo" {
- oldOrderCode, payTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivtyVivo(uid, sourceId)
- item.OrderType = 3
- } else {
- if (!activityDetail.IsResearchPoints && activityDetail.IsLimitPeople == 0) || activityDetail.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)走月卡日卡逻辑
- oldOrderCode = services.GetHaverEquallyOrderByUser10Min(uid, goodsId) //获取用户十分钟之内是否有相同的订单信息
- item.OrderType = 1
- } else {
- oldOrderCode, payTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivty(uid, sourceId)
- item.OrderType = 2
- }
- }
- title = activityDetail.ActivityName
- item.OrderCode = utils.GetOrdernum()
- item.OutTradeNo = "TRADE" + item.OrderCode
- if activityDetail.ActivityTypeName == "买方线下交流" {
- item.GoodsName = "买方交流"
- }
- if activityDetail.ActivityTypeName == "专家电话会" || activityDetail.ActivityTypeName == "专家线下沙龙" {
- item.GoodsName = "专家调研"
- }
- if activityDetail.ActivityTypeName == "公司调研电话会" {
- item.GoodsName = "上市公司小范围"
- }
- switch goodsId {
- case 1:
- item.GoodsName = "日卡"
- case 2:
- item.GoodsName = "月卡"
- case 9:
- item.GoodsName = "活动回放"
- }
- //如果活动有自定义的价格就优先按照自定义的价格来
- if activityDetail.ActivityPrice > 0 {
- goodsDetail.CurrentPrice = activityDetail.ActivityPrice
- }
- //return
- item.GoodsId = goodsId
- item.GoodsMoney = goodsDetail.Price
- item.OrderMoney = goodsDetail.CurrentPrice
- item.SourceId = sourceId
- item.Source = utils.CYGX_OBJ_ACTIVITY
- item.SourceTitle = title
- item.UserId = user.UserId
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.RealName = user.RealName
- item.SellerName, item.SellerId = services.GetSellerName(user) // 销售姓名
- item.ShareName, item.ShareId = services.GetAdminByInviteShareCode(req.InviteShareCode) // 分享人信息
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- //如果是音视频的订单,数据做二次处理
- if source == "ActivityVivo" {
- vivoPointsSetDetail, err := models.GetCygxActivityVivoPointsSetByActivityId(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- item.GoodsMoney = vivoPointsSetDetail.GoodsMoney
- item.OrderMoney = vivoPointsSetDetail.GoodsMoney
- item.Source = vivoPointsSetDetail.Source
- if vivoPointsSetDetail.Source == utils.CYGX_OBJ_ACTIVITYVIDEO {
- activityVideoInfo, err := models.GetCygxActivityVideoByActivityId(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- title = activityVideoInfo.VideoName
- } else if vivoPointsSetDetail.Source == utils.CYGX_OBJ_ACTIVITYVOICE {
- activityVoiceInfo, err := models.GetCygxActivityVoiceByActivityId(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- title = activityVoiceInfo.VoiceName
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,音视频数据类型错误"
- return
- }
- item.SourceTitle = title
- }
- //如果十分钟之内有相同的订单就修改,没有就新增
- if oldOrderCode == "" {
- err = order.AddCygxOrder(item)
- } else {
- item.OrderCode = oldOrderCode
- err = order.UpdateCygxOrder(item, oldOrderCode)
- }
- JsapiApiResp, err := services.ExampleJsapiApiServicePrepay(item, user.UnionId)
- if err != nil {
- br.Msg = "创建订单信息失败"
- br.ErrMsg = "创建订单信息失败,ExampleJsapiApiServicePrepayErr:" + err.Error()
- return
- }
- resp := new(order.WxJsapiApiResp)
- resp.Detail = JsapiApiResp
- resp.OrderCode = item.OrderCode
- resp.PayTimeCountdown = payTimeCountdown //截止支付时间倒计时
- if err != nil {
- br.Msg = "创建订单信息失败"
- br.ErrMsg = "创建订单信息失败,Err:" + err.Error()
- return
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 通过研选专栏创建订单
- // @Description 通过文章创建订单接口
- // @Param request body models.ActivitySingnupRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /addByYanxuanspecial [post]
- func (this *OrderController) AddByYanxuanspecial() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req order.CygxOrderAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- goodsId := req.GoodsId
- sourceId := req.SourceId
- if goodsId == 0 {
- br.Msg = "支付失败"
- br.ErrMsg = "支付失败,goodsId 信息错误Err:" + err.Error()
- return
- }
- goodsDetail, err := order.GetCygxGoodsDetailByGoodsId(goodsId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- var title string
- oldOrderCode := services.GetHaverEquallyOrderByUser10Min(uid, goodsId) //获取用户十分钟之内是否有相同的订单信息
- // 研选专栏
- yanxuanSpecialBySpeciaDetail, err := models.GetYanxuanSpecialBySpecialId(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- title = yanxuanSpecialBySpeciaDetail.Title
- item := new(order.CygxOrder)
- item.OrderCode = utils.GetOrdernum()
- item.OutTradeNo = "TRADE" + item.OrderCode
- item.GoodsName = goodsDetail.GoodsName
- item.GoodsId = goodsId
- item.GoodsMoney = goodsDetail.Price
- item.OrderMoney = goodsDetail.CurrentPrice
- item.SourceId = sourceId
- item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
- item.SourceTitle = title
- item.UserId = user.UserId
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.RealName = user.RealName
- item.SellerName, item.SellerId = services.GetSellerName(user) // 销售姓名
- item.ShareName, item.ShareId = services.GetAdminByInviteShareCode(req.InviteShareCode) // 分享人信息
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- item.OrderType = 1
- //如果十分钟之内有相同的订单就修改,没有就新增
- if oldOrderCode == "" {
- err = order.AddCygxOrder(item)
- } else {
- item.OrderCode = oldOrderCode
- err = order.UpdateCygxOrder(item, oldOrderCode)
- }
- if err != nil {
- br.Msg = "创建订单信息失败"
- br.ErrMsg = "创建订单信息失败,Err:" + err.Error()
- return
- }
- JsapiApiResp, err := services.ExampleJsapiApiServicePrepay(item, user.UnionId)
- if err != nil {
- br.Msg = "创建订单信息失败"
- br.ErrMsg = "创建订单信息失败,ExampleJsapiApiServicePrepayErr:" + err.Error()
- return
- }
- resp := new(order.WxJsapiApiResp)
- resp.Detail = JsapiApiResp
- resp.OrderCode = item.OrderCode
- br.Data = resp
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 用户订单列表
- // @Description 用户订单列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param OrderType query int false "订单类型 1:畅读卡订单,2:单场付费订单"
- // @Success 200 {object} models.SpecialListResp
- // @router /user/orderList [get]
- func (this *OrderController) UserOrderList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- orderType, _ := this.GetInt("OrderType", 1)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- resp := new(order.UserOrderListResp)
- var condition string
- var pars []interface{}
- userId := user.UserId
- if orderType > 0 {
- condition += ` AND order_type = ? `
- pars = append(pars, orderType)
- }
- condition += ` AND user_id = ? `
- pars = append(pars, userId)
- total, err := order.GetCygxOrderCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- condition += ` ORDER BY order_id DESC `
- list, err := order.GetCygxOrderList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- //音视频时长
- var activityVivoIds []int
- for _, v := range list {
- if v.OrderType == 3 {
- activityVivoIds = append(activityVivoIds, v.SourceId)
- }
- }
- mapActivityVivo := services.GetActivityVivoByActivityIds(activityVivoIds)
- for _, v := range list {
- item := new(order.OrderListResp)
- item.OrderCode = v.OrderCode
- item.OrderMoney = v.OrderMoney
- item.SourceId = v.SourceId
- item.Source = v.Source
- item.SourceTitle = v.SourceTitle
- item.OrderStatus = v.OrderStatus
- switch item.OrderStatus {
- case 0:
- item.OrderStatusText = "已取消"
- case 1:
- item.OrderStatusText = "待支付"
- case 2:
- item.OrderStatusText = "支付成功"
- case 3:
- item.OrderStatusText = "转入退款"
- case 4:
- item.OrderStatusText = "退款处理中"
- case 5:
- item.OrderStatusText = "退款异常"
- case 6:
- item.OrderStatusText = "退款关闭"
- }
- if orderType == 1 {
- if v.GoodsId == 1 {
- item.LabelKeywordImgLink = utils.LABEL_ICO_7 //日卡图标
- item.StartDate = v.StartDate.Format(utils.FormatDateTime)
- item.EndDate = v.EndDate.Format(utils.FormatDateTime)
- } else if v.GoodsId == 2 {
- item.LabelKeywordImgLink = utils.LABEL_ICO_8 // 月卡图标
- item.StartDate = v.StartDate.Format(utils.FormatDate)
- item.EndDate = v.EndDate.Format(utils.FormatDate)
- }
- } else if orderType == 2 {
- item.LabelKeywordImgLink = utils.LABEL_ICO_3
- } else if orderType == 3 {
- item.LabelKeywordImgLink = utils.LABEL_ICO_10
- }
- if v.OrderType == 3 {
- item.PlaySeconds = mapActivityVivo[v.SourceId]
- }
- item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- resp.List = append(resp.List, item)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 订单支付详情
- // @Description 订单支付详情接口
- // @Param OrderCode query string false "订单号"
- // @Success 200 {object} models.SpecialListResp
- // @router /orderPay/detail [get]
- func (this *OrderController) OrderDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(order.PayEdOrderDetailResp)
- orderCode := this.GetString("OrderCode")
- orderDetail, err := order.GetCygxOrderDetailByOrderCode(orderCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- if orderDetail.OrderType == 1 && orderDetail.OrderStatus == 2 {
- cardDetail, err := order.GetCygxOrderUserCardDetailByOrderCode(orderCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- resp.EndDate = strings.Replace(cardDetail.EndDate.Format(utils.FormatDateTime), "00:00:00", "", -1)
- }
- resp.OrderCode = orderDetail.OrderCode
- resp.OrderType = orderDetail.OrderType
- resp.OrderStatus = orderDetail.OrderStatus
- resp.Source = orderDetail.Source
- resp.SourceId = orderDetail.SourceId
- if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
- resp.IsPublicActivitie, resp.IsSignUp = services.GetActivityWechatPayMsg(orderDetail.SourceId) //如果是活动就要判断是否是公开活动,是否需要自动报名
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 取消订单
- // @Description 取消订单接口
- // @Param request body models.CygxOrderCancelReq true "type json string"
- // @router /cancel [post]
- func (this *OrderController) Cancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req order.CygxOrderCancelReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- orderCode := req.OrderCode
- orderDetail, err := order.GetCygxOrderDetailByOrderCode(orderCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- err = order.CancelCygxOrder(orderDetail)
- if err != nil {
- br.Msg = "取消订单失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|