This commit is contained in:
苏尹岚
2020-12-03 16:59:23 +08:00
parent a73cba5328
commit 503d91b3fa

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
"git.rosy.net.cn/baseapi/utils"
@@ -99,25 +100,74 @@ func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
CategoryName: jdshopapi.JdsStoreCategoryName,
CustomerID: utils.Int2Str(store.ID),
}
createEntityStoreParam2 := &jdshopapi.CreateEntityStoreParam{
Name: "京西菜市" + strings.ReplaceAll(store.Name, "店", "") + "生鲜店",
AddCode: store.JdsCode,
AddCodeName: store.DistrictName,
AddName: store.ProvinceName + store.CityName + store.DistrictName + "@!" + store.Address,
Coordinate: utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lat)) + "," + utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lng)),
Phone: store.Tel1,
ExtendJSON: string(timeJSON),
ImageFile: base64.StdEncoding.EncodeToString(data),
CategoryName: "生鲜店",
CustomerID: utils.Int2Str(store.ID),
url, _ := api.JdShop2API.UploadImageNew(data, "2659335b16e3880e367759b8fc675933.tem.png")
ex := store.LicenceExpire
if ex == "" {
ex = utils.Time2Str(utils.Str2Time(store.LicenceValid).AddDate(0, 6, 0))
}
if !strings.Contains(ex, "00:00:00") {
ex += " 00:00:00"
}
var url2 string
if store.Licence != "" {
data2, _, _ := jxutils.DownloadFileByURL(store.Licence)
fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)]
url2, _ = api.JdShop2API.UploadImageNew(data2, fileName)
}
storeName := store.Name
if strings.Contains(storeName, "") {
storeName = storeName[0:strings.Index(storeName, "")] + storeName[strings.Index(storeName, "")+3:len(storeName)]
}
if strings.Contains(storeName, "(") {
storeName = storeName[0:strings.Index(storeName, "(")] + storeName[strings.Index(storeName, ")")+3:len(storeName)]
}
if strings.Contains(storeName, ".") {
storeName = strings.ReplaceAll(storeName, ".", "")
}
if strings.Contains(storeName, "-") {
storeName = strings.ReplaceAll(storeName, "-", "")
}
if strings.Contains(storeName, " ") {
storeName = strings.ReplaceAll(storeName, " ", "")
}
storeName = "京西菜市" + strings.ReplaceAll(storeName, "店", "") + "生鲜店"
if len(storeName) > 30 {
storeName = utils.LimitUTF8StringLen2(storeName, 30)
}
param := &jdshopapi.UpdateBasicParam{
StoreName: storeName,
CategoryID2: 4,
Coordinate: utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lat)) + "," + utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lng)),
BussinessBeginTime: int2TimeStr(int(store.OpenTime1)),
BussinessEndTime: int2TimeStr(int(store.CloseTime1)),
ImgURL: url,
StorePhone: store.Tel1,
AddName: store.Address,
AddCode3: store.JdsCode,
CategoryID1: 3,
}
if url2 != "" {
param.CategoryID1 = 34
param.CategoryID2 = 62
param.QualificationRequests = []*jdshopapi.QualificationRequests{
&jdshopapi.QualificationRequests{
QualificationID: 41,
QualificationName: "营业执照",
QualificationNo: store.LicenceCode,
QualificationURL: url2,
StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)),
EndingTime: ex,
Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex},
},
}
}
if store.JdsStreetCode != 0 {
createEntityStoreParam.AddCode = store.JdsStreetCode
createEntityStoreParam2.AddCode = store.JdsStreetCode
param.AddCode3 = store.JdsStreetCode
}
if createEntityStoreParam.AddCode == 0 {
createEntityStoreParam.AddCode = store.JdCode
createEntityStoreParam2.AddCode = store.JdCode
param.AddCode3 = store.JdCode
}
//证明这个店可能隶属直辖市或者东莞
if model.ZXCityCodeMap[store.CityCode] != "" {
@@ -135,7 +185,7 @@ func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
for _, vvv := range result3 {
if street == vvv.AreaName {
createEntityStoreParam.AddCode = vvv.AreaID
createEntityStoreParam2.AddCode = vvv.AreaID
param.AddCode3 = vvv.AreaID
break
}
}
@@ -147,68 +197,20 @@ func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
}
}
vendorStoreID, err = api.JdShopAPI.CreateEntityStore(createEntityStoreParam)
vendorStoreID2, _ := api.JdShop2API.CreateEntityStore(createEntityStoreParam2)
if shopDetailResult, err := api.JdShop2API.ShopDetail(utils.Str2Int(vendorStoreID2)); err == nil {
if store.Licence != "" {
var storeName string
data, _, _ := jxutils.DownloadFileByURL(store.Licence)
fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)]
url, _ := api.JdShop2API.UploadImageNew(data, fileName)
ex := store.LicenceExpire
if ex == "" {
ex = utils.Time2Str(utils.Str2Time(store.LicenceValid).AddDate(0, 6, 0))
}
if !strings.Contains(ex, "00:00:00") {
ex += " 00:00:00"
}
if strings.Contains(store.Name, "") {
storeName = store.Name[0:strings.Index(store.Name, "")] + store.Name[strings.Index(store.Name, "")+3:len(store.Name)]
}
if strings.Contains(store.Name, ".") {
storeName = store.Name[0:strings.Index(store.Name, ".")] + store.Name[strings.Index(store.Name, ".")+1:len(store.Name)]
}
err = api.JdShop2API.UpdateBasic(&jdshopapi.UpdateBasicParam{
StoreID: utils.Str2Int(vendorStoreID2),
StoreName: storeName,
CategoryID2: 62,
Coordinate: shopDetailResult.Coordinate,
BussinessBeginTime: shopDetailResult.BussinessBeginTime,
BussinessEndTime: shopDetailResult.BussinessEndTime,
ImgURL: shopDetailResult.ImgURL,
StorePhone: shopDetailResult.StorePhone,
AddName: shopDetailResult.AddName,
AddCode1: shopDetailResult.AddCode1,
AddCode2: shopDetailResult.AddCode2,
AddCode3: shopDetailResult.AddCode3,
CategoryID1: 34,
QualificationRequests: []*jdshopapi.QualificationRequests{
&jdshopapi.QualificationRequests{
QualificationID: 41,
QualificationName: "营业执照",
QualificationNo: store.LicenceCode,
QualificationURL: url,
StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)),
EndingTime: ex,
Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex},
},
},
})
err = api.JdShop2API.UpdateExpand(utils.Str2Int(vendorStoreID2))
if err == nil {
var storeMap *model.StoreMap
sql := `
SELECT * FROM store_map WHERE deletad_at = ? AND store_id = ? AND vendor_id = ? AND vendor_org_code = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue, storeID, model.VendorIDJDShop, "2",
}
if err = dao.GetRow(db, &storeMap, sql, sqlParams); err == nil {
if storeMap != nil {
storeMap.VendorStoreID = vendorStoreID2
_, err = dao.UpdateEntity(db, storeMap, "VendorStoreID")
}
}
}
if vendorStroeID2, err := api.JdShop2API.SubmitBasic(param); err == nil {
time.Sleep(time.Second)
err = api.JdShop2API.UpdateExpand(int(vendorStroeID2))
var storeMap *model.StoreMap
sql := `
SELECT * FROM store_map WHERE deletad_at = ? AND store_id = ? AND vendor_id = ? AND vendor_org_code = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue, storeID, model.VendorIDJDShop, "2",
}
err = dao.GetRow(db, &storeMap, sql, sqlParams)
if storeMap != nil {
storeMap.VendorStoreID = utils.Int64ToStr(vendorStroeID2)
_, err = dao.UpdateEntity(db, storeMap, "VendorStoreID")
}
}
return vendorStoreID, err