yinbaoshangpinupdate
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package yinbaoapi
|
package yinbaoapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
@@ -16,6 +18,10 @@ const (
|
|||||||
MainStoreVendorOrgCode = "3933189"
|
MainStoreVendorOrgCode = "3933189"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
regexpSkuID = regexp.MustCompile(`<tr data="(.*?)"`)
|
||||||
|
)
|
||||||
|
|
||||||
func (a *API) AccessStorePage(action string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
func (a *API) AccessStorePage(action string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
fullURL := utils.GenerateGetURL(pageUrl, action, nil)
|
fullURL := utils.GenerateGetURL(pageUrl, action, nil)
|
||||||
// result, _ := json.MarshalIndent(bizParams, "", " ")
|
// result, _ := json.MarshalIndent(bizParams, "", " ")
|
||||||
@@ -189,3 +195,168 @@ func (a *API) LoadCategorysWithOption(userId string) (loadCategorysWithOptionRes
|
|||||||
}
|
}
|
||||||
return loadCategorysWithOptionResult, err
|
return loadCategorysWithOptionResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取单个商品id
|
||||||
|
//https://beta27.pospal.cn/Product/LoadProductsByPage
|
||||||
|
func (a *API) LoadProductsByPage(userId, keyword string) (v string, err error) {
|
||||||
|
result, err := a.AccessStorePage("Product/LoadProductsByPage", map[string]interface{}{
|
||||||
|
"userId": userId,
|
||||||
|
"keyword": keyword,
|
||||||
|
"pageIndex": 1,
|
||||||
|
"pageSize": 50,
|
||||||
|
"enable": 1,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
body := result["contentView"].(string)
|
||||||
|
if strings.Contains(body, "未查询到符合条件的记录") {
|
||||||
|
err = utils.NewErrorCode("未查询到符合条件的记录!", "-1", 0)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
result := regexpSkuID.FindStringSubmatch(body)
|
||||||
|
return result[1], err
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
type FindProductResult struct {
|
||||||
|
Category struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
UserID int `json:"userId"`
|
||||||
|
UID int64 `json:"uid"`
|
||||||
|
ParentUID int64 `json:"parentUid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Enable int `json:"enable"`
|
||||||
|
CreatedDatetime string `json:"createdDatetime"`
|
||||||
|
UpdatedDatetime string `json:"updatedDatetime"`
|
||||||
|
CategoryType int `json:"categoryType"`
|
||||||
|
TxtUID string `json:"txtUid"`
|
||||||
|
} `json:"category"`
|
||||||
|
Productimages []interface{} `json:"productimages"`
|
||||||
|
CategoryShowID int `json:"categoryShowId"`
|
||||||
|
ParentHas int `json:"parentHas"`
|
||||||
|
TxtUID string `json:"txtUid"`
|
||||||
|
UpdateStock float64 `json:"updateStock"`
|
||||||
|
IsOutOfStock bool `json:"isOutOfStock"`
|
||||||
|
ProductUnitExchangeList []interface{} `json:"productUnitExchangeList"`
|
||||||
|
BaseUnitName string `json:"baseUnitName"`
|
||||||
|
IsCurrentPrice bool `json:"isCurrentPrice"`
|
||||||
|
DisableEntireDiscount bool `json:"disableEntireDiscount"`
|
||||||
|
IsPrior bool `json:"isPrior"`
|
||||||
|
ProductTags []interface{} `json:"productTags"`
|
||||||
|
CustomerPrices []interface{} `json:"customerPrices"`
|
||||||
|
EnableBatch int `json:"enableBatch"`
|
||||||
|
HideFromClient int `json:"hideFromClient"`
|
||||||
|
SpecNum int `json:"specNum"`
|
||||||
|
IsEnableVirtualStock bool `json:"isEnableVirtualStock"`
|
||||||
|
IsPassPromotionProduct bool `json:"isPassPromotionProduct"`
|
||||||
|
IsBindPassProduct bool `json:"isBindPassProduct"`
|
||||||
|
IgnoreStock bool `json:"ignoreStock"`
|
||||||
|
DataIndex int `json:"dataIndex"`
|
||||||
|
SellPriceIsNull bool `json:"sellPriceIsNull"`
|
||||||
|
Spu string `json:"spu"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
UID int64 `json:"uid"`
|
||||||
|
CategoryUID int64 `json:"categoryUid"`
|
||||||
|
UserID int `json:"userId"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Barcode string `json:"barcode"`
|
||||||
|
BuyPrice float64 `json:"buyPrice"`
|
||||||
|
SellPrice float64 `json:"sellPrice"`
|
||||||
|
Stock float64 `json:"stock"`
|
||||||
|
MaxStock float64 `json:"maxStock"`
|
||||||
|
MinStock float64 `json:"minStock"`
|
||||||
|
Pinyin string `json:"pinyin"`
|
||||||
|
SellPrice2 float64 `json:"sellPrice2"`
|
||||||
|
IsPoint int `json:"isPoint"`
|
||||||
|
Enable int `json:"enable"`
|
||||||
|
CreatedDatetime string `json:"createdDatetime"`
|
||||||
|
ProductTastes []interface{} `json:"productTastes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取单个商品信息
|
||||||
|
//https://beta27.pospal.cn/Product/FindProduct
|
||||||
|
func (a *API) FindProduct(productId string) (findProductResult *FindProductResult, err error) {
|
||||||
|
result, err := a.AccessStorePage("Product/FindProduct", map[string]interface{}{
|
||||||
|
"productId": productId,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
utils.Map2StructByJson(result["product"], &findProductResult, false)
|
||||||
|
}
|
||||||
|
return findProductResult, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新单个商品信息(称编码)
|
||||||
|
//Request URL: https://beta27.pospal.cn/Product/SaveProduct
|
||||||
|
func (a *API) SaveProduct(userId, keyword string) (err error) {
|
||||||
|
productId, err := a.LoadProductsByPage(userId, keyword)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
findProductResult, err := a.FindProduct(productId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
params2 := map[string]interface{}{
|
||||||
|
"pluCode": findProductResult.Barcode[3:],
|
||||||
|
}
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"id": utils.Int2Str(findProductResult.ID),
|
||||||
|
"enable": utils.Int2Str(findProductResult.Enable),
|
||||||
|
"userId": utils.Int2Str(findProductResult.UserID),
|
||||||
|
"barcode": findProductResult.Barcode,
|
||||||
|
"name": findProductResult.Name,
|
||||||
|
"categoryUid": utils.Int64ToStr(findProductResult.CategoryUID),
|
||||||
|
"categoryName": findProductResult.Category.Name,
|
||||||
|
"sellPrice": utils.Float64ToStr(findProductResult.SellPrice),
|
||||||
|
"buyPrice": utils.Float64ToStr(findProductResult.BuyPrice),
|
||||||
|
"isCustomerDiscount": "1",
|
||||||
|
"customerPrice": "",
|
||||||
|
"sellPrice2": utils.Float64ToStr(findProductResult.SellPrice2),
|
||||||
|
"pinyin": findProductResult.Pinyin,
|
||||||
|
"supplierUid": "",
|
||||||
|
"supplierName": "无",
|
||||||
|
"productionDate": "",
|
||||||
|
"shelfLife": "",
|
||||||
|
"maxStock": utils.Float64ToStr(findProductResult.MaxStock),
|
||||||
|
"minStock": utils.Float64ToStr(findProductResult.MinStock),
|
||||||
|
"stock": utils.Float64ToStr(findProductResult.Stock),
|
||||||
|
"description": "",
|
||||||
|
"noStock": "0",
|
||||||
|
"productCommonAttribute": params2,
|
||||||
|
"baseUnitName": findProductResult.BaseUnitName,
|
||||||
|
"customerPrices": []string{},
|
||||||
|
"productUnitExchangeList": []string{},
|
||||||
|
"productTags": []string{},
|
||||||
|
"productTastes": []string{},
|
||||||
|
"attribute1": "",
|
||||||
|
"attribute2": "",
|
||||||
|
"attribute3": "",
|
||||||
|
"attribute4": "",
|
||||||
|
"attribute6": "",
|
||||||
|
}
|
||||||
|
result, _ := json.Marshal(params)
|
||||||
|
_, err = a.AccessStorePage("Product/SaveProduct", map[string]interface{}{
|
||||||
|
"productJson": string(result),
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//登录?
|
||||||
|
//https://beta27.pospal.cn/account/SignIn?noLog=
|
||||||
|
//userName: 18048531223
|
||||||
|
// password: Rosy201507
|
||||||
|
// returnUrl:
|
||||||
|
// screenSize: 1600*900
|
||||||
|
//Accept: application/json, text/javascript, */*; q=0.01
|
||||||
|
//Accept-Encoding: gzip, deflate, br
|
||||||
|
//Accept-Language: zh-CN,zh;q=0.9
|
||||||
|
//Connection: keep-alive
|
||||||
|
//Content-Length: 71
|
||||||
|
//Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||||
|
//Host: beta27.pospal.cn
|
||||||
|
//Origin: https://beta27.pospal.cn
|
||||||
|
//Referer: https://beta27.pospal.cn/account/signin
|
||||||
|
//Sec-Fetch-Mode: cors
|
||||||
|
//Sec-Fetch-Site: same-origin
|
||||||
|
//User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
|
||||||
|
//X-Requested-With: XMLHttpRequest
|
||||||
|
|||||||
@@ -53,3 +53,26 @@ func TestLoadCategorysWithOption(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log(utils.Format4Output(result, false))
|
t.Log(utils.Format4Output(result, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadProductsByPage(t *testing.T) {
|
||||||
|
result, err := api.LoadProductsByPage(MainStoreVendorOrgCode, "0000001")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindProduct(t *testing.T) {
|
||||||
|
result, err := api.FindProduct("7818179")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSaveProduct(t *testing.T) {
|
||||||
|
err := api.SaveProduct(MainStoreVendorOrgCode, "0000001")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func init() {
|
|||||||
sugarLogger = logger.Sugar()
|
sugarLogger = logger.Sugar()
|
||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
api = New("682628966212343269", "18C0E0867E467DBC26EFF5E957B02EC4") //总店
|
api = New("682628966212343269", "18C0E0867E467DBC26EFF5E957B02EC4") //总店
|
||||||
api.SetCookie(".POSPALAUTH30220", "0102B128D1E568D0D708FEB190954771D0D708000833003900330033003100380039003A0000012F00FF27DD332FACE5011FCB641B9C049B0882ED228F18")
|
api.SetCookie(".POSPALAUTH30220", "010214EB504F27D2D708FE145315B12FD2D708000833003900330033003100380039003A0000012F00FFAFFECF157DB55356D2DA4F6E2B3CDB5BCD9B47C2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddProductInfo(t *testing.T) {
|
func TestAddProductInfo(t *testing.T) {
|
||||||
@@ -28,11 +28,12 @@ func TestAddProductInfo(t *testing.T) {
|
|||||||
result, err := api.AddProductInfo(&ProductInfoParam{
|
result, err := api.AddProductInfo(&ProductInfoParam{
|
||||||
ProductInfo: &ProductInfo{
|
ProductInfo: &ProductInfo{
|
||||||
Name: "测试商品",
|
Name: "测试商品",
|
||||||
Barcode: "12132",
|
Barcode: "12131",
|
||||||
BuyPrice: &stock,
|
BuyPrice: &stock,
|
||||||
SellPrice: &stock,
|
SellPrice: &stock,
|
||||||
Stock: &stock,
|
Stock: &stock,
|
||||||
SupplierUID: 123,
|
SupplierUID: 123,
|
||||||
|
CategoryUID: 1585290800642661192,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user