|
|
@@ -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
|
|
|
+}
|