Commit 5be4f3b6 by 岳巧源

1

parent d85dcc7c
Showing with 217 additions and 47 deletions
import hashlib
import json
import os
import logging
import pandas as pd
import pika
import requests
import config
log_path = "/data/golang/src/europa-erp-go/scripts/data_server/py_mq.log"
title_arr = [
"原厂型号",
"品牌",
"库存",
"起订量",
"阶梯数量1", "价格1",
"阶梯数量2", "价格2",
"阶梯数量3", "价格3",
"阶梯数量4", "价格4",
"阶梯数量5", "价格5",
"批次",
"增量",
"封装"
]
logging.basicConfig(level=logging.INFO,
filename=log_path,
format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s'
)
class Producer:
def __init__(self):
credentials = pika.PlainCredentials(username=config.rabbit_mq_user, password=config.rabbit_mq_password)
self.conn = pika.BlockingConnection(pika.ConnectionParameters(
host=config.rabbit_mq_host,
port=config.rabbit_mq_port,
credentials=credentials
))
channel = self.conn.channel()
channel.queue_declare(queue=config.rabbit_mq_queue_producer, durable=True)
self.channel = channel
def push(self, message):
self.channel.basic_publish(
exchange=config.rabbit_mq_exchange,
routing_key=config.rabbit_mq_routing_key,
body=str.encode(message))
def close(self):
try:
self.channel.close()
self.conn.close()
except Exception as e:
print(e)
"""判断传入的字符串是不是数字"""
def is_number(s: str):
if s.lower() == "nan":
return False
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
def resolve(file_name: str, supplier_id: int, sku_file_id: int):
producer = Producer()
df = pd.read_excel(file_name, sheet_name=0)
for i in range(len(df.index.values)):
goods_name = str(df.loc[i, "原厂型号"])
brand_name = str(df.loc[i, "品牌"])
currency = str(df.loc[i, "币种"])
if currency.strip() == "" or currency.strip() == "nan":
continue
currency = currency.upper().strip()
if currency != "USD" and currency != "RMB":
continue
if goods_name.strip() == "" or brand_name.strip() == "" or goods_name.strip() == "nan" or brand_name.strip() == "nan":
continue
if not is_number(str(df.loc[i, "库存"])) or not str(df.loc[i, "库存"]).isdigit():
stock = "0"
else:
stock = str(int(df.loc[i, "库存"]))
if not is_number(str(df.loc[i, "起订量"])) or not str(df.loc[i, "起订量"]).isdigit():
moq = "1"
else:
moq = str(int(df.loc[i, "起订量"]))
if not is_number(str(df.loc[i, "MPQ(最小包装数量)"])) or not str(df.loc[i, "MPQ(最小包装数量)"]).isdigit():
mpq = "1"
else:
mpq = str(int(df.loc[i, "MPQ(最小包装数量)"]))
if not is_number(str(df.loc[i, "增量"])) or not str(df.loc[i, "增量"]).isdigit():
multiple = "1"
else:
multiple = str(int(df.loc[i, "增量"]))
price_is_us = False
if currency == "USD":
price_is_us = True
supp_id = int(supplier_id)
supplier_name = ""
if not is_number(str(df.loc[i, "库存"])) or not str(df.loc[i, "库存"]).isdigit():
continue
batch_sn = {
str(df.loc[i, "批次"]): int(df.loc[i, "库存"]),
}
eccn = ""
if str(df.loc[i, "批次"]).strip() == "" or str(df.loc[i, "批次"]).strip() == "nan":
batch_sn = {}
table = {
"goods_name": goods_name,
"brand_name": brand_name,
"stock": stock,
"moq": moq,
"price_is_us": price_is_us,
"supplier_name": supplier_name,
"multiple": multiple,
"eccn": eccn,
"supplier_id": supp_id,
"batch_sn": batch_sn,
"ladder_price": [],
"goods_sn": "",
"mpq": mpq,
"sku_file_id": int(sku_file_id),
}
normal_text = (goods_name + brand_name + str(supplier_id) + str(df.loc[i, "封装"]) + str(df.loc[i, "批次"])).lower()
md = hashlib.md5(normal_text.encode())
md_str = md.hexdigest()
table["goods_sn"] = md_str
for index in range(1, 6):
if "阶梯数量" + str(index) not in df.columns:
continue
if "价格" + str(index) not in df.columns:
continue
ladder_data = df.loc[i, "阶梯数量" + str(index)]
price_data = df.loc[i, "价格" + str(index)]
if not is_number(str(price_data)) or not is_number(str(ladder_data)):
continue
if str(ladder_data).strip() != "" and str(ladder_data).strip() != "nan" and str(ladder_data).strip() != "NaN" and \
str(price_data).strip() != "" and str(price_data).strip() != "nan" and str(price_data).strip() != "NaN":
item_map = dict()
item_map["purchases"] = int(ladder_data)
if price_is_us:
item_map["price_us"] = float(price_data)
item_map["price_cn"] = float(0)
else:
item_map["price_us"] = float(0)
item_map["price_cn"] = float(price_data)
table["ladder_price"].append(item_map)
ans = json.dumps(table, ensure_ascii=False)
logging.info(ans)
producer.push(ans)
producer.close()
def process(url: str, supplier_id: int, sku_file_id: int):
# http://erp.liexindev.net/sku/20240823/p6jMKaPtjMpNnZMK5vEX3KEQf7Gdvgvw3TCA7d6b.xls
abs_path = ""
try:
response = requests.get(url)
if response.status_code == 200:
tmp_file = url.split(sep="/")[-1]
absolute_path = config.tmp_xls_file_dir + tmp_file
abs_path = absolute_path
with open(absolute_path, "wb") as f:
f.write(response.content)
resolve(absolute_path, supplier_id, sku_file_id)
except Exception as e:
logging.error(e)
finally:
if abs_path != "":
os.remove(abs_path)
......@@ -49,4 +49,5 @@ def post_to_jd():
if __name__ == '__main__':
post_to_jd()
\ No newline at end of file
s = ""
print(s.isdigit())
\ No newline at end of file
......@@ -49,3 +49,7 @@ create index sku_sn_shop_id_index on lie_shop_push_sku_log(sku_sn,shop_id);
select * from lie_shop_picture where lie_pdf != '' and lie_pdf not like '%172.18.137.41%' and lie_pdf not like '%files.ichunt.net%' and lie_pdf not like '%.pdf%' and lie_pdf not like '%toshiba.semicon-storage.com%' and lie_pdf not like '%www.microchip.com%' and lie_pdf not like '%www.ti.com%';
update lie_shop_picture set jd_pdf = '' where lie_pdf != '' and lie_pdf not like '%172.18.137.41%' and lie_pdf not like '%files.ichunt.net%' and lie_pdf not like '%.pdf%' and lie_pdf not like '%toshiba.semicon-storage.com%' and lie_pdf not like '%www.microchip.com%' and lie_pdf not like '%www.ti.com%';
create index shop_item_shop_id_index on lie_shop_sku(shop_item_id,shop_id);
alter table lie_shop_sku add column activity_id bigint unsigned default 0 not null comment '京东平台促销活动id' after shop_item_id;
\ No newline at end of file
......@@ -14,4 +14,10 @@
"sku_sn": "1155307286192804400_1",
}
.\gf_windows_amd64.exe gen dao -l "mysql:liexin_data_distribution:liexin_data_distribution#zsyM@tcp(192.168.1.238:3306)/liexin_data_distribution" -t "lie_shop_push_sku_log" -r "lie_"
\ No newline at end of file
/clearanceOptimize/list
/optimizeClearance/export
nohup /usr/bin/python3.6 /data/golang/src/europa-erp-go/scripts/data_server/server.py >>/data/golang/src/europa-erp-go/scripts/data_server/py_mq.log 2>&1 &
.\gf_windows_amd64.exe gen dao -l "mysql:liexin_data_distribution:liexin_data_distribution#zsyM@tcp(192.168.1.238:3306)/liexin_data_distribution" -t "lie_shop_sku" -r "lie_"
\ No newline at end of file
......@@ -456,8 +456,8 @@ def create_vc_promotion():
"@type": "com.jd.promo.activity.sdk.model.ActivityBaseDTO",
"name": "内部促销活动测试",
"type": 26,
"beginTime": "2024-11-18 00:00:00",
"endTime": "2024-11-21 00:00:00",
"beginTime": "2024-11-19 16:10:00",
"endTime": "2024-11-20 18:00:00",
"bound": 1,
"extType": 9302,
"venderType": 1,
......@@ -467,49 +467,13 @@ def create_vc_promotion():
"activityRuleDTOList": [
{
"discountDTO": {
"rebate": "9",
"rebate": "9.6",
},
"preConditionDTO": {
"needNum": 9,
},
"level": 1,
},
{
"discountDTO": {
"rebate": "8",
},
"preConditionDTO": {
"needNum": 99,
},
"level": 2,
},
{
"discountDTO": {
"rebate": "7",
},
"preConditionDTO": {
"needNum": 999,
},
"level": 3,
},
{
"discountDTO": {
"rebate": "6",
},
"preConditionDTO": {
"needNum": 9999,
},
"level": 4,
},
{
"discountDTO": {
"rebate": "5",
},
"preConditionDTO": {
"needNum": 99999,
},
"level": 5,
}
],
"activityScopeDTO": {
"@type": "com.jd.promo.activity.sdk.model.ActivityScopeDTO",
......@@ -519,7 +483,7 @@ def create_vc_promotion():
},
"activitySkuDTOList": [
{
"skuId": 100156428022,
"skuId": 100127486935,
"skuBindType": 1,
}
],
......@@ -598,7 +562,21 @@ def delete_vc_activity():
print(json.dumps(ans, ensure_ascii=False))
"""
获取商品的上下架状态
"""
def get_sku_state_list(wareId: int):
method_name = "jingdong.vop.goods.getSkuStateList"
token = "845ce8478b074103b9e78a769d5fa4831y2u"
app_key = "CA52430E90209F51D8F5D7B615DDE9AD"
app_secret = "c92691b2379c48de87e699c4c2f7fb32"
param = {
"skuId": wareId
}
ans = request_to_jd_vc(method_name, token, app_key, app_secret, param)
print(json.dumps(ans, ensure_ascii=False))
if __name__ == '__main__':
# create_vc_promotion()
modify_vc_stock_num(100001, 100156621732)
\ No newline at end of file
# get_sku_state_list(100127486935)
create_vc_promotion()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment