aa
This commit is contained in:
@@ -149,6 +149,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"thingType": model.ThingTypeName,
|
||||
"apiFunctionName": model.ApiFunctionName,
|
||||
"vendorStatus": model.VendorStatus,
|
||||
"couponsStatus": model.CouponStatusName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1482,7 +1482,7 @@ func GetPriceDefendOrder(db *DaoDB, vendorOrderID string, storeIDs, skuIDs, issu
|
||||
return priceDefendOrders, err
|
||||
}
|
||||
|
||||
func GetCoupons(db *DaoDB, couponType int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
func GetCoupons(db *DaoDB, couponType int, couponStatuss []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM coupons
|
||||
@@ -1497,5 +1497,10 @@ func GetCoupons(db *DaoDB, couponType int, keyword string) (coupons []*model.Cou
|
||||
sql += " AND (name LIKE ? OR desc LIKE ?)"
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
if len(couponStatuss) > 0 {
|
||||
sql += " AND coupon_status IN (" + GenQuestionMarks(len(couponStatuss)) + ")"
|
||||
sqlParams = append(sqlParams, couponStatuss)
|
||||
}
|
||||
err = GetRows(db, &coupons, sql, sqlParams)
|
||||
return coupons, err
|
||||
}
|
||||
|
||||
@@ -35,6 +35,16 @@ const (
|
||||
OrderTypeDefendPrice = 3 //守价订单
|
||||
)
|
||||
|
||||
const (
|
||||
CouponStatusRe = -2 //优惠券状态还没生效
|
||||
CouponStatusOverdue = -1 //已过期
|
||||
CouponStatusNormal = 0 //正常
|
||||
)
|
||||
|
||||
const (
|
||||
UserCouponStatusOverdue = 1 // 已被使用
|
||||
)
|
||||
|
||||
var (
|
||||
PayStatusName = map[int]string{
|
||||
PayStatusNo: "待支付",
|
||||
@@ -49,6 +59,13 @@ var (
|
||||
RefundStatusYes: "已退款",
|
||||
RefundStatusFailed: "退款失败",
|
||||
}
|
||||
|
||||
CouponStatusName = map[int]string{
|
||||
CouponStatusRe: "还没生效",
|
||||
CouponStatusOverdue: "已过期",
|
||||
CouponStatusNormal: "正常",
|
||||
UserCouponStatusOverdue: "已被使用",
|
||||
}
|
||||
)
|
||||
|
||||
type ModelTimeInfo struct {
|
||||
@@ -410,16 +427,17 @@ func (v *PriceDefendOrder) TableIndex() [][]string {
|
||||
}
|
||||
|
||||
type Coupons struct {
|
||||
ModelIDCULD
|
||||
ModelIDCUL
|
||||
|
||||
CouponType int `json:"couponType"` //优惠券类型 ,1为总额满减, 2为运费优惠,
|
||||
Name string `json:"name"` //优惠券名字
|
||||
Desc string `json:"desc"` //优惠券详情描述
|
||||
BeginAt time.Time `json:"beginAt"` //开始时间
|
||||
EndAt time.Time `json:"endAt"` //到期时间
|
||||
UpperLimit int `json:"upperLimit"` //满多少
|
||||
Cut int `json:"cut"` //减多少
|
||||
StoreLimit string `orm:"type(text)" json:"storeLimit"` //门店限制:如100118,102919
|
||||
CouponType int `json:"couponType"` //优惠券类型 ,1为总额满减, 2为运费优惠,
|
||||
Name string `json:"name"` //优惠券名字
|
||||
Desc string `json:"desc"` //优惠券详情描述
|
||||
BeginAt time.Time `json:"beginAt"` //开始时间
|
||||
EndAt time.Time `json:"endAt"` //到期时间
|
||||
UpperLimit int `json:"upperLimit"` //满多少
|
||||
Cut int `json:"cut"` //减多少
|
||||
StoreLimit string `orm:"type(text)" json:"storeLimit"` //门店限制:如100118,102919
|
||||
CouponStatus int `json:"couponStatus"` //优惠券状态,0为正常可使用,-1为已过期, -2为还没开始
|
||||
}
|
||||
|
||||
func (v *Coupons) TableIndex() [][]string {
|
||||
@@ -431,14 +449,15 @@ func (v *Coupons) TableIndex() [][]string {
|
||||
type UserCoupons struct {
|
||||
ModelIDCUL
|
||||
|
||||
CouponID int `orm:"column(coupon_id)" json:"couponID"` //优惠券ID
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //userID
|
||||
CouponStatus int `json:"couponStatus"` //优惠券状态,0为正常可使用,-1为已过期, -2为已使用
|
||||
CouponID int `orm:"column(coupon_id)" json:"couponID"` //优惠券ID
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //userID
|
||||
Mobile string `json:"moblie"` //电话,可能他还没注册
|
||||
UserCouponStatus int `json:"userCouponStatus"` //优惠券状态,0为正常可使用,-1为已过期, 1为已使用
|
||||
}
|
||||
|
||||
func (v *UserCoupons) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CouponID", "UserID"},
|
||||
[]string{"CouponID", "UserID", "Mobile"},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2149,10 +2149,42 @@ func GetMyPriceDefendOrders(ctx *jxcontext.Context, fromTime, toTime string) (pr
|
||||
return priceDefendOrders, err
|
||||
}
|
||||
|
||||
func GetCoupons(ctx *jxcontext.Context, couponType int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
func GetCoupons(ctx *jxcontext.Context, couponType int, couponStatuss []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
coupons, err = dao.GetCoupons(db, couponType, keyword)
|
||||
coupons, err = dao.GetCoupons(db, couponType, couponStatuss, keyword)
|
||||
return coupons, err
|
||||
}
|
||||
|
||||
func AddCoupons(ctx *jxcontext.Context, coupons *model.Coupons, count int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if coupons.BeginAt == utils.ZeroTimeValue || coupons.EndAt == utils.ZeroTimeValue {
|
||||
return fmt.Errorf("请输入正确的起始时间!")
|
||||
} else {
|
||||
if coupons.BeginAt.Sub(coupons.EndAt) > 0 {
|
||||
return fmt.Errorf("请输入正确的起始时间!")
|
||||
}
|
||||
//优惠券还没开始生效
|
||||
if time.Now().Sub(coupons.BeginAt) < 0 {
|
||||
coupons.CouponStatus = model.CouponStatusRe
|
||||
}
|
||||
}
|
||||
if coupons.UpperLimit == 0 || coupons.Cut == 0 {
|
||||
return fmt.Errorf("请输入正确的满减!")
|
||||
} else {
|
||||
if coupons.Cut > coupons.UpperLimit {
|
||||
return fmt.Errorf("请输入正确的满减!")
|
||||
}
|
||||
}
|
||||
if coupons.CouponType == 0 {
|
||||
return fmt.Errorf("请选择一个优惠券类型!")
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
dao.WrapAddIDCULDEntity(coupons, ctx.GetUserName())
|
||||
dao.CreateEntity(db, coupons)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
@@ -287,15 +288,37 @@ func (c *JxOrderController) TestDefend() {
|
||||
|
||||
// @Title 查询优惠券
|
||||
// @Description 查询优惠券
|
||||
// @Param token header string true "认证token"
|
||||
// @Param couponType query int false "优惠券类型,1为商品总额满减,2为运费优惠"
|
||||
// @Param keyword query string false "关键字"
|
||||
// @Param token header string true "认证token"
|
||||
// @Param couponType query int false "优惠券类型,1为商品总额满减,2为运费优惠"
|
||||
// @Param couponStatuss query string false "优惠券状态,0为正常可使用,-1为已过期, -2为还没开始"
|
||||
// @Param keyword query string false "关键字"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetCoupons [get]
|
||||
func (c *JxOrderController) GetCoupons() {
|
||||
c.callGetCoupons(func(params *tJxorderGetCouponsParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = localjx.GetCoupons(params.Ctx, params.CouponType, params.Keyword)
|
||||
var statuss []int
|
||||
if err = jxutils.Strings2Objs(params.CouponStatuss, &statuss); err == nil {
|
||||
retVal, err = localjx.GetCoupons(params.Ctx, params.CouponType, statuss, params.Keyword)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 添加优惠券
|
||||
// @Description 添加优惠券
|
||||
// @Param token header string true "认证token"
|
||||
// @Param payload formData string true "优惠券类型 payload"
|
||||
// @Param count formData int true "优惠券数量,默认1"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /AddCoupons [post]
|
||||
func (c *JxOrderController) AddCoupons() {
|
||||
c.callAddCoupons(func(params *tJxorderAddCouponsParams) (retVal interface{}, errCode string, err error) {
|
||||
coupons := &model.Coupons{}
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), coupons); err == nil {
|
||||
err = localjx.AddCoupons(params.Ctx, coupons, params.Count)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user