diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index b38108f1a..0dc2eda1e 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -774,7 +774,7 @@ func RefreshOrdersWithoutJxStoreID(ctx *jxcontext.Context, fromDate, toDate stri return hint, err } -func GetOrdersSupplement(ctx *jxcontext.Context, storIDs, vendorIDs []int, vendorOrderID, fromTime, toTime string, status, stype, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { +func GetOrdersSupplement(ctx *jxcontext.Context, storIDs, vendorIDs []int, vendorOrderID, fromTime, toTime string, status, stype, IsReverse, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { var ( db = dao.GetDB() fromTimeP time.Time @@ -789,7 +789,7 @@ func GetOrdersSupplement(ctx *jxcontext.Context, storIDs, vendorIDs []int, vendo if fromTimeP.After(toTimeP) { return nil, fmt.Errorf("时间范围不合法!开始时间:[%v],结束时间:[%v]", fromTimeP, toTimeP) } - result, totalCount, err := dao.GetOrdersSupplement(db, storIDs, vendorIDs, vendorOrderID, fromTimeP, toTimeP, status, stype, offset, pageSize) + result, totalCount, err := dao.GetOrdersSupplement(db, storIDs, vendorIDs, vendorOrderID, fromTimeP, toTimeP, status, stype, IsReverse, offset, pageSize) pageInfo = &model.PagedInfo{ Data: result, TotalCount: totalCount, diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 8ead577a6..62128c3a7 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -72,12 +72,6 @@ type StoreSkuBindInfo struct { Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"` } -type tStoreSkuBindInfo struct { - NameID int `json:"nameID"` - UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价 - IsFocused bool `json:"isFocused"` //是否关注过 -} - type tStoreSkuBindAndSpec struct { model.StoreSkuBind SkuStatus int @@ -2963,3 +2957,61 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin } return hint, err } + +func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync bool) (err error) { + var ( + nameMap = make(map[int]*StoreSkuBindInfo) + ) + db := dao.GetDB() + storeList, err := dao.GetStoreList(db, nil, nil, "") + for _, v := range storeList { + storeSkuList, _ := dao.GetStoreSkusAndSkuName(db, []int{v.ID}, skuIDs) + for _, vv := range storeSkuList { + if nameMap[vv.ID] != nil { + nameMap[vv.ID].Skus = append(nameMap[vv.ID].Skus, &StoreSkuBindSkuInfo{ + SkuID: vv.SkuID, + }) + } else { + skuBindInfo := &StoreSkuBindInfo{ + UnitPrice: vv.UnitPrice, + NameID: vv.ID, + StoreID: v.ID, + Skus: []*StoreSkuBindSkuInfo{}, + } + nameMap[vv.ID] = skuBindInfo + } + } + } + for _, v := range nameMap { + var skuBindInfoList []*StoreSkuBindInfo + skuBindInfoResult := &StoreSkuBindInfo{ + NameID: v.NameID, + UnitPrice: v.UnitPrice, + IsFocus: 1, + } + var skuBindSkuList []*StoreSkuBindSkuInfo + skuMap := make(map[int]int) + skuList, _ := dao.GetSkus(db, nil, []int{v.NameID}, nil, nil) + if len(v.Skus) != len(skuList) { + for _, skus := range v.Skus { + skuMap[skus.SkuID] = 1 + } + for _, vv := range skuList { + if skuMap[vv.ID] != 1 { + continue + } + skuBindSkuList = append(skuBindSkuList, &StoreSkuBindSkuInfo{ + SkuID: vv.ID, + IsSale: 0, + }) + } + } + skuBindInfoList = append(skuBindInfoList, skuBindInfoResult) + if isSync { + UpdateStoreSkus(ctx, v.StoreID, skuBindInfoList, true, true) + } else { + updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false) + } + } + return err +} diff --git a/business/jxstore/event/event.go b/business/jxstore/event/event.go new file mode 100644 index 000000000..4a9713f86 --- /dev/null +++ b/business/jxstore/event/event.go @@ -0,0 +1,9 @@ +package event + +func AddOperateEvent() { + +} + +func AddOperateEventDetail() { + +} diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 10df80426..5af4b4dba 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -82,31 +82,26 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e _, err = task.GetResult(0) dao.Commit(db) } - dao.Begin(db) - defer func() { - if r := recover(); r != nil || err != nil { - dao.Rollback(db) - if r != nil { - panic(r) - } - } - }() - priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1))) + priceReferList, _ := dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1))) if len(priceReferList) > 0 { - task := tasksch.NewParallelTask("更新单价", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, - func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - v := batchItemList[0].(*model.PriceReferSnapshot) - priceRefer, err := dao.GetPriceReferUnitPrice(db, v.CityCode, v.NameID, v.SnapshotAt) - v.MidUnitPrice = priceRefer.MidUnitPrice - v.MaxUnitPrice = priceRefer.MaxUnitPrice - v.MinUnitPrice = priceRefer.MinUnitPrice - v.AvgUnitPrice = priceRefer.AvgUnitPrice - _, err = dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "AvgUnitPrice", "MinUnitPrice") - return retVal, err - }, priceReferList) - tasksch.HandleTask(task, nil, true).Run() - _, err = task.GetResult(0) + dao.Begin(db) + defer func() { + if r := recover(); r != nil || err != nil { + dao.Rollback(db) + if r != nil { + panic(r) + } + } + }() + for _, v := range priceReferList { + priceRefer, _ := dao.GetPriceReferUnitPrice(db, v.CityCode, v.NameID, v.SnapshotAt) + v.MidUnitPrice = priceRefer.MidUnitPrice + v.MaxUnitPrice = priceRefer.MaxUnitPrice + v.MinUnitPrice = priceRefer.MinUnitPrice + v.AvgUnitPrice = priceRefer.AvgUnitPrice + _, err = dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "AvgUnitPrice", "MinUnitPrice") + } + dao.Commit(db) } - dao.Commit(db) return err } diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 7dadf5c58..aaac96497 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1052,7 +1052,7 @@ func GetWayBillByOrderID(db *DaoDB, orderStatus, vendorID, waybillVendorID int, return wayBillList, err } -func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID string, fromTime, toTime time.Time, status, stype, offset, pageSize int) (orderSupplementFee []*model.OrderSupplementFee, totalCount int, err error) { +func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID string, fromTime, toTime time.Time, status, stype, IsReverse, offset, pageSize int) (orderSupplementFee []*model.OrderSupplementFee, totalCount int, err error) { sql := ` SELECT SQL_CALC_FOUND_ROWS * FROM order_supplement_fee @@ -1075,7 +1075,7 @@ func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID stri sqlParams = append(sqlParams, storIDs) } if len(vendorIDs) > 0 { - sql += " AND store_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")" + sql += " AND vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")" sqlParams = append(sqlParams, vendorIDs) } if vendorOrderID != "" { @@ -1090,6 +1090,11 @@ func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs []int, vendorOrderID stri sql += " AND type = ?" sqlParams = append(sqlParams, stype) } + if IsReverse == -1 { + sql += " AND link_id = 0" + } else if IsReverse == 1 { + sql += " AND link_id <> 0" + } sql += ` LIMIT ? OFFSET ?` sqlParams = append(sqlParams, pageSize, offset) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 13281737c..07e10f364 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1188,7 +1188,7 @@ func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error UPDATE store_sku_bind a JOIN store d ON d.id = a.store_id JOIN price_refer_snapshot b ON a.sku_id = b.sku_id AND b.snapshot_at = ? AND d.city_code = b.city_code - SET a.price = (b.mid_price*IF(d.pay_percentage=0,100,d.pay_percentage))/100 + SET a.unit_price = (b.mid_unit_price*IF(d.pay_percentage < 50,70,d.pay_percentage))/100 WHERE 1=1 ` sqlParams := []interface{}{ @@ -1199,7 +1199,7 @@ func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error sqlParams = append(sqlParams, storeIDs) } sql += ` - AND (a.price/IF(d.pay_percentage=0,100,d.pay_percentage))*100 > b.mid_price + AND (a.price/IF(d.pay_percentage < 50,70,d.pay_percentage))*100 > b.mid_price AND a.deleted_at = ? AND a.status = ? ` @@ -1370,6 +1370,7 @@ func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBi func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.Time) (result *PriceReferSnapshotExt, err error) { var ( pRefer []*PriceReferSnapshotExt + priceRefer = &PriceReferSnapshotExt{} minUnitPrice int maxUnitPrice int midUnitPrice int @@ -1426,10 +1427,35 @@ func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.T midUnitPrice += midPrice avgUnitPrice += avgPrice } - result.MinUnitPrice = minUnitPrice / len(pRefer) - result.MaxUnitPrice = maxUnitPrice / len(pRefer) - result.AvgUnitPrice = avgUnitPrice / len(pRefer) - result.MidUnitPrice = midUnitPrice / len(pRefer) + priceRefer.MinUnitPrice = minUnitPrice / len(pRefer) + priceRefer.MaxUnitPrice = maxUnitPrice / len(pRefer) + priceRefer.AvgUnitPrice = avgUnitPrice / len(pRefer) + priceRefer.MidUnitPrice = midUnitPrice / len(pRefer) } - return result, err + return priceRefer, err +} + +func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) { + sql := ` + SELECT a.*,c.id + FROM store_sku_bind a + JOIN sku b ON b.id = a.sku_id AND b.deleted_at = ? + JOIN sku_name c ON c.id = b.name_id AND c.deleted_at = ? + WHERE a.deleted_at = ? + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + utils.DefaultTimeValue, + utils.DefaultTimeValue, + } + if len(storeIDs) > 0 { + sql += " AND a.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")" + sqlParams = append(sqlParams, storeIDs) + } + if len(skuIDs) > 0 { + sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")" + sqlParams = append(sqlParams, skuIDs) + } + err = GetRows(db, &storeSkuNameExt, sql, sqlParams...) + return storeSkuNameExt, err } diff --git a/business/model/event.go b/business/model/event.go new file mode 100644 index 000000000..9a5a8cb9f --- /dev/null +++ b/business/model/event.go @@ -0,0 +1,35 @@ +package model + +import "time" + +type OperateEvent struct { + ID int64 `orm:"column(id)" json:"id"` + CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"` + LastOperator string `orm:"size(32)" json:"lastOperator"` // 最后操作员 + AccessUUID string `orm:"column(access_uuid)" json:"accessUUID"` + UserID string `orm:"column(user_id)" json:"userID"` + APIFunction string `orm:"column(api_function)" json:"apiFunction"` +} + +func (v *OperateEvent) TableIndex() [][]string { + return [][]string{ + []string{"AccessUUID", "UserID"}, + } +} + +type OperateEventDetail struct { + ID int64 `orm:"column(id)" json:"id"` + OperateType int `json:"operateType"` // 1为修改,2为新增,4为删除 + ThingID int `orm:"column(thing_id)" json:"thingID"` + ThingType int `json:"thingType"` //各字段类型 + StoreID int `orm:"column(store_id)" json:"storeID"` + AccessUUID string `orm:"column(access_uuid)" json:"accessUUID"` + BeforeData string `orm:"size(32)" json:"beforeData"` + AfterData string `orm:"size(32)" json:"afterData"` +} + +func (v *OperateEventDetail) TableIndex() [][]string { + return [][]string{ + []string{"AccessUUID", "ThingID", "StoreID"}, + } +} diff --git a/controllers/jx_order.go b/controllers/jx_order.go index ee9ae829a..56cee5353 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -936,6 +936,7 @@ func (c *OrderController) ComplaintRider() { // @Param toTime query string false "结束日期(包含),格式(2006-01-02),如果订单号为空此项必须要求" // @Param status query int false "账单状态,0是未结账,1是已结账" // @Param type query int false "扣款类型,1为差评补贴,2为优惠券" +// @Param isReverse query int false "只查冲账记录,0为默认都查,1为只查冲账,-1为不查冲账" // @Param offset query int false "结果起始序号(以0开始,缺省为0)" // @Param pageSize query int false "结果页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult @@ -945,7 +946,7 @@ func (c *OrderController) GetOrdersSupplement() { var vendorIDList, storeIDList []int c.callGetOrdersSupplement(func(params *tOrderGetOrdersSupplementParams) (retVal interface{}, errCode string, err error) { if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil { - retVal, err = orderman.GetOrdersSupplement(params.Ctx, storeIDList, vendorIDList, params.VendorOrderID, params.FromTime, params.ToTime, params.Status, params.Type, params.Offset, params.PageSize) + retVal, err = orderman.GetOrdersSupplement(params.Ctx, storeIDList, vendorIDList, params.VendorOrderID, params.FromTime, params.ToTime, params.Status, params.Type, params.IsReverse, params.Offset, params.PageSize) } return retVal, "", err }) diff --git a/controllers/jx_report.go b/controllers/jx_report.go index f604dbfc9..ecebd0f84 100644 --- a/controllers/jx_report.go +++ b/controllers/jx_report.go @@ -1,6 +1,7 @@ package controllers import ( + "git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxstore/report" "git.rosy.net.cn/jx-callback/business/jxutils" "github.com/astaxie/beego" @@ -82,3 +83,29 @@ func (c *ReportController) PriceRefer() { return retVal, "", err }) } + +// @Title 生成价格参考数据单价 +// @Description 生成价格参考数据单价 +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /PriceReferUnitPrice [post] +func (c *ReportController) PriceReferUnitPrice() { + // c.callPriceReferUnitPrice(func(params *tReportPriceReferUnitPriceParams) (retVal interface{}, errCode string, err error) { + // report.UpdatePriceReferUnitPrice(params.Ctx) + // return retVal, "", err + // }) +} + +// @Title 自动关注商品(针对后加的商品规格未关注) +// @Description 自动关注商品(针对后加的商品规格未关注) +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /AutoFocusStoreSkus [post] +func (c *ReportController) AutoFocusStoreSkus() { + c.callAutoFocusStoreSkus(func(params *tReportAutoFocusStoreSkusParams) (retVal interface{}, errCode string, err error) { + cms.AutoFocusStoreSkusWithoutFocus(params.Ctx, nil, false) + return retVal, "", err + }) +} diff --git a/globals/beegodb/beegodb.go b/globals/beegodb/beegodb.go index 5ce864921..5f039f248 100644 --- a/globals/beegodb/beegodb.go +++ b/globals/beegodb/beegodb.go @@ -42,6 +42,8 @@ func Init() { orm.RegisterModel(&model.StorePriceScoreSnapshot{}) orm.RegisterModel(&model.StoreSkuNamePrice{}) orm.RegisterModel(&model.OrderSupplementFee{}) + orm.RegisterModel(&model.OperateEvent{}) + orm.RegisterModel(&model.OperateEventDetail{}) // orm.RegisterModel(&model.ActivityForSku{}) // orm.RegisterModel(&legacymodel.JxBadComments2{}) diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 02877e5f9..aebca060f 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1098,6 +1098,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], + beego.ControllerComments{ + Method: "AutoFocusStoreSkus", + Router: `/AutoFocusStoreSkus`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], beego.ControllerComments{ Method: "PriceRefer", @@ -1107,6 +1116,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], + beego.ControllerComments{ + Method: "PriceReferUnitPrice", + Router: `/PriceReferUnitPrice`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], beego.ControllerComments{ Method: "StatisticsReportForAfsOrders",