sc-common-interface 2.5.8__tar.gz → 2.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.5.8
3
+ Version: 2.6.0
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -197,8 +197,17 @@ def get_live_info(data):
197
197
  headers = data["headers"]
198
198
  sales_id = data["sales_id"]
199
199
  url = "%s/api/posts/live/sales/%s" % (env, sales_id)
200
- response = requests.get(url,headers=headers).json()
201
- return response
200
+ count = 0
201
+ while True:
202
+ response = requests.get(url,headers=headers)
203
+ if response.status_code==200:
204
+ return response.json()
205
+ else:
206
+ count=count+1
207
+ if count>10:
208
+ print("查询报错")
209
+ return response
210
+
202
211
 
203
212
 
204
213
 
@@ -429,7 +438,7 @@ def create_live(data):
429
438
  stamp = int(time.time())
430
439
  title = "接口创建的直播活动名称%d"%stamp
431
440
  salesDescription = "接口创建的直播活动介绍%d"%stamp
432
- salesOwner = "接口创建的直播主%d"%stamp
441
+ salesOwner = "接口创建的直播主%d"%stamp
433
442
  platform = "FB_GROUP"
434
443
  patternModel = "INCLUDE_MATCH"
435
444
  keywordValidInLive = True
@@ -700,11 +709,18 @@ def create_live(data):
700
709
  },
701
710
  "postConfigMap":{}
702
711
  }
703
- response = requests.post(url,headers=headers,json=body).json()
712
+ count = 0
713
+ while True:
714
+ response = requests.post(url,headers=headers,json=body)
715
+ if response.status_code==200 and response.json()["code"]=="SUCCESS":
716
+ sales_id = response.json()["data"]["sales"]["id"]
717
+ return sales_id
718
+ else:
719
+ count=count+1
720
+ if count>10:
721
+ return response
722
+
704
723
  # print(json.dumps(body))
705
- print(response)
706
- sales_id = response["data"]["sales"]["id"]
707
- return sales_id
708
724
 
709
725
 
710
726
  def add_live(data):
@@ -1475,18 +1491,47 @@ def get_live_product(data):
1475
1491
  return response
1476
1492
 
1477
1493
  def search_product_set(data):
1494
+ """查询直播间组合商品列表"""
1478
1495
  env = data["env"]
1479
1496
  headers = data["headers"]
1480
1497
  sales_id = data["sales_id"]
1481
1498
  query = ""
1499
+ pageNum = 1
1500
+ if "pageNum" in data:
1501
+ pageNum = data["pageNum"]
1482
1502
  if "query" in data:
1483
1503
  query = data["query"]
1484
1504
  url = "%s/admin/api/bff-web/live/sale/%s/sale_list/product_set"%(env,sales_id)
1485
- param = {"pageNum":1,"pageSize":10,"query":query,"queryType":"PRODUCT_NAME"}
1505
+ param = {"pageNum":pageNum,"pageSize":10,"query":query,"queryType":"PRODUCT_NAME"}
1486
1506
  # print(param)
1487
1507
  res = requests.get(url,headers=headers,params=param).json()
1488
1508
  return res
1489
1509
 
1510
+ def get_product_set(data):
1511
+ """查询来添加组合商品"""
1512
+ env = data["env"]
1513
+ headers = data["headers"]
1514
+ sales_id = data["sales_id"]
1515
+ query = ""
1516
+ pageNum = 1
1517
+ if "pageNum" in data:
1518
+ pageNum = data["pageNum"]
1519
+ if "query" in data:
1520
+ query = data["query"]
1521
+ url = "%s/admin/api/bff-web/live/sale/%s/product/product_set/list"%(env,sales_id)
1522
+ param = {"pageNum":pageNum,"pageSize":10,"query":query}
1523
+ # print(param)
1524
+ count = 0
1525
+ while True:
1526
+ res = requests.get(url, headers=headers, params=param)
1527
+ if res.status_code==200:
1528
+ return res.json()
1529
+ else:
1530
+ count+=1
1531
+ if count>10:
1532
+ print("查询get_product_set 异常")
1533
+ return res
1534
+
1490
1535
  def get_sales_keyword(data):
