diff --git a/business/jxstore/cms/sync_store_sku_fakejd.go b/business/jxstore/cms/sync_store_sku_fakejd.go deleted file mode 100644 index 734be6322..000000000 --- a/business/jxstore/cms/sync_store_sku_fakejd.go +++ /dev/null @@ -1,329 +0,0 @@ -package cms - -import ( - "fmt" - "io" - "time" - - "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxutils" - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" - "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" - "git.rosy.net.cn/jx-callback/business/model" - "git.rosy.net.cn/jx-callback/business/model/dao" - "git.rosy.net.cn/jx-callback/business/partner" - "git.rosy.net.cn/jx-callback/business/partner/putils" - "git.rosy.net.cn/jx-callback/globals/api/apimanager" - "github.com/360EntSecGroup-Skylar/excelize" -) - -func storeOrSkuMap2List(intStrMap map[int]string) (ids []int) { - for k, v := range intStrMap { - if v != "" { - ids = append(ids, k) - } - } - return ids -} - -func getStoreSkus(db *dao.DaoDB, storeID int, skuIDs []int) (skus []*dao.StoreSkuSyncInfo, err error) { - sql := ` - SELECT - t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status, - t1.jd_sync_status sku_sync_status, t1.jd_price vendor_price, t1.jd_lock_time lock_time, - t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end, - t2.*, - t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc, t3.status name_status, t3.ex_prefix, t3.ex_prefix_begin, t3.ex_prefix_end - FROM store_sku_bind t1 - LEFT JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ?/* AND t2.status = ?*/ - LEFT JOIN sku_name t3 ON t2.name_id = t3.id AND t3.deleted_at = ?/* AND t3.status = ?*/ - WHERE 1 = 1 - AND t1.store_id = ? - AND t1.deleted_at = ? - AND t1.sku_id IN ( ` + dao.GenQuestionMarks(len(skuIDs)) + `) - ORDER BY t1.price` - sqlParams := []interface{}{ - utils.DefaultTimeValue, - utils.DefaultTimeValue, - storeID, - utils.DefaultTimeValue, - skuIDs, - } - if err = dao.GetRows(db, &skus, sql, sqlParams...); err != nil { - return nil, err - } - return skus, err -} - -func SyncStoreSku4FakeJD(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inSkuMap map[int]string, isContinueWhenError bool) (err error) { - vendorID := model.VendorIDJD - db := dao.GetDB() - storeDetail, err := dao.GetStoreDetail(db, storeID, vendorID) - if err != nil { - return err - } - storeDetail.VendorOrgCode = apimanager.FakeJdOrgCode - skuIDs := storeOrSkuMap2List(inSkuMap) - skus, err := getStoreSkus(db, storeID, skuIDs) - if err != nil || len(skus) == 0 { - return err - } - formalizeStoreSkuList(skus) - storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) - - var ( - stockList, onlineList, offlineList, priceList []*partner.StoreSkuInfo - ) - skuMap := make(map[*partner.StoreSkuInfo]*dao.StoreSkuSyncInfo) - now := jxutils.OperationTime2HourMinuteFormat(time.Now()) - var failedList []*partner.StoreSkuInfoWithErr - for _, sku := range skus { - sku.SkuSyncStatus = model.SyncFlagSaleMask | model.SyncFlagPriceMask | model.SyncFlagStockMask - sku.VendorSkuID = inSkuMap[sku.SkuID] - sku.SkuID = int(utils.Str2Int64(sku.VendorSkuID)) // skuID与vendorID一样 - sku.VendorOrgCode = apimanager.FakeJdOrgCode - - sku.VendorPrice = 0 - sku.MergedStatus = MergeSkuSaleStatusWithStoreOpTime(sku, storeDetail, now) - var bareSku *partner.StoreSkuInfo - if isStoreSkuSyncNeedDelete(sku) { - if !dao.IsVendorThingIDEmpty(sku.VendorSkuID) { - bareSku = storeSkuSyncInfo2Bare(sku) - stockList = append(stockList, bareSku) - } else { - // updateItems = append(updateItems, sku2Update(vendorID, sku, model.SyncFlagDeletedMask)) - } - } else if model.IsSyncStatusNew(sku.SkuSyncStatus) { - calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)) - if dao.IsVendorThingIDEmpty(sku.VendorSkuID) { - // todo 多平台商品库没有正常创建,直接跳过 - } else { - sku.SkuSyncStatus |= model.SyncFlagSaleMask | model.SyncFlagPriceMask - bareSku = storeSkuSyncInfo2Bare(sku) - stockList = append(stockList, bareSku) - priceList = append(priceList, bareSku) - if sku.MergedStatus == model.SkuStatusNormal { - onlineList = append(onlineList, bareSku) - } else { - offlineList = append(offlineList, bareSku) - } - } - } else { - if dao.IsVendorThingIDEmpty(sku.VendorSkuID) { - // err = fmt.Errorf("门店:%d,修改没有创建的商品:%d", storeID, sku.SkuID) - err = utils.NewErrorCode(fmt.Sprintf("门店:%d,修改没有创建的商品:%d", storeID, sku.SkuID), "-1", 0) - failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorChineseNames[vendorID], "异常同步错误") - if parentTask == nil { - return err - } - parentTask.AddBatchErr(err) - parentTask.AddFailedList(failedList) - } else { - isAdded2Update := false - if model.IsSyncStatusPrice(sku.SkuSyncStatus) { - bareSku = storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))) - priceList = append(priceList, bareSku) - } - if !isAdded2Update { - if model.IsSyncStatusSale(sku.SkuSyncStatus) { - if bareSku == nil { - bareSku = storeSkuSyncInfo2Bare(sku) - } - if sku.MergedStatus == model.SkuStatusNormal { - onlineList = append(onlineList, bareSku) - stockList = append(stockList, bareSku) - } else { - offlineList = append(offlineList, bareSku) - // 因为京东平台以是否有库存表示是否关注,所以不论是否可售,都要设置库存 - stockList = append(stockList, bareSku) - } - } - } - } - } - if bareSku != nil { - skuMap[bareSku] = sku - } - } - bareSku2Sync := func(bareSkuList []*partner.StoreSkuInfo) (skuList []*dao.StoreSkuSyncInfo) { - if len(bareSkuList) > 0 { - skuList = make([]*dao.StoreSkuSyncInfo, len(bareSkuList)) - for k, v := range bareSkuList { - skuList[k] = skuMap[v] - } - } - return skuList - } - isContinueWhenError2 := true - realStoreID := int(utils.Str2Int64(vendorStoreID)) - task := tasksch.NewParallelTask("SyncStoreSku4FakeJD", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError2), ctx, - func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - step := batchItemList[0].(int) - // globals.SugarLogger.Debugf("step:%d", step) - switch step { - case 0: - for k, list := range [][]*partner.StoreSkuInfo{stockList /*, onlineList*/} { - if len(list) > 0 { - _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - var failedList []*partner.StoreSkuInfoWithErr - failedList, err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeDetail.VendorOrgCode, realStoreID, vendorStoreID, batchedStoreSkuList) - if len(failedList) > 0 { - task.AddFailedList(failedList) - } - successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) - if k == 0 && len(successList) > 0 { - updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagStockMask) - } - return nil, len(successList), err - }, ctx, task, list, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStock), isContinueWhenError2) - } - } - case 1, 2: - statusList := onlineList - status := model.SkuStatusNormal - name := "可售门店商品" - if step == 2 { - statusList = offlineList - status = model.SkuStatusDontSale - name = "不可售门店商品" - } - if len(statusList) > 0 { - _, err = putils.FreeBatchStoreSkuInfo(name, func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - var failedList []*partner.StoreSkuInfoWithErr - failedList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeDetail.VendorOrgCode, realStoreID, vendorStoreID, batchedStoreSkuList, status) - if len(failedList) > 0 { - task.AddFailedList(failedList) - } - successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) - if len(successList) > 0 { - updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagSaleMask) - } - return nil, len(successList), err - }, ctx, task, statusList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStatus), isContinueWhenError2) - } - case 3: - if len(priceList) > 0 { - _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - var failedList []*partner.StoreSkuInfoWithErr - failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeDetail.VendorOrgCode, realStoreID, vendorStoreID, batchedStoreSkuList) - if len(failedList) > 0 { - task.AddFailedList(failedList) - } - successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) - if len(successList) > 0 { - updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagPriceMask) - } - return nil, len(successList), err - }, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError2) - } - } - return retVal, err - }, []int{0, 1, 2, 3}) - tasksch.HandleTask(task, parentTask, true).Run() - _, err = task.GetResult(0) - return err -} - -func SyncFakeJdStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap, skuMap map[int]string, isAsync, isContinueWhenError bool) (hint string, err error) { - storeIDs := storeOrSkuMap2List(storeMap) - task := tasksch.NewParallelTask("同步假京东", nil, ctx, - func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - storeID := batchItemList[0].(int) - err = SyncStoreSku4FakeJD(ctx, task, storeID, storeMap[storeID], skuMap, isContinueWhenError) - return retVal, err - }, storeIDs) - tasksch.HandleTask(task, parentTask, true).Run() - if isAsync { - hint = task.GetID() - } else { - _, err = task.GetResult(0) - hint = utils.Int2Str(len(storeIDs)) - } - return hint, err -} - -func excel2FakeJdThingMap(ctx *jxcontext.Context, reader io.Reader) (thingMapList []*model.FakeJdThingMap, err error) { - xlsx, err := excelize.OpenReader(reader) - if err != nil { - return nil, err - } - for sheetIndex := 0; sheetIndex < xlsx.SheetCount; sheetIndex++ { - rows, err2 := xlsx.GetRows(xlsx.GetSheetName(sheetIndex + 1)) - if err2 != nil { - return nil, err2 - } - for rowNum, row := range rows { - thingMap := &model.FakeJdThingMap{ - JxID: int(utils.Str2Int64WithDefault(row[0], 0)), - JdID: utils.Str2Int64WithDefault(row[1], 0), - } - if thingMap.JxID == 0 || thingMap.JdID == 0 { - if rowNum == 0 { - continue - } else { - break - } - } - if sheetIndex == 0 { - thingMap.ThingType = model.ThingTypeStore - } else { - thingMap.ThingType = model.ThingTypeSku - } - dao.WrapAddIDCULEntity(thingMap, ctx.GetUserName()) - thingMapList = append(thingMapList, thingMap) - } - } - return thingMapList, err -} - -func getFakeThingMap(ctx *jxcontext.Context, db *dao.DaoDB) (storeMap, skuMap map[int]string, err error) { - var thingMapList []*model.FakeJdThingMap - err = dao.GetRows(db, &thingMapList, "SELECT t1.* FROM fake_jd_thing_map t1") - if err == nil { - storeMap, skuMap = make(map[int]string), make(map[int]string) - for _, v := range thingMapList { - if v.ThingType == model.ThingTypeStore { - storeMap[v.JxID] = utils.Int64ToStr(v.JdID) - } else { - skuMap[v.JxID] = utils.Int64ToStr(v.JdID) - } - } - } - return storeMap, skuMap, err -} - -func UploadFakeJdThingMap(ctx *jxcontext.Context, reader io.Reader, isSyncNow, isAsync, isContinueWhenError bool) (hint string, err error) { - thingMapList, err := excel2FakeJdThingMap(ctx, reader) - if err != nil { - return "", err - } - - db := dao.GetDB() - dao.Begin(db) - defer func() { - if r := recover(); r != nil { - dao.Rollback(db) - panic(r) - } - }() - _, err = dao.ExecuteSQL(db, "DELETE t1 FROM fake_jd_thing_map t1") - if err != nil { - dao.Rollback(db) - return "", err - } - err = dao.CreateMultiEntities(db, thingMapList) - if err != nil { - dao.Rollback(db) - return "", err - } - dao.Commit(db) - - if isSyncNow { - if storeMap, skuMap, err2 := getFakeThingMap(ctx, db); err2 == nil { - hint, err = SyncFakeJdStoreSku(ctx, nil, storeMap, skuMap, isAsync, isContinueWhenError) - } - } else { - hint = utils.Int2Str(len(thingMapList)) - } - return hint, err -} diff --git a/business/jxstore/cms/sync_store_sku_fakejd_test.go b/business/jxstore/cms/sync_store_sku_fakejd_test.go deleted file mode 100644 index a71d0580d..000000000 --- a/business/jxstore/cms/sync_store_sku_fakejd_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package cms - -import ( - "os" - "testing" - - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" -) - -func TestSyncStoreSku4FakeJD(t *testing.T) { - skuMap := map[int]string{ - 22509: "2029937911", - } - err := SyncStoreSku4FakeJD(jxcontext.AdminCtx, nil, 100118, "11943257", skuMap, true) - if err != nil { - t.Fatal(err) - } -} - -func TestUploadFakeJdThingMap(t *testing.T) { - file, err := os.Open("到家菜市门店与商品映射信息(1).xlsx") - if err != nil { - t.Fatal(err) - } - hint, err := UploadFakeJdThingMap(jxcontext.AdminCtx, file, true, false, true) - if err != nil { - t.Fatal(err) - } - t.Log(hint) -} diff --git a/business/model/dao/food_recipe.go b/business/model/dao/food_recipe.go deleted file mode 100644 index 638403b5a..000000000 --- a/business/model/dao/food_recipe.go +++ /dev/null @@ -1,150 +0,0 @@ -package dao - -import ( - "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxutils" - "git.rosy.net.cn/jx-callback/business/model" -) - -type FoodRecipeWithAction struct { - model.FoodRecipe - AuthorName string `json:"authorName"` - ActionType int8 `json:"actionType"` -} - -type FoodRecipeItemChoiceExt struct { - model.FoodRecipeItemChoice - - Img string `orm:"size(255)" json:"img"` - SkuName string `json:"skuName"` - - Prefix string `json:"-"` - SkuNameName string `orm:"column(sku_name_name)" json:"-"` - Unit string `orm:"size(8)" json:"-"` - SpecQuality float32 `json:"-"` - SpecUnit string `json:"-"` - Comment string `json:"-"` -} - -func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string, skuIDs []int, offset, pageSize int) (recipeList []*FoodRecipeWithAction, totalCount int, err error) { - var sql string - var sqlParams []interface{} - if userID != "" { - sql = ` - SELECT SQL_CALC_FOUND_ROWS - t1.*, t2.action_type, t3.name author_name - FROM food_recipe t1 - LEFT JOIN food_recipe_user t2 ON t2.recipe_id = t1.id AND t2.user_id = ? AND t2.deleted_at = ? - LEFT JOIN user t3 ON t3.user_id = t1.author_id - WHERE t1.deleted_at = ?` - sqlParams = []interface{}{ - userID, - utils.DefaultTimeValue, - utils.DefaultTimeValue, - } - } else { - sql = ` - SELECT SQL_CALC_FOUND_ROWS t1.* - FROM food_recipe t1 - WHERE t1.deleted_at = ?` - sqlParams = []interface{}{ - utils.DefaultTimeValue, - } - } - if keyword != "" { - keywordLike := "%" + keyword + "%" - sql += " AND (t1.name LIKE ?" - sqlParams = append(sqlParams, keywordLike) - sql += ")" - } - if recipeID > 0 { - sql += " AND t1.id = ?" - sqlParams = append(sqlParams, recipeID) - } - if authorID != "" { - sql += " AND t1.author_id = ?" - sqlParams = append(sqlParams, authorID) - } - if len(skuIDs) > 0 { - sql += ` AND ( - SELECT COUNT(*) - FROM food_recipe_item_choice t11 - WHERE t11.recipe_id = t1.id AND t11.sku_id IN (` + GenQuestionMarks(len(skuIDs)) + `) - ) > 0` - sqlParams = append(sqlParams, skuIDs) - } - offset = jxutils.FormalizePageOffset(offset) - pageSize = jxutils.FormalizePageSize(pageSize) - sql += ` - ORDER BY t1.created_at DESC - LIMIT ? OFFSET ?` - sqlParams = append(sqlParams, pageSize, offset) - - Begin(db) - defer Commit(db) - if err = GetRows(db, &recipeList, sql, sqlParams...); err == nil { - totalCount = GetLastTotalRowCount(db) - } - return recipeList, totalCount, err -} - -func GetRecommendFoodRecipes(db *DaoDB, keyword, userID string, offset, pageSize int) (recipeList []*model.FoodRecipe, totalCount int, err error) { - list, totalCount, err := QueryFoodRecipes(db, keyword, 0, userID, "", nil, offset, pageSize) - if err == nil { - recipeList = FoodRecipeWithActionList2Recipe(list) - } - return recipeList, totalCount, err -} - -func FoodRecipeWithActionList2Recipe(recipeList []*FoodRecipeWithAction) (outRecipeList []*model.FoodRecipe) { - for _, v := range recipeList { - outRecipeList = append(outRecipeList, &v.FoodRecipe) - } - return outRecipeList -} - -func QueryFoodRecipesItems(db *DaoDB, recipeID int) (recipeItemList []*model.FoodRecipeItem, err error) { - sql := ` - SELECT t1.* - FROM food_recipe_item t1 - WHERE t1.deleted_at = ? AND t1.recipe_id = ?` - sqlParams := []interface{}{ - utils.DefaultTimeValue, - recipeID, - } - sql += " ORDER BY t1.index" - err = GetRows(db, &recipeItemList, sql, sqlParams...) - return recipeItemList, err -} - -func QueryFoodRecipesItemChoices(db *DaoDB, recipeID int) (recipeItemChoiceList []*FoodRecipeItemChoiceExt, err error) { - sql := ` - SELECT t1.*, - t2.spec_quality, t2.spec_unit, t2.comment, - t3.img, t3.prefix, t3.name sku_name_name, t3.unit - FROM food_recipe_item_choice t1 - LEFT JOIN sku t2 ON t2.id = t1.sku_id - LEFT JOIN sku_name t3 ON t3.id = t2.name_id - WHERE t1.deleted_at = ? AND t1.recipe_id = ?` - sqlParams := []interface{}{ - utils.DefaultTimeValue, - recipeID, - } - sql += " ORDER BY t1.index, t1.choice_index" - err = GetRows(db, &recipeItemChoiceList, sql, sqlParams...) - return recipeItemChoiceList, err -} - -func QueryFoodRecipesSteps(db *DaoDB, recipeID int) (recipeStepList []*model.FoodRecipeStep, err error) { - sql := ` - SELECT t1.* - FROM food_recipe_step t1 - WHERE t1.deleted_at = ? AND t1.recipe_id = ?` - sqlParams := []interface{}{ - utils.DefaultTimeValue, - recipeID, - } - sql += " ORDER BY t1.index" - err = GetRows(db, &recipeStepList, sql, sqlParams...) - return recipeStepList, err -} diff --git a/business/model/dao/food_recipe_test.go b/business/model/dao/food_recipe_test.go deleted file mode 100644 index b3b064046..000000000 --- a/business/model/dao/food_recipe_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package dao - -import ( - "testing" -) - -func TestQueryRecipes(t *testing.T) { - db := GetDB() - recipeList, _, err := QueryFoodRecipes(db, "", 0, "", "", nil, 0, 0) - if err != nil { - t.Fatal(err) - } - if len(recipeList) > 0 { - t.Fatal("should not return list") - } - - recipeItemList, err := QueryFoodRecipesItems(db, -1) - if err != nil { - t.Fatal(err) - } - if len(recipeItemList) > 0 { - t.Fatal("should not return list") - } - - choiceList, err := QueryFoodRecipesItemChoices(db, -1) - if err != nil { - t.Fatal(err) - } - if len(choiceList) > 0 { - t.Fatal("should not return list") - } - - stepList, err := QueryFoodRecipesSteps(db, -1) - if err != nil { - t.Fatal(err) - } - if len(stepList) > 0 { - t.Fatal("should not return list") - } -} diff --git a/business/model/dao/page_store.go b/business/model/dao/page_store.go deleted file mode 100644 index fe413e2f6..000000000 --- a/business/model/dao/page_store.go +++ /dev/null @@ -1,101 +0,0 @@ -package dao - -import ( - "git.rosy.net.cn/jx-callback/business/jxutils" - "git.rosy.net.cn/jx-callback/business/model" -) - -type PageShopWithPlaceName struct { - model.PageShop - - CityName string `json:"cityName"` - DistrictName string `json:"districtName"` - Distance int `json:"distance"` -} - -func QueryPageStores(db *DaoDB, pageSize, offset int, keyword string, vendorStoreID string, vendorID int, orgCode string, - cityCode, districtCode int, tel string, minShopScore float32, minRecentOrderNum, minSkuCount int, - lng1, lat1, lng2, lat2 float64) (pagedInfo *model.PagedInfo, err error) { - sql := ` - SELECT SQL_CALC_FOUND_ROWS - t1.*, - t2.name city_name, t3.name district_name - FROM page_shop t1 - LEFT JOIN place t2 ON t2.code = t1.city_code - LEFT JOIN place t3 ON t3.code = t1.district_code - WHERE 1 = 1 - ` - sqlParams := []interface{}{} - - if vendorStoreID != "" { - sql += " AND t1.vendor_store_id = ?" - sqlParams = append(sqlParams, vendorStoreID) - } - if vendorID != -1 { - sql += " AND t1.vendor_id = ?" - sqlParams = append(sqlParams, vendorID) - } - if orgCode != "" { - sql += " AND t1.org_code = ?" - sqlParams = append(sqlParams, orgCode) - } - if cityCode != 0 { - sql += " AND t1.city_code = ?" - sqlParams = append(sqlParams, cityCode) - } - if districtCode != 0 { - sql += " AND t1.district_code = ?" - sqlParams = append(sqlParams, districtCode) - } - if tel != "" { - sql += " AND t1.tel1 = ?" - sqlParams = append(sqlParams, tel) - } - if minShopScore > 0 { - sql += " AND t1.shop_score >= ?" - sqlParams = append(sqlParams, minShopScore) - } - if minRecentOrderNum > 0 { - sql += " AND t1.recent_order_num >= ?" - sqlParams = append(sqlParams, minRecentOrderNum) - } - if minSkuCount > 0 { - sql += " AND t1.sku_count >= ?" - sqlParams = append(sqlParams, minSkuCount) - } - if lng1 > 0 { - sql += " AND t1.lng >= ? AND t1.lat >= ? AND t1.lng <= ? AND t1.lat <= ?" - sqlParams = append(sqlParams, lng1, lat1, lng2, lat2) - } - if keyword != "" { - keywordLike := "%" + keyword + "%" - sql += " AND (t1.name LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.org_code LIKE ? OR t1.address LIKE ? OR t2.name LIKE ? OR t3.name LIKE ? OR t1.licence_code LIKE ?" - sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike) - sql += ")" - } - sql += ` - ORDER BY t1.recent_order_num DESC - LIMIT ? OFFSET ? - ` - pageSize = jxutils.FormalizePageSize(pageSize) - offset = jxutils.FormalizePageOffset(offset) - sqlParams = append(sqlParams, pageSize, offset) - var shopList []*PageShopWithPlaceName - Begin(db) - defer func() { - if r := recover(); r != nil { - Rollback(db) - panic(r) - } - }() - if err = GetRows(db, &shopList, sql, sqlParams...); err == nil { - pagedInfo = &model.PagedInfo{ - TotalCount: GetLastTotalRowCount(db), - Data: shopList, - } - Commit(db) - } else { - Rollback(db) - } - return pagedInfo, err -} diff --git a/business/model/user.go b/business/model/user.go index 1c371809a..f78cb0489 100644 --- a/business/model/user.go +++ b/business/model/user.go @@ -99,6 +99,110 @@ func (user *User) GetAvatar() string { return user.Avatar } +type StoreBoss struct { + ModelIDCULD + UserID string `orm:"size(48);column(user_id);unique" json:"userID"` // 内部唯一标识 + BossName string `orm:"size(48);index" json:"bossName"` // 门店老板真实姓名 + StoreID int `orm:"column(store_id)" json:"storeID"` + ParentUserID string `orm:"size(48);column(parent_user_id)" json:"-"` + + ReferrerID string `orm:"size(48);index" json:"referrerID"` // 推荐人ID + ReferrerName string `orm:"size(48);index" json:"referrerName"` // 推荐人姓名 + + CityCode int `json:"cityCode"` // 期望开店所在的城市 + IDCardFront string `orm:"size(255);column(id_card_front)" json:"idCardFront"` + IDCardBack string `orm:"size(255);column(id_card_back)" json:"idCardBack"` + IDCardHand string `orm:"size(255);column(id_card_hand)" json:"idCardHand"` + Licence string `orm:"size(255)" json:"licence"` + LicenceCode string `orm:"size(32);index" json:"licenceCode"` + Remark string `orm:"type(text)" json:"-"` +} + +// const ( +// PaymentType +// ) +type UserPayment struct { + ModelIDCULD + UserID string `orm:"size(48);column(user_id)" json:"userID"` // 内部唯一标识 + Type int8 // +} + +type UserDeliveryAddress struct { + ModelIDCULD + + UserID string `orm:"size(48);column(user_id)" json:"userID"` // 内部唯一标识 + + Tag string `orm:"size(32)" json:"tag"` + ConsigneeName string `orm:"size(32)" json:"consigneeName"` + ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"` + Address string `orm:"size(255)" json:"address"` // 地址(区县以下,门牌号以上的地址信息) + DetailAddress string `orm:"size(255)" json:"detailAddress"` // 门牌号 + Lng float64 `orm:"digits(10);decimals(6)" json:"lng"` + Lat float64 `orm:"digits(10);decimals(6)" json:"lat"` + + AutoAddress string `orm:"size(255)" json:"autoAddress"` // 这个是通过坐标自动获取的结构化的地址 + CityCode int `orm:"default(0);null" json:"cityCode"` // 根据坐标获得 + DistrictCode int `orm:"default(0);null" json:"districtCode"` // 根据坐标获得 + + Remark string `orm:"type(text)" json:"remark"` + IsDefault int8 `json:"isDefault"` +} + +func (*UserDeliveryAddress) TableUnique() [][]string { + return [][]string{ + // []string{"UserID", "ConsigneeMobile", "DeletedAt"}, + } +} + +type UserCartItem struct { + ID int64 `orm:"column(id)" json:"-"` + CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"` + UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"-"` + LastOperator string `orm:"size(32)" json:"-"` // 最后操作员 + + UserID string `orm:"size(48);column(user_id)" json:"userID"` + StoreID int `orm:"column(store_id)" json:"storeID"` + SkuID int `orm:"column(sku_id)" json:"skuID"` + ActID int `orm:"column(act_id)" json:"actID"` + + Count int `json:"count"` + Price int `json:"price"` + IsChecked int8 `json:"isChecked"` +} + +func (*UserCartItem) TableUnique() [][]string { + return [][]string{ + []string{"UserID", "StoreID", "SkuID", "ActID"}, + } +} + +type UserAgreement struct { + ModelIDCULD + Name string `orm:"size(32);index" json:"name"` // 外部显示标识(当前可以重复) + Mobile string `orm:"size(32)" json:"mobile"` + IDNumber string `orm:"column(id_number);size(20)" json:"idNumber"` + BankNumber string `orm:"size(32)" json:"bankNumber"` +} + +type UserOrderSms struct { + ID int64 `orm:"column(id)" json:"-"` + CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"` + UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"-"` + LastOperator string `orm:"size(32)" json:"-"` // 最后操作员 + + Mobile string `orm:"size(32)" json:"mobile"` + Name string `orm:"size(32)" json:"name"` + VendorUserID string `orm:"column(vendor_user_id)" json:"vendorUserID"` + SMSMark int `orm:"column(sms_mark)" json:"smsMark"` + TotalCount int `json:"totalCount"` +} + +func (*UserOrderSms) TableUnique() [][]string { + return [][]string{ + []string{"Mobile"}, + } +} + type UserMember struct { ModelIDCULD @@ -116,3 +220,58 @@ func (v *UserMember) TableIndex() [][]string { []string{"CreatedAt"}, } } + +type Role struct { + ModelIDCULD + + Name string `json:"name"` //角色名 +} + +func (*Role) TableUnique() [][]string { + return [][]string{ + []string{"Name", "DeletedAt"}, + } +} + +type UserRole struct { + ModelIDCULD + + UserID string `orm:"column(user_id)" json:"userID"` //用户ID + RoleID int `orm:"column(role_id)" json:"roleID"` //角色ID +} + +func (*UserRole) TableUnique() [][]string { + return [][]string{ + []string{"UserID", "RoleID", "DeletedAt"}, + } +} + +type Menu struct { + ModelIDCULD + + Name string `json:"name"` //功能名 + URL string `orm:"column(url)" json:"url"` //路径 + ImgURL string `orm:"column(img_url)" json:"imgURL"` //图标 + Level int `json:"level"` //级别 + ParentID int `orm:"column(parent_id)" json:"parentID"` //父功能ID + Color string `json:"color"` //颜色 +} + +func (*Menu) TableUnique() [][]string { + return [][]string{ + []string{"Name", "DeletedAt"}, + } +} + +type RoleMenu struct { + ModelIDCULD + + RoleID int `orm:"column(role_id)" json:"roleID"` //角色ID + MenuID int `orm:"column(menu_id)" json:"menuID"` //功能ID +} + +func (*RoleMenu) TableUnique() [][]string { + return [][]string{ + []string{"MenuID", "RoleID", "DeletedAt"}, + } +} diff --git a/business/partner/partner_spider.go b/business/partner/partner_spider.go deleted file mode 100644 index 699dcd66b..000000000 --- a/business/partner/partner_spider.go +++ /dev/null @@ -1,14 +0,0 @@ -package partner - -import ( - "git.rosy.net.cn/jx-callback/business/jxutils/ditu" - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" - "git.rosy.net.cn/jx-callback/business/model" -) - -type IPurchasePlatformNetSpiderHandler interface { - GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) - GetStorePageInfo(ctx *jxcontext.Context, storeID string) (storePageInfo *model.PageShop, err error) - - // GetStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, cityInfo string, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) -} diff --git a/business/partner/purchase/ebai/net_spider.go b/business/partner/purchase/ebai/net_spider.go deleted file mode 100644 index 37fd010c3..000000000 --- a/business/partner/purchase/ebai/net_spider.go +++ /dev/null @@ -1,65 +0,0 @@ -package ebai - -import ( - "git.rosy.net.cn/baseapi/platformapi/ebaiapi" - "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxutils/ditu" - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" - "git.rosy.net.cn/jx-callback/business/model" - "git.rosy.net.cn/jx-callback/globals/api" -) - -func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) { - shopListInfo, err := api.EbaiAPI.GetStoreList2(coord.Lng, coord.Lat) - if err != nil { - return nil, err - } - if shopListInfo != nil { - for _, v := range shopListInfo.ShopList { - storeIDList = append(storeIDList, v.ShopInfo.Wid) - } - } - return storeIDList, nil -} - -func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, storeID string) (storePageInfo *model.PageShop, err error) { - shopInfo, err2 := api.EbaiAPI.GetStoreInfo2(storeID) - if err = err2; err == nil && shopInfo != nil { - // 饿百扒下来的坐标是加了密的,不能用 - // lng, lat, _ := api.AutonaviAPI.CoordinateConvert(shopInfo.Longitude/100000, shopInfo.Latitude/100000, autonavi.CoordSysBaidu) - storePageInfo = &model.PageShop{ - Name: shopInfo.Name, - VendorID: model.VendorIDEBAI, - VendorStoreID: storeID, - OrgCode: shopInfo.Brand, - VendorStatus: utils.Int2Str(shopInfo.BusinessStatus), - - Address: shopInfo.Address, - Lng: 0, - Lat: 0, - DistrictCode: 0, - - Tel1: shopInfo.Phone, - - RecentOrderNum: shopInfo.RecentOrderNum, - SkuCount: shopInfo.SkuCount, - BusinessType: shopInfo.Category, - ShopScore: float64(shopInfo.ShopScore), - } - storePageInfo.LicenceCode, storePageInfo.LicenceImg = getLicenceInfoFromShopInfo(shopInfo) - } - return storePageInfo, err -} - -func getLicenceInfoFromShopInfo(storeInfo *ebaiapi.PageShopInfo) (licenceCode, licenceImg string) { - for _, v := range storeInfo.MedicineQualification { - if v.AptitudeType == "101" { // 营业执照 - licenceCode = v.LicenseNumber - if len(v.AptitudePhoto) > 0 { - licenceImg = v.AptitudePhoto[0] - } - break - } - } - return licenceCode, licenceImg -} diff --git a/business/partner/purchase/jd/net_spider.go b/business/partner/purchase/jd/net_spider.go deleted file mode 100644 index 6093e3216..000000000 --- a/business/partner/purchase/jd/net_spider.go +++ /dev/null @@ -1,54 +0,0 @@ -package jd - -import ( - "fmt" - - "git.rosy.net.cn/baseapi/platformapi/jdapi" - "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxutils/ditu" - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" - "git.rosy.net.cn/jx-callback/business/model" - "git.rosy.net.cn/jx-callback/globals/api" -) - -func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) { - shopListInfo, err := api.JdPageAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat)) - if err != nil { - // time.Sleep(5 * time.Second) - return nil, err - } - if shopListInfo != nil { - shopDataList, _ := shopListInfo["data"].(map[string]interface{})["data"].([]interface{}) - for _, v := range shopDataList { - floorCellData := v.(map[string]interface{})["floorCellData"].(map[string]interface{}) - storeIDList = append(storeIDList, utils.Interface2String(floorCellData["storeId"])) - } - } - return storeIDList, nil -} - -func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, storeID string) (storePageInfo *model.PageShop, err error) { - shopInfo, err2 := api.JdPageAPI.GetStoreInfo2(storeID) - if err = err2; err == nil && shopInfo != nil { - return &model.PageShop{ - Name: shopInfo.StoreInfo.StoreName, - VendorID: model.VendorIDJD, - VendorStoreID: storeID, - OrgCode: shopInfo.StoreInfo.OrgCode, - VendorStatus: utils.Int2Str(shopInfo.StoreInfo.StationStatus), - - Address: shopInfo.StoreInfo.StoreAddress, - Lng: 0, - Lat: 0, - DistrictCode: 0, - - Tel1: shopInfo.StoreInfo.StoreTel, - - RecentOrderNum: jdapi.MonthSaleNum2Int(shopInfo.StoreInfo.MonthSaleNum), - SkuCount: int(utils.Str2Int64WithDefault(shopInfo.StoreInfo.InSaleNum, 0)), - BusinessType: shopInfo.StoreInfo.Industry, - ShopScore: float64(shopInfo.StoreCommentVO.ScoreAvg), - }, nil - } - return nil, err -}