Sfoglia il codice sorgente

增加我的优惠卷查询接口

zhou.xiaoning 4 anni fa
parent
commit
3242af272d
7 ha cambiato i file con 537 aggiunte e 2 eliminazioni
  1. 43 0
      controllers/hsby/hsby.go
  2. 144 0
      docs/docs.go
  3. 144 0
      docs/swagger.json
  4. 101 0
      docs/swagger.yaml
  5. 16 0
      models/account.go
  6. 87 2
      models/hsby.go
  7. 2 0
      routers/router.go

+ 43 - 0
controllers/hsby/hsby.go

@@ -1117,3 +1117,46 @@ func QueryHsbyMarketGoodses(c *gin.Context) {
 		appG.Response(http.StatusOK, e.SUCCESS, goodses)
 	}
 }
+
+// QueryMyCouponsReq 我的优惠卷查询请求参数
+type QueryMyCouponsReq struct {
+	AccountIDs string `form:"accountIDs" binding:"required"`
+	GoodsID    int    `form:"goodsID"`
+	SellUserID int    `form:"sellUserID"`
+}
+
+// QueryMyCoupons 我的优惠卷查询
+// @Summary 我的优惠卷查询
+// @Produce json
+// @Security ApiKeyAuth
+// @Param accountIDs query string true "资金账户列表,格式:1,2,3"
+// @Param goodsID query int false "商品ID, 一般与sellOrderID配套传入"
+// @Param sellUserID query int false "卖方UserID"
+// @Success 200 {object} models.MyCoupon
+// @Failure 500 {object} app.Response
+// @Router /HSBY/QueryMyCoupons [get]
+// @Tags 定制【海商报业】
+func QueryMyCoupons(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryMyCouponsReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取数据
+	myCoupons, err := models.GetMyCoupons(req.AccountIDs, req.GoodsID, req.SellUserID)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功返回
+	logger.GetLogger().Debugln("QueryMyCoupons successed: %v", myCoupons)
+	appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
+}

+ 144 - 0
docs/docs.go

@@ -2057,6 +2057,57 @@ var doc = `{
                 }
             }
         },
+        "/HSBY/QueryMyCoupons": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "我的优惠卷查询",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID, 一般与sellOrderID配套传入",
+                        "name": "goodsID",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "卖方UserID",
+                        "name": "sellUserID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.MyCoupon"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryMyPayOrders": {
             "get": {
                 "security": [
@@ -6903,6 +6954,10 @@ var doc = `{
                     "description": "行情最小变动单位 [整数,报价小数位一起使用]",
                     "type": "integer"
                 },
+                "sellUserID": {
+                    "description": "卖方UserID",
+                    "type": "integer"
+                },
                 "trademode": {
                     "description": "交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价",
                     "type": "integer"
@@ -7769,6 +7824,95 @@ var doc = `{
                 }
             }
         },
+        "models.MyCoupon": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "coupontypeid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "资金账户ID",
+                    "type": "integer"
+                },
+                "areauserid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                },
+                "conditionvalue": {
+                    "description": "条件阈值(可为0)",
+                    "type": "number"
+                },
+                "couponcategroy": {
+                    "description": "种类 - 1:现金券 2:折扣券 3:折扣券(单张)",
+                    "type": "integer"
+                },
+                "couponname": {
+                    "description": "优惠券名称",
+                    "type": "string"
+                },
+                "coupontypeid": {
+                    "description": "优惠券类型ID",
+                    "type": "integer"
+                },
+                "couponvalue": {
+                    "description": "面值[1:现金券 - 抵扣值 2:折扣券-折扣值]",
+                    "type": "number"
+                },
+                "curfreezeqty": {
+                    "description": "期末冻结数量",
+                    "type": "integer"
+                },
+                "curqty": {
+                    "description": "期末数量",
+                    "type": "integer"
+                },
+                "isgeneral": {
+                    "description": "是否通用券 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "isunusable": {
+                    "description": "是否不可用",
+                    "type": "boolean"
+                },
+                "limitedflag": {
+                    "description": "是否指定商品 - 0:不限 1:限制",
+                    "type": "integer"
+                },
+                "limitedgoodsids": {
+                    "description": "指定商品IDs[逗号分隔,前后加逗号]",
+                    "type": "string"
+                },
+                "orifreezeqty": {
+                    "description": "期初冻结数量",
+                    "type": "integer"
+                },
+                "oriqty": {
+                    "description": "期初数量",
+                    "type": "integer"
+                },
+                "reasontype": {
+                    "description": "不可用原因 - 0:未确认 1:不可用于此商品 2:不可用于此卖家",
+                    "type": "integer"
+                },
+                "todaydecrease": {
+                    "description": "今日减少",
+                    "type": "integer"
+                },
+                "todayincrease": {
+                    "description": "今日增加",
+                    "type": "integer"
+                },
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "userscope": {
+                    "description": "卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]",
+                    "type": "string"
+                }
+            }
+        },
         "models.OperationPrimaryMenu": {
             "type": "object",
             "properties": {

+ 144 - 0
docs/swagger.json

@@ -2041,6 +2041,57 @@
                 }
             }
         },
+        "/HSBY/QueryMyCoupons": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "我的优惠卷查询",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID, 一般与sellOrderID配套传入",
+                        "name": "goodsID",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "卖方UserID",
+                        "name": "sellUserID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.MyCoupon"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryMyPayOrders": {
             "get": {
                 "security": [
@@ -6887,6 +6938,10 @@
                     "description": "行情最小变动单位 [整数,报价小数位一起使用]",
                     "type": "integer"
                 },
+                "sellUserID": {
+                    "description": "卖方UserID",
+                    "type": "integer"
+                },
                 "trademode": {
                     "description": "交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价",
                     "type": "integer"
@@ -7753,6 +7808,95 @@
                 }
             }
         },
+        "models.MyCoupon": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "coupontypeid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "资金账户ID",
+                    "type": "integer"
+                },
+                "areauserid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                },
+                "conditionvalue": {
+                    "description": "条件阈值(可为0)",
+                    "type": "number"
+                },
+                "couponcategroy": {
+                    "description": "种类 - 1:现金券 2:折扣券 3:折扣券(单张)",
+                    "type": "integer"
+                },
+                "couponname": {
+                    "description": "优惠券名称",
+                    "type": "string"
+                },
+                "coupontypeid": {
+                    "description": "优惠券类型ID",
+                    "type": "integer"
+                },
+                "couponvalue": {
+                    "description": "面值[1:现金券 - 抵扣值 2:折扣券-折扣值]",
+                    "type": "number"
+                },
+                "curfreezeqty": {
+                    "description": "期末冻结数量",
+                    "type": "integer"
+                },
+                "curqty": {
+                    "description": "期末数量",
+                    "type": "integer"
+                },
+                "isgeneral": {
+                    "description": "是否通用券 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "isunusable": {
+                    "description": "是否不可用",
+                    "type": "boolean"
+                },
+                "limitedflag": {
+                    "description": "是否指定商品 - 0:不限 1:限制",
+                    "type": "integer"
+                },
+                "limitedgoodsids": {
+                    "description": "指定商品IDs[逗号分隔,前后加逗号]",
+                    "type": "string"
+                },
+                "orifreezeqty": {
+                    "description": "期初冻结数量",
+                    "type": "integer"
+                },
+                "oriqty": {
+                    "description": "期初数量",
+                    "type": "integer"
+                },
+                "reasontype": {
+                    "description": "不可用原因 - 0:未确认 1:不可用于此商品 2:不可用于此卖家",
+                    "type": "integer"
+                },
+                "todaydecrease": {
+                    "description": "今日减少",
+                    "type": "integer"
+                },
+                "todayincrease": {
+                    "description": "今日增加",
+                    "type": "integer"
+                },
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "userscope": {
+                    "description": "卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]",
+                    "type": "string"
+                }
+            }
+        },
         "models.OperationPrimaryMenu": {
             "type": "object",
             "properties": {

+ 101 - 0
docs/swagger.yaml

@@ -2456,6 +2456,9 @@ definitions:
       quoteminunit:
         description: 行情最小变动单位 [整数,报价小数位一起使用]
         type: integer
+      sellUserID:
+        description: 卖方UserID
+        type: integer
       trademode:
         description: 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式
           21:竞拍-大宗式 22:受托竞价
@@ -3126,6 +3129,72 @@ definitions:
     required:
     - messageboardid
     type: object
+  models.MyCoupon:
+    properties:
+      accountid:
+        description: 资金账户ID
+        type: integer
+      areauserid:
+        description: 所属机构
+        type: integer
+      conditionvalue:
+        description: 条件阈值(可为0)
+        type: number
+      couponcategroy:
+        description: 种类 - 1:现金券 2:折扣券 3:折扣券(单张)
+        type: integer
+      couponname:
+        description: 优惠券名称
+        type: string
+      coupontypeid:
+        description: 优惠券类型ID
+        type: integer
+      couponvalue:
+        description: 面值[1:现金券 - 抵扣值 2:折扣券-折扣值]
+        type: number
+      curfreezeqty:
+        description: 期末冻结数量
+        type: integer
+      curqty:
+        description: 期末数量
+        type: integer
+      isgeneral:
+        description: 是否通用券 - 0:否 1:是
+        type: integer
+      isunusable:
+        description: 是否不可用
+        type: boolean
+      limitedflag:
+        description: 是否指定商品 - 0:不限 1:限制
+        type: integer
+      limitedgoodsids:
+        description: 指定商品IDs[逗号分隔,前后加逗号]
+        type: string
+      orifreezeqty:
+        description: 期初冻结数量
+        type: integer
+      oriqty:
+        description: 期初数量
+        type: integer
+      reasontype:
+        description: 不可用原因 - 0:未确认 1:不可用于此商品 2:不可用于此卖家
+        type: integer
+      todaydecrease:
+        description: 今日减少
+        type: integer
+      todayincrease:
+        description: 今日增加
+        type: integer
+      userid:
+        description: 用户ID
+        type: integer
+      userscope:
+        description: 卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]
+        type: string
+    required:
+    - accountid
+    - coupontypeid
+    type: object
   models.OperationPrimaryMenu:
     properties:
       Children:
@@ -6405,6 +6474,38 @@ paths:
       summary: 我的闲置中收款信息查询
       tags:
       - 定制【海商报业】
+  /HSBY/QueryMyCoupons:
+    get:
+      parameters:
+      - description: 资金账户列表,格式:1,2,3
+        in: query
+        name: accountIDs
+        required: true
+        type: string
+      - description: 商品ID, 一般与sellOrderID配套传入
+        in: query
+        name: goodsID
+        type: integer
+      - description: 卖方UserID
+        in: query
+        name: sellUserID
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.MyCoupon'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 我的优惠卷查询
+      tags:
+      - 定制【海商报业】
   /HSBY/QueryMyPayOrders:
     get:
       parameters:

+ 16 - 0
models/account.go

@@ -535,6 +535,22 @@ func GetUserInfoByIDS(userids []int64) ([]Userinfo, error) {
 	return infos, err
 }
 
+// GetUserAccountByAccountID 通过资金账户获取用户信息
+func GetUserAccountByAccountID(accountID int) (*Useraccount, error) {
+	engine := db.GetEngine()
+	infos := make([]Useraccount, 0)
+	if err := engine.Table("USERACCOUNT U").
+		Join("INNER", "TAACCOUNT TA", "TA.RELATEDUSERID = U.USERID").
+		Where("TA.ACCOUNTID = ?", accountID).Find(&infos); err != nil {
+		return nil, err
+	}
+	if len(infos) > 0 {
+		return &infos[0], nil
+	}
+
+	return nil, nil
+}
+
 // GetUserFavoriteGoodses 获取用户商品收藏信息
 func GetUserFavoriteGoodses(userID int) ([]Userfavoritegoods, error) {
 	engine := db.GetEngine()

+ 87 - 2
models/hsby.go

@@ -1379,6 +1379,8 @@ type HsbyMarketGoods struct {
 	Trademode int32 `json:"trademode"  xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
 
 	HasCoupon bool `json:"hascoupon" xorm:"-"` // 是否可用优惠卷
+
+	SellUserID int `json:"sellUserID" xorm:"-"` // 卖方UserID
 }
 
 // GetHsbyMarketGoodses 获取商城商品列表(三级商城)
@@ -1442,8 +1444,15 @@ func GetHsbyMarketGoodses(marketIDs string, accountID, categoryID int) ([]HsbyMa
 			} else {
 				for i := range orders {
 					order := &orders[i]
+
+					// 获取卖家UserID
+					userAccount, err := GetUserAccountByAccountID(int(order.Accountid))
+					if err != nil {
+						continue
+					}
+
 					tmpGoodsID := fmt.Sprintf(",%d,", order.Goodsid)
-					tmpAccountID := fmt.Sprintf(",%d,", order.Accountid)
+					tmpUserID := fmt.Sprintf(",%d,", userAccount.Userid)
 
 					// 优惠卷是否可用于商品
 					isRightGoods := false
@@ -1459,7 +1468,7 @@ func GetHsbyMarketGoodses(marketIDs string, accountID, categoryID int) ([]HsbyMa
 					if coupon.Isgeneral == 1 {
 						isRightAccount = true
 					} else {
-						if strings.Contains(coupon.Userscope, tmpAccountID) {
+						if strings.Contains(coupon.Userscope, tmpUserID) {
 							isRightAccount = true
 						}
 					}
@@ -1474,3 +1483,79 @@ func GetHsbyMarketGoodses(marketIDs string, accountID, categoryID int) ([]HsbyMa
 
 	return orders, nil
 }
+
+// MyCoupon 我的优惠卷
+type MyCoupon struct {
+	Accountid     int64 `json:"accountid"  xorm:"'ACCOUNTID'" binding:"required"`       // 资金账户ID
+	Coupontypeid  int32 `json:"coupontypeid"  xorm:"'COUPONTYPEID'" binding:"required"` // 优惠券类型ID
+	Userid        int64 `json:"userid"  xorm:"'USERID'"`                                // 用户ID
+	Oriqty        int64 `json:"oriqty"  xorm:"'ORIQTY'"`                                // 期初数量
+	Orifreezeqty  int64 `json:"orifreezeqty"  xorm:"'ORIFREEZEQTY'"`                    // 期初冻结数量
+	Curqty        int64 `json:"curqty"  xorm:"'CURQTY'"`                                // 期末数量
+	Curfreezeqty  int64 `json:"curfreezeqty"  xorm:"'CURFREEZEQTY'"`                    // 期末冻结数量
+	Todayincrease int64 `json:"todayincrease"  xorm:"'TODAYINCREASE'"`                  // 今日增加
+	Todaydecrease int64 `json:"todaydecrease"  xorm:"'TODAYDECREASE'"`                  // 今日减少
+
+	Areauserid      int64   `json:"areauserid"  xorm:"'AREAUSERID'"`           // 所属机构
+	Couponname      string  `json:"couponname"  xorm:"'COUPONNAME'"`           // 优惠券名称
+	Couponcategroy  int32   `json:"couponcategroy"  xorm:"'COUPONCATEGROY'"`   // 种类 - 1:现金券 2:折扣券 3:折扣券(单张)
+	Conditionvalue  float64 `json:"conditionvalue"  xorm:"'CONDITIONVALUE'"`   // 条件阈值(可为0)
+	Couponvalue     float64 `json:"couponvalue"  xorm:"'COUPONVALUE'"`         // 面值[1:现金券 - 抵扣值 2:折扣券-折扣值]
+	Limitedflag     int32   `json:"limitedflag"  xorm:"'LIMITEDFLAG'"`         // 是否指定商品 - 0:不限 1:限制
+	Limitedgoodsids string  `json:"limitedgoodsids"  xorm:"'LIMITEDGOODSIDS'"` // 指定商品IDs[逗号分隔,前后加逗号]
+	Isgeneral       int32   `json:"isgeneral"  xorm:"'ISGENERAL'"`             // 是否通用券 - 0:否 1:是
+	Userscope       string  `json:"userscope"  xorm:"'USERSCOPE'"`             // 卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]
+
+	IsUnusable bool `json:"isunusable" xorm:"-"` // 是否不可用
+	ReasonType int  `json:"reasontype"`          // 不可用原因 - 0:未确认 1:不可用于此商品 2:不可用于此卖家
+}
+
+// GetMyCoupons 获取我的优惠卷信息
+func GetMyCoupons(accountIDs string, goodsID, sellUserID int) ([]MyCoupon, error) {
+	engine := db.GetEngine()
+
+	myCoupons := make([]MyCoupon, 0)
+	session := engine.Table("COUPONPOSITION CP").
+		Join("INNER", "COUPONTYPE CT", "CT.COUPONTYPEID = CP.COUPONTYPEID").
+		Where(fmt.Sprintf("CP.ACCOUNTID in (%s)", accountIDs))
+	if err := session.Find(&myCoupons); err != nil {
+		return nil, err
+	}
+
+	// 如果传入了商品ID和卖方UserID,则判断优惠卷是否可用
+	if goodsID != 0 && sellUserID != 0 && len(myCoupons) > 0 {
+		for i := range myCoupons {
+			myCoupon := &myCoupons[i]
+
+			// 优惠卷是否可用于商品
+			isRightGoods := false
+			if myCoupon.Limitedflag == 0 {
+				isRightGoods = true
+			} else {
+				if strings.Contains(myCoupon.Limitedgoodsids, fmt.Sprintf(",%d,", goodsID)) {
+					isRightGoods = true
+				}
+			}
+			// 优惠卷是否可用于卖家
+			isRightAccount := false
+			if myCoupon.Isgeneral == 1 {
+				isRightAccount = true
+			} else {
+				if strings.Contains(myCoupon.Userscope, fmt.Sprintf(",%d,", sellUserID)) {
+					isRightAccount = true
+				}
+			}
+
+			if !isRightGoods {
+				myCoupon.IsUnusable = true
+				myCoupon.ReasonType = 1
+			}
+			if !isRightAccount {
+				myCoupon.IsUnusable = true
+				myCoupon.ReasonType = 2
+			}
+		}
+	}
+
+	return myCoupons, nil
+}

+ 2 - 0
routers/router.go

@@ -266,6 +266,8 @@ func InitRouter() *gin.Engine {
 		hsbyR.GET("/QueryHsbyMarkets", hsby.QueryHsbyMarkets)
 		// 查询特卖商品列表(三级商城)
 		hsbyR.GET("/QueryHsbyMarketGoodses", hsby.QueryHsbyMarketGoodses)
+		// 我的优惠卷查询
+		hsbyR.GET("/QueryMyCoupons", hsby.QueryMyCoupons)
 	}
 
 	return r