xingzai 1 rok pred
rodič
commit
ffa70fedf4

+ 16 - 19
controllers/order.go

@@ -19,7 +19,7 @@ type OrderController struct {
 // @Description 创建订单接口
 // @Param	request	body models.ActivitySingnupRep true "type json string"
 // @Success Ret=200 {object} models.SignupStatus
-// @router /add [post]
+// @router /addByarticle [post]
 func (this *OrderController) Add() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
@@ -42,7 +42,6 @@ func (this *OrderController) Add() {
 	}
 	uid := user.UserId
 	goodsId := req.GoodsId
-	source := req.Source
 	sourceId := req.SourceId
 	if goodsId == 0 {
 		br.Msg = "支付失败"
@@ -56,24 +55,16 @@ func (this *OrderController) Add() {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
-	fmt.Println(goodsDetail)
 	var title string
-	if source == "activity" {
-
-	} else if source == "article" {
-		articleDetail, err := models.GetArticleDetailById(sourceId)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取信息失败,Err:" + err.Error()
-			return
-		}
-		title = articleDetail.Title
-	} else {
-		br.Msg = "支付失败"
-		br.ErrMsg = "支付失败,source 信息错误Err:" + source
+	oldOrderCode := services.GetHaverEquallyOrderByUser10Min(user.UserId, goodsId) //获取用户十分钟之内是否有相同的订单信息
+	fmt.Println("oldOrderCode", oldOrderCode)
+	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.GoodsName = goodsDetail.GoodsName
@@ -81,7 +72,7 @@ func (this *OrderController) Add() {
 	item.GoodsMoney = goodsDetail.Price
 	item.OrderMoney = goodsDetail.CurrentPrice
 	item.SourceId = sourceId
-	item.Source = source
+	item.Source = utils.CYGX_OBJ_ARTICLE
 	item.SourceTitle = title
 	item.UserId = user.UserId
 	item.Mobile = user.Mobile
@@ -94,7 +85,13 @@ func (this *OrderController) Add() {
 	item.ModifyTime = time.Now()
 	item.RegisterPlatform = utils.REGISTER_PLATFORM
 
-	err = order.AddCygxOrder(item)
+	//如果十分钟之内有相同的订单就修改,没有就新增
+	if oldOrderCode == "" {
+		err = order.AddCygxOrder(item)
+	} else {
+		err = order.UpdateCygxOrder(item, oldOrderCode)
+	}
+
 	if err != nil {
 		br.Msg = "创建订单信息失败"
 		br.ErrMsg = "创建订单信息失败,Err:" + err.Error()

+ 0 - 28
models/article_data.go

@@ -1,28 +0,0 @@
-package models
-
-import (
-	"github.com/beego/beego/v2/client/orm"
-	"time"
-)
-
-type CygxArticleData struct {
-	Id         int       `orm:"column(id);pk"`
-	ArticleId  int       `description:"文章id"`
-	CreateTime time.Time `description:"创建时间"`
-	Cover      string    `description:"封面图片,公司logo"`
-}
-
-//新增文章
-func AddCygxArticleData(item *CygxArticleData) (lastId int64, err error) {
-	o := orm.NewOrm()
-	lastId, err = o.Insert(item)
-	return
-}
-
-//获取数量
-func GetCygxArticleDataCount(articcleId int) (count int, err error) {
-	o := orm.NewOrm()
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_data WHERE article_id=? `
-	err = o.Raw(sqlCount, articcleId).QueryRow(&count)
-	return
-}

+ 0 - 1
models/db.go

@@ -125,7 +125,6 @@ func init() {
 		new(MicroRoadshowVideo),
 		new(CygxActivityVideoHistory),
 		new(CygxActivitySpecialTrip),
-		new(CygxArticleData),
 		new(CygxArticleComment),
 		new(CygxResourceData),
 		new(CygxResearchSummaryVoiceHistory),

+ 73 - 3
models/order/order.go

@@ -7,9 +7,9 @@ import (
 )
 
 type CygxOrderAddReq struct {
-	GoodsId  int    `description:"商品ID"`
-	Source   string `description:"资源(文章、活动)"`
-	SourceId int    `description:"资源ID"`
+	GoodsId int `description:"商品ID"`
+	//Source   string `description:"资源(文章、活动)"`
+	SourceId int `description:"资源ID"`
 }
 
 type CygxOrder struct {
@@ -43,6 +43,37 @@ type CygxOrder struct {
 	RegisterPlatform int       `comment:"来源 1小程序,2:网页"`
 }
 
+type CygxOrderResp struct {
+	OrderId          int       `orm:"column(order_id);pk";comment:"订单id"`
+	OrderCode        string    `comment:"订单编号"`
+	OutTradeCode     string    `comment:"外部交易号"`
+	PaymentType      int       `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
+	GoodsName        string    `comment:"商品名称"`
+	GoodsId          int       `comment:"商品ID"`
+	BuyerInvoice     string    `comment:"买家发票信息"`
+	GoodsMoney       float64   `comment:"商品总价"`
+	OrderMoney       float64   `comment:"订单总价"`
+	Point            int       `comment:"订单消耗积分"`
+	PointMoney       float64   `comment:"订单消耗积分抵多少钱"`
+	PayMoney         float64   `comment:"订单实付金额"`
+	RefundMoney      float64   `comment:"订单退款金额"`
+	OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
+	PayTime          time.Time `comment:"订单付款时间"`
+	SourceId         int       `comment:"来源ID"`
+	Source           string    `comment:"来源\n报告 :article\n活动 :activity"`
+	SourceTitle      string    `comment:"来源名称,活动或者报告标题"`
+	UserId           int       `comment:"用户ID"`
+	Mobile           string    `comment:"手机号"`
+	Email            string    `comment:"邮箱"`
+	CompanyId        int       `comment:"公司ID"`
+	CompanyName      string    `comment:"公司名称"`
+	RealName         string    `comment:"用户实际名称"`
+	SellerName       string    `comment:"所属销售"`
+	CreateTime       time.Time `comment:"创建时间"`
+	ModifyTime       time.Time `comment:"修改时间"`
+	RegisterPlatform int       `comment:"来源 1小程序,2:网页"`
+}
+
 type CygxOrderAction struct {
 	ActionId         int64     `orm:"column(action_id);pk"` // 动作id
 	Action           string    // 动作内容
@@ -105,3 +136,42 @@ func AddCygxOrder(item *CygxOrder) (err error) {
 	}
 	return
 }
+
+// 根据订单编号修改
+func UpdateCygxOrder(item *CygxOrder, oldOrderCode string) (err error) {
+	o := orm.NewOrm()
+	updateParams := make(map[string]interface{})
+	updateParams["SourceId"] = item.SourceId
+	updateParams["Source"] = item.Source
+	updateParams["SourceTitle"] = item.SourceTitle
+	updateParams["ModifyTime"] = item.ModifyTime
+	ptrStructOrTableName := "cygx_order"
+	whereParam := map[string]interface{}{"order_code": oldOrderCode}
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func GetCygxOrderList(condition string, pars []interface{}) (item []*CygxOrderResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_order
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+// 获取数量
+func GetCygxOrderCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_order WHERE   1= 1  ` + condition
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}

+ 1 - 1
routers/commentsRouter.go

@@ -307,7 +307,7 @@ func init() {
     beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"],
         beego.ControllerComments{
             Method: "Add",
-            Router: `/add`,
+            Router: `/addByarticle`,
             AllowHTTPMethods: []string{"post"},
             MethodParams: param.Make(),
             Filters: nil,

+ 30 - 0
services/order.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_mfyx/models"
 	"hongze/hongze_mfyx/models/order"
 	"hongze/hongze_mfyx/utils"
+	"time"
 )
 
 // 获取日卡、月卡商品配置信息
@@ -62,3 +63,32 @@ func GetGoodsInfoByActivity(item *models.ActivityDetail) (goodsListResp []*order
 	goodsListResp = goodsList
 	return
 }
+
+// 获取用户十分钟之内是否有相同的订单信息
+func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("获取用户十分钟之内是否有相同的订单信息失败 GetHaverEquallyOrderByUser10Min, err:", err.Error()), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	endTime := time.Now().Add(-15 * time.Minute)
+	condition = ` AND  user_id = ? AND  goods_id = ? AND create_time > ?  ORDER BY order_id DESC  LIMIT  1 `
+	pars = append(pars, userId, goodsId, endTime)
+	orderList, e := order.GetCygxOrderList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxOrderList, Err: " + e.Error())
+		return
+	}
+	if len(orderList) == 0 {
+		return
+	} else {
+		for _, v := range orderList {
+			orderCode = v.OrderCode
+		}
+	}
+	return
+}