1491
1536
  env = data["env"]
1492
1537
  headers = data["headers"]
@@ -1547,342 +1592,168 @@ def change_product_set_keyword_status(data):
1547
1592
  return response
1548
1593
 
1549
1594
 
1550
-
1551
-
1552
- if __name__=="__main__":
1553
- data = {
1554
- "success": True,
1555
- "code": "SUCCESS",
1556
- "message": "success",
1557
- "data": {
1558
- "pageInfo": {
1559
- "pageNum": 1,
1560
- "pageSize": 10,
1561
- "total": 5,
1562
- "lastPage": True
1563
- },
1564
- "list": [
1595
+ def get_produnct_set_detail(data):
1596
+ # print(data)
1597
+ env = data["env"]
1598
+ headers = data["headers"]
1599
+ spu_ids = data["spu_ids"]
1600
+ sales_id = data["sales_id"]
1601
+ url = "%s/admin/api/bff-web/live/sale/%s/product/product/list" % (env, sales_id)
1602
+ body = {
1603
+ "ids": spu_ids,
1604
+ "pageNum": 1,
1605
+ "pageSize": 101
1606
+ }
1607
+ count = 0
1608
+ while True:
1609
+ response = requests.post(url, headers=headers, json=body)
1610
+ if response.status_code==200:
1611
+ return response.json()
1612
+ else:
1613
+ count+=1
1614
+ if count>10:
1615
+ print("查询get_produnct_set_detail 异常")
1616
+ return response
1617
+
1618
+
1619
+ def add_specific_product_set_to_live(data):
1620
+ env = data["env"]
1621
+ headers = data["headers"]
1622
+ sales_id = data["sales_id"]
1623
+ set_list_res = get_product_set(data)
1624
+ data_list = set_list_res["data"]["list"]
1625
+ arr = 0
1626
+ if "arr" in data:
1627
+ arr = data["arr"]
1628
+ if arr >len(data_list)-1:
1629
+ arr = 0
1630
+ product_info = data_list[arr]
1631
+ product_id = product_info["id"]
1632
+ childrenInfo = product_info["childrenInfo"]
1633
+ title = product_info["title"]
1634
+ spu_ids = list(childrenInfo.keys())
1635
+ # necessaryQuantitys = jsonpath(data_list, "$..necessaryQuantity")
1636
+ data["spu_ids"] = spu_ids
1637
+ # 查询子商品信息
1638
+ response = get_produnct_set_detail(data)
1639
+ products = []
1640
+ zi_list = response["data"]["list"]
1641
+ # print(vars["childrenInfo"])
1642
+ for i in zi_list:
1643
+ product = {}
1644
+ spu_id = i["id"]
1645
+ product["count"] = childrenInfo[spu_id]["necessaryQuantity"]
1646
+ product["spuId"] = spu_id
1647
+ variations = i["variations"]
1648
+ if variations == []:
1649
+ product["skuId"] = spu_id
1650
+ else:
1651
+ sku_id = variations[0]["id"]
1652
+ product["skuId"] = sku_id
1653
+ products.append(product)
1654
+
1655
+ url = "%s/admin/api/bff-web/live/sale/%s/sale_list/product_set" % (env, sales_id)
1656
+ keyword = "python添加商品关键子%d" % int(time.time())
1657
+ add_body = {
1658
+ "spuList": [
1565
1659
  {
1566
- "id": "6741acc0cfda6a000ead3544",
1567
- "image": "https://shoplineimg.com/61a87c9763b70c005106fbd0/6741acb473b250000b26861a/50xf.webp?source_format=jpeg\u0026cheap_resize=1",
1568
- "title": "无库存组合商品",
1569
- "recommend": {
1570
- "isActivity": True,
1571
- "recommendTime": True
1572
- },
1573
- "effectiveKey": True,
1660
+ "id": "%s" % product_id,
1574
1661
  "defaultKey": "",
1575
1662
  "combinationList": [
1576
1663
  {
1577
- "id": "943947ecdfff37355535ecea0bd17c11",
1578
- "price": {
1579
- "originCents": 900,
1580
- "origin": "900 ₫",
1581
- "salesCents": 500,
1582
- "sales": "500 ₫"
1583
- },
1584
- "keywords": [
1585
- "组合商品关键字1732366855"
1586
- ],
1587
- "products": [
1588
- {
1589
- "spuId": "674153b778cb880011e7dc9b",
1590
- "skuId": "674153b778cb880011e7dc9b",
1591
- "count": 2,
1592
- "name": "商品名称1732334518",
1593
- "quantity": 99,
1594
- "unlimitedQuantity": True
1595
- },
1596
- {
1597
- "spuId": "65e855cbaf49be000ee315a9",
1598
- "skuId": "65e855cbaf49be000ee315a9",
1599
- "count": 2,
1600
- "name": "无库存商品(不要删除)",
1601
- "quantity": 0,
1602
- "unlimitedQuantity": True
1603
- }
1604
- ],
1605
- "buyerProductCount": 0
1606
- }
1607
- ],
1608
- "availableStartTime": True,
1609
- "availableEndTime": True,
1610
- "tempPrice": {
1611
- "originCents": 900,
1612
- "origin": "900 ₫",
1613
- "salesCents": 500,
1614
- "sales": "500 ₫"
1615
- },
1616
- "childrenInfo": {
1617
- "65e855cbaf49be000ee315a9": {
1618
- "necessaryQuantity": 2,
1619
- "variations": []
1620
- },
1621
- "674153b778cb880011e7dc9b": {
1622
- "necessaryQuantity": 2,
1623
- "variations": []
1624
- }
1625
- },
1626
- "status": "active"
1627
- },
1628
- {
1629
- "id": "670fbd3dac9b6acdb37c8192",
1630
- "image": "https://shoplineimg.com/61a87c9763b70c005106fbd0/670fbd1fac9b6a65377c874a/50xf.webp?source_format=jpeg\u0026cheap_resize=1",
1631
- "title": "dyy组合商品变动-子商品从无规格变成多规格",
1632
- "recommend": {
1633
- "isActivity": True,
1634
- "recommendTime": "2024-11-23T20:26:54+08:00"
1635
- },
1636
- "effectiveKey": True,
1637
- "defaultKey": "C",
1638
- "combinationList": [
1639
- {
1640
- "id": "fc37396e6a9d294cec87752911092300",
1641
- "price": {
1642
- "originCents": 222,
1643
- "origin": "222 ₫",
1644
- "salesCents": 90,
1645
- "sales": "90 ₫"
1646
- },
1647
- "keywords": [
1648
- "C1"
1649
- ],
1650
- "products": [
1651
- {
1652
- "spuId": "670fbced7fb2d151ef8f665a",
1653
- "skuId": "670fc098b34584000d03a595",
1654
- "count": 2,
1655
- "name": "dyy商品从无规格变成多规格(蓝)",
1656
- "quantity": -1,
1657
- "unlimitedQuantity": True
1658
- },
1659
- {
1660
- "spuId": "670fbb5227a445000f12b050",
1661
- "skuId": "670fbb517e0510001fd941c9",
1662
- "count": 2,
1663
- "name": "模式4接口自动化添加的多规格商品1729084241(红,M)",
1664
- "quantity": 55,
1665
- "unlimitedQuantity": True
1666
- }
1667
- ],
1668
- "buyerProductCount": 1
1669
- }
1670
- ],
1671
- "availableStartTime": True,
1672
- "availableEndTime": True,
1673
- "tempPrice": {
1674
- "originCents": 222,
1675
- "origin": "222 ₫",
1676
- "salesCents": 90,
1677
- "sales": "90 ₫"
1678
- },
1679
- "childrenInfo": {
1680
- "670fbb5227a445000f12b050": {
1681
- "necessaryQuantity": 2,
1682
- "variations": [
1683
- "670fbb517e0510001fd941c9",
1684
- "670fbb517e0510001fd941ca",
1685
- "670fbb517e0510001fd941cb",
1686
- "670fbb517e0510001fd941cc"
1687
- ]
1688
- },
1689
- "670fbced7fb2d151ef8f665a": {
1690
- "necessaryQuantity": 2,
1691
- "variations": [
1692
- "670fc098b34584000d03a595",
1693
- "670fc098b34584000d03a596"
1694
- ]
1695
- }
1696
- },
1697
- "status": "active"
1698
- },
1699
- {
1700
- "id": "670f9464ac9b6ad8fd7c806b",
1701
- "image": "https://shoplineimg.com/61a87c9763b70c005106fbd0/670f9448ac9b6ad4297c80df/50xf.webp?source_format=jpeg\u0026cheap_resize=1",
1702
- "title": "dyy组合商品变动(子商品下的子规格被删除)0000",
1703
- "recommend": {
1704
- "isActivity": True,
1705
- "recommendTime": True
1706
- },
1707
- "effectiveKey": True,
1708
- "defaultKey": "B",
1709
- "combinationList": [
1710
- {
1711
- "id": "b7d9e9e56797242331a71e39f5b8ed4b",
1712
- "price": {
1713
- "originCents": 100,
1714
- "origin": "100 ₫",
1715
- "salesCents": 90,
1716
- "sales": "90 ₫"
1717
- },
1664
+ "products": products,
1718
1665
  "keywords": [
1719
- "B1"
1720
- ],
1721
- "products": [
1722
- {
1723
- "spuId": "670f94397fb2d18edc8f61bc",
1724
- "skuId": "670f9439a6ddbb00093ef3fa",
1725
- "count": 2,
1726
- "name": "dyy商品变动(子规格被删除)(紫色)",
1727
- "quantity": -1,
1728
- "unlimitedQuantity": True
1729
- }
1666
+ "%s" % keyword
1730
1667
  ],
1731
- "buyerProductCount": 0
1668
+ "skuId": ""
1732
1669
  }
1733
- ],
1734
- "availableStartTime": True,
1735
- "availableEndTime": True,
1736
- "tempPrice": {
1737
- "originCents": 100,
1738
- "origin": "100 ₫",
1739
- "salesCents": 90,
1740
- "sales": "90 ₫"
1741
- },
1742
- "childrenInfo": {
1743
- "670f94397fb2d18edc8f61bc": {
1744
- "necessaryQuantity": 2,
1745
- "variations": [
1746
- "670f9439a6ddbb00093ef3fa"
1747
- ]
1748
- }
1749
- },
1750
- "status": "active"
1751
- },
1752
- {
1753
- "id": "670f8a6c7fb2d15f7b8f6431",
1754
- "image": "https://shoplineimg.com/61a87c9763b70c005106fbd0/670f8a57b7b2cb000a26a9f6/50xf.webp?source_format=jpeg\u0026cheap_resize=1",
1755
- "title": "dyy超长的组合商品yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
1756
- "recommend": {
1757
- "isActivity": True,
1758
- "recommendTime": True
1759
- },
1760
- "effectiveKey": True,
1761
- "defaultKey": "A",
1762
- "combinationList": [
1670
+ ]
1671
+ }
1672
+ ]
1673
+ }
1674
+ try:
1675
+ #先删除再添加
1676
+ data["product_id"] = product_id
1677
+ delete_product_set(data)
1678
+ time.sleep(2)
1679
+ data_res = requests.post(url, headers=headers, json=add_body).json()
1680
+ return product_id,products,keyword,title,data_res
1681
+ except Exception:
1682
+ print("出现异常")
1683
+
1684
+ def add_mutil_product_set_to_live(data):
1685
+ """添加多规格商品的全部"""
1686
+ pass
1687
+
1688
+
1689
+ def add_all_product_set_to_live(data):
1690
+ env = data["env"]
1691
+ headers = data["headers"]
1692
+ sales_id = data["sales_id"]
1693
+ while True:
1694
+ print(data)
1695
+ set_list_res = get_product_set(data)
1696
+ print(set_list_res)
1697
+ data_list = set_list_res["data"]["list"]
1698
+ for product_info in data_list:
1699
+ product_id = product_info["id"]
1700
+ childrenInfo = product_info["childrenInfo"]
1701
+ spu_ids = list(childrenInfo.keys())
1702
+ # necessaryQuantitys = jsonpath(data_list, "$..necessaryQuantity")
1703
+ data["spu_ids"] = spu_ids
1704
+ #查询子商品信息
1705
+ response = get_produnct_set_detail(data)
1706
+ products = []
1707
+ zi_list = response["data"]["list"]
1708
+ # print(vars["childrenInfo"])
1709
+ for i in zi_list:
1710
+ product = {}
1711
+ spu_id = i["id"]
1712
+ product["count"] = childrenInfo[spu_id]["necessaryQuantity"]
1713
+ product["spuId"] = spu_id
1714
+ variations = i["variations"]
1715
+ if variations == []:
1716
+ product["skuId"] = spu_id
1717
+ else:
1718
+ sku_id = variations[0]["id"]
1719
+ product["skuId"] = sku_id
1720
+ products.append(product)
1721
+ url = "%s/admin/api/bff-web/live/sale/%s/sale_list/product_set"%(env,sales_id)
1722
+ keyword = "python添加商品关键子%d"%int(time.time())
1723
+ add_body = {
1724
+ "spuList": [
1763
1725
  {
1764
- "id": "c536c6eaffa7364a1dac2743aeff518a",
1765
- "price": {
1766
- "originCents": 100,
1767
- "origin": "100 ₫",
1768
- "salesCents": 90,
1769
- "sales": "90 ₫"
1770
- },
1771
- "keywords": [
1772
- "A1"
1773
- ],
1774
- "products": [
1775
- {
1776
- "spuId": "670f8a48b7b2cb384126a9bc",
1777
- "skuId": "670f8a48db1762000bcedfc8",
1778
- "count": 2,
1779
- "name": "dyy超长的商品yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy(dyy超长的商品yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy)",
1780
- "quantity": -1,
1781
- "unlimitedQuantity": True
1782
- },
1726
+ "id": "%s"%product_id,
1727
+ "defaultKey": "",
1728
+ "combinationList": [
1783
1729
  {
1784
- "spuId": "670f84314149e400117b3c6a",
1785
- "skuId": "670f84314bd7dd001035d0ea",
1786
- "count": 1,
1787
- "name": "多规格商品名称1729070129(红)",
1788
- "quantity": 50,
1789
- "unlimitedQuantity": True
1790
- }
1791
- ],
1792
- "buyerProductCount": 0
1793
- }
1794
- ],
1795
- "availableStartTime": True,
1796
- "availableEndTime": True,
1797
- "tempPrice": {
1798
- "originCents": 100,
1799
- "origin": "100 ₫",
1800
- "salesCents": 90,
1801
- "sales": "90 ₫"
1802
- },
1803
- "childrenInfo": {
1804
- "670f84314149e400117b3c6a": {
1805
- "necessaryQuantity": 1,
1806
- "variations": [
1807
- "670f84314bd7dd001035d0ea"
1808
- ]
1809
- },
1810
- "670f8a48b7b2cb384126a9bc": {
1811
- "necessaryQuantity": 2,
1812
- "variations": [
1813
- "670f8a48db1762000bcedfc8",
1814
- "670f8a48db1762000bcedfc9"
1730
+ "products": products,
1731
+ "keywords": [
1732
+ "%s"%keyword
1733
+ ],
1734
+ "skuId": ""
1735
+ }
1736
+ ]
1737
+ }
1815
1738
  ]
1816
1739
  }
1817
- },
1818
- "status": "active"
1819
- },
1820
- {
1821
- "id": "673c889f3dc982185de87d1c",
1822
- "image": "https://shoplineimg.com/61a87c9763b70c005106fbd0/673c889b52b9d600110bfc1c/50xf.webp?source_format=png\u0026cheap_resize=1",
1823
- "title": "ffsssdsfsfsf",
1824
- "recommend": {
1825
- "isActivity": True,
1826
- "recommendTime": True
1827
- },
1828
- "effectiveKey": True,
1829
- "defaultKey": "",
1830
- "combinationList": [
1831
- {
1832
- "id": "46df6fa5b6af8bcbec7aa28db26f1eae",
1833
- "price": {
1834
- "originCents": 455,
1835
- "origin": "455 ₫",
1836
- "salesCents": 55,
1837
- "sales": "55 ₫"
1838
- },
1839
- "keywords": [
1840
- "厨房风格"
1841
- ],
1842
- "products": [
1843
- {
1844
- "spuId": "673c311f52b9d659d30bf878",
1845
- "skuId": "673c311f52b9d659d30bf878",
1846
- "count": 2,
1847
- "name": "inbox自定义商品",
1848
- "quantity": 999999,
1849
- "unlimitedQuantity": True
1850
- },
1851
- {
1852
- "spuId": "673c2e5a3dc982185de87b57",
1853
- "skuId": "673c2e5a3dc982185de87b57",
1854
- "count": 2,
1855
- "name": "自定义商品哈哈哈",
1856
- "quantity": -1,
1857
- "unlimitedQuantity": True
1858
- }
1859
- ],
1860
- "buyerProductCount": 0
1861
- }
1862
- ],
1863
- "availableStartTime": True,
1864
- "availableEndTime": True,
1865
- "tempPrice": {
1866
- "originCents": 455,
1867
- "origin": "455 ₫",
1868
- "salesCents": 55,
1869
- "sales": "55 ₫"
1870
- },
1871
- "childrenInfo": {
1872
- "673c2e5a3dc982185de87b57": {
1873
- "necessaryQuantity": 2,
1874
- "variations": []
1875
- },
1876
- "673c311f52b9d659d30bf878": {
1877
- "necessaryQuantity": 2,
1878
- "variations": []
1879
- }
1880
- },
1881
- "status": "active"
1882
- }
1883
- ]
1884
- },
1885
- "traceId": "019833d17de727ab192e0fe3582c372e"
1886
- }
1887
- keyword, product_id,combination_id, __ = get_stock_product_set(data)
1888
- print(keyword)
1740
+ try:
1741
+ data_res = requests.post(url,headers=headers,json=add_body).json()
1742
+ print(data_res)
1743
+ except Exception:
1744
+ print("出现异常")
1745
+ lastPage = set_list_res["data"]["pageInfo"]["lastPage"]
1746
+ pageNum = set_list_res["data"]["pageInfo"]["pageNum"]
1747
+ print("加前的pagenum",pageNum)
1748
+ # print(lastPage)
1749
+ if lastPage == False:
1750
+ pageNum = pageNum + 1
1751
+ data["pageNum"] = pageNum
1752
+ print("pageNum=",pageNum)
1753
+ else:
1754
+ break
1755
+
1756
+ if __name__=="__main__":
1757
+ a =1
1758
+ a+=1
1759
+ print(a)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.5.8
3
+ Version: 2.6.0
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc-common-interface',
5
- version='2.5.8',
5
+ version='2.6.0',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),