BOM:R2 物料清单与淘宝 / 立创比价(表格 + 抓价脚本与数据)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
这个提交包含在:
zhou yang
2026-10-04 19:24:42 +08:00
共同撰写人 Claude Opus 5.5
父节点 bfe094a5d7
当前提交 22a255acd7
共修改 19 个文件,包含 39549 行新增和 0 行删除
+39
查看文件
@@ -0,0 +1,39 @@
import json, re, math, collections
exec(open('build.py', encoding='utf-8').read().split('# ---------- Excel ----------')[0])
# 店铺覆盖度:一家店能供的料越多越优先(省运费)
cover = collections.Counter()
REL = {}
for r in L:
sid = r['sid'] or ''
if not sid.startswith('C'): continue
items = [i for i in TB.get(sid, {}).get('items', []) if i['price']]
rel = [i for i in items if relevant(sid, r, i)]
for i in rel:
i['p'] = float(i['price']); i['s'] = sales_n(i['sales'])
REL[sid] = (r, rel)
for s in {i['shop'] for i in rel}:
cover[s] += 1
def cat2(r):
m = r['mid'] or ''
if re.match(r'0402WGF|RHC|FRC|HoGT|NCP18|CL\d|GRM|0402CG|T491|470uF|6.3TPV', m): return 'passive'
return 'other'
plan = []
for sid, (r, rel) in REL.items():
lp = lcsc_price(sid, r['total'])[0]
cands = []
for i in rel:
bad = cat2(r) == 'other' and lp and i['p'] < 0.3 * lp and lp > 1.0
score = 3 * math.log1p(cover[i['shop']]) + math.log1p(i['s']) - (4 if i.get('series') else 0) - (8 if bad else 0) - (3 if i['s'] == 0 else 0)
cands.append((score, i))
cands.sort(key=lambda x: -x[0])
plan.append({'sid': sid, 'mid': r['mid'], 'desc': r['desc'], 'need': r['total'], 'lcsc': lp,
'cands': [dict(id=i['id'], tmall=i['tmall'], shop=i['shop'], p=i['p'], sales=i['sales'], title=i['title'], score=round(s, 2)) for s, i in cands[:3]]})
json.dump(plan, open('cost_plan.json', 'w', encoding='utf-8'), ensure_ascii=False, indent=1)
shops = collections.Counter(p['cands'][0]['shop'] for p in plan if p['cands'])
print(len(plan), 'shops', len(shops)); print(shops.most_common(15))
for p in plan:
c = p['cands'][0] if p['cands'] else None
print(p['mid'][:22].ljust(22), p['need'], p['lcsc'], '|', c and (c['p'], c['shop'][:10], c['title'][:40]))