- UpdateActStoreSkuBind
This commit is contained in:
@@ -120,7 +120,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac
|
||||
return jxutils.IntMap2List(wholeValidVendorMap), actStoreSkuList, actStoreSkuMapList, err
|
||||
}
|
||||
|
||||
func addActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap) (err error) {
|
||||
func addActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap) (err error) {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -156,8 +156,7 @@ func addActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList []*m
|
||||
return err
|
||||
}
|
||||
|
||||
func AddActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
db := dao.GetDB()
|
||||
func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -174,6 +173,10 @@ func AddActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreS
|
||||
return err
|
||||
}
|
||||
}
|
||||
if act.Status != model.ActStatusCreated {
|
||||
return fmt.Errorf("当前活动状态:%s不能进行此操作", model.ActStatusName[act.Status])
|
||||
}
|
||||
|
||||
_, actStoreSkuList, actStoreSkuMapList, err := ActStoreSkuParam2Model(ctx, db, act, vendorIDs, actStoreSku)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -187,7 +190,7 @@ func AddActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreS
|
||||
}
|
||||
}
|
||||
}()
|
||||
if err = addActStoreBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
if err = addActStoreSkuBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, act := range actMap {
|
||||
@@ -247,7 +250,7 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
}
|
||||
}
|
||||
|
||||
if err = addActStoreBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
if err = addActStoreSkuBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
dao.Rollback(db)
|
||||
return "", err
|
||||
}
|
||||
@@ -304,25 +307,21 @@ func GetActStoreSkuInfo(ctx *jxcontext.Context, actID int, vendorIDs []int) (act
|
||||
|
||||
func CancelAct(ctx *jxcontext.Context, actID int) (err error) {
|
||||
db := dao.GetDB()
|
||||
if err = deleteActStoreBind(ctx, db, actID, nil); err != nil {
|
||||
if err = DeleteActStoreSkuBind(ctx, db, actID, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = SyncAct(ctx, nil, actID, nil, nil, nil, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
return deleteActStoreBind(ctx, dao.GetDB(), actID, actStoreSku)
|
||||
}
|
||||
|
||||
// actStoreSkuParam为空,不会删除act_store_sku,但会删除act_store_sku_map
|
||||
func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSkuParam []*ActStoreSkuParam) (err error) {
|
||||
func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSkuParam []*ActStoreSkuParam) (err error) {
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(actMap) == 0 {
|
||||
return fmt.Errorf("找不到活动:%d,或已被全部取消", actID)
|
||||
return fmt.Errorf("找不到活动:%d,或已被取消", actID)
|
||||
}
|
||||
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, nil, nil)
|
||||
@@ -423,7 +422,7 @@ func SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, actID int, vendor
|
||||
if vendorIDs == nil {
|
||||
vendorIDs = partner.GetVendorIDsFromActMap(actMap)
|
||||
}
|
||||
task := tasksch.NewParallelTask("SyncAct", nil, ctx,
|
||||
task := tasksch.NewParallelTask("SyncAct", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformActHandler); handler != nil {
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestCancelAct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteActStoreBind(t *testing.T) {
|
||||
err := DeleteActStoreBind(jxcontext.AdminCtx, 1, []*ActStoreSkuParam{
|
||||
err := DeleteActStoreSkuBind(jxcontext.AdminCtx, dao.GetDB(), 1, []*ActStoreSkuParam{
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100119,
|
||||
@@ -104,7 +104,7 @@ func TestDeleteActStoreBind(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddActStoreBind(t *testing.T) {
|
||||
err := AddActStoreBind(jxcontext.AdminCtx, 1, []*ActStoreSkuParam{
|
||||
err := AddActStoreSkuBind(jxcontext.AdminCtx, dao.GetDB(), 1, []*ActStoreSkuParam{
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100119,
|
||||
|
||||
@@ -28,6 +28,13 @@ const (
|
||||
ActCreateTypeSpider = 3
|
||||
)
|
||||
|
||||
var (
|
||||
ActTypeName = map[int]string{
|
||||
ActSkuDirectDown: "直降",
|
||||
ActSkuSecKill: "秒杀",
|
||||
}
|
||||
)
|
||||
|
||||
type Act struct {
|
||||
ModelIDCULD
|
||||
|
||||
|
||||
@@ -83,15 +83,18 @@ func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
%s JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
JOIN sku t4 ON t4.id = t1.sku_id AND t4.deleted_at = ?
|
||||
JOIN store_sku_bind t5 ON t5.sku_id = t1.sku_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
WHERE t1.deleted_at = ? AND t1.act_id = ?
|
||||
WHERE t1.act_id = ?
|
||||
`, leftOrEmpty)
|
||||
sqlParams = append(sqlParams,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
actID,
|
||||
)
|
||||
if leftOrEmpty != "" {
|
||||
sql += " AND t1.deleted_at = ?"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
|
||||
@@ -76,7 +76,7 @@ func act2EbaiActivity(act *model.Act2, actOrderRules []*model.ActOrderRule) (act
|
||||
CloseTime: "23:59",
|
||||
WeekDay: "0,1,2,3,4,5,6",
|
||||
ActivityDesc: act.Advertising,
|
||||
ShowCategory: act.Name,
|
||||
ShowCategory: model.ActTypeName[act.Type],
|
||||
PromotionSkuDesc: act.Advertising,
|
||||
DayLimit: act.LimitDaily,
|
||||
ActivityPlatform: ebaiapi.ActivityPFAll,
|
||||
|
||||
@@ -262,7 +262,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
return err
|
||||
}()
|
||||
db := dao.GetDB()
|
||||
globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
|
||||
_, err2 := dao.BatchUpdateEntityByKV(db, updateItems)
|
||||
if err == nil {
|
||||
err = err2
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
@@ -160,3 +163,47 @@ func (c *ActController) SyncAct() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 添加SKU活动商品
|
||||
// @Description 添加SKU活动商品
|
||||
// @Param token header string true "认证token"
|
||||
// @Param actID formData int true "活动id"
|
||||
// @Param actStoreSkuAddList formData string false "需添加的活动商品信息"
|
||||
// @Param actStoreSkuDeleteList formData string false "需删除的活动商品信息"
|
||||
// @Param isAsync formData bool false "是否异步"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UpdateActStoreSkuBind [put]
|
||||
func (c *ActController) UpdateActStoreSkuBind() {
|
||||
c.callUpdateActStoreSkuBind(func(params *tActUpdateActStoreSkuBindParams) (retVal interface{}, errCode string, err error) {
|
||||
var actStoreSkuAddList, actStoreSkuDeleteList []*act.ActStoreSkuParam
|
||||
if err = jxutils.Strings2Objs(params.ActStoreSkuAddList, &actStoreSkuAddList, params.ActStoreSkuDeleteList, &actStoreSkuDeleteList); err == nil {
|
||||
if len(actStoreSkuAddList) == 0 && len(actStoreSkuDeleteList) == 0 {
|
||||
err = fmt.Errorf("actStoreSkuAddList与actStoreSkuDeleteList不能都为空")
|
||||
} else {
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
}()
|
||||
if len(actStoreSkuAddList) > 0 {
|
||||
if err = act.AddActStoreSkuBind(params.Ctx, db, params.ActID, actStoreSkuAddList); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
}
|
||||
if len(actStoreSkuDeleteList) > 0 {
|
||||
if err = act.DeleteActStoreSkuBind(params.Ctx, db, params.ActID, actStoreSkuDeleteList); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}()
|
||||
retVal, err = act.SyncAct(params.Ctx, nil, params.ActID, nil, nil, nil, params.IsAsync)
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -61,6 +61,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdateActStoreSkuBind",
|
||||
Router: `/UpdateActStoreSkuBind`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"],
|
||||
beego.ControllerComments{
|
||||
Method: "AddAuthBind",
|
||||
|
||||
Reference in New Issue
Block a user