seed_market_golden.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """临时脚本:在本地库插入与线上一致的优惠券/充值套餐对照数据(仅用于接口对比)。"""
  2. import datetime
  3. import json
  4. import re
  5. from pathlib import Path
  6. import pymysql
  7. YML = Path(r"C:\Users\Administrator\WorkBuddy\2026-10-17-12-27-10\java-rewrite\yoshop-java\src\main\resources\application.yml")
  8. text = YML.read_text(encoding="utf-8")
  9. pwd = re.findall(r"password:\s*(.+)", text)[0].strip().strip('"').strip("'")
  10. CST = datetime.timezone(datetime.timedelta(hours=8))
  11. created = int(datetime.datetime(2026, 10, 17, 17, 8, 41, tzinfo=CST).timestamp())
  12. start_ts = int(datetime.datetime(2026, 10, 1, tzinfo=CST).timestamp())
  13. end_ts = int(datetime.datetime(2026, 10, 31, tzinfo=CST).timestamp()) + 86399
  14. conn = pymysql.connect(host="192.168.1.177", port=3306, user="root", password=pwd,
  15. database="shop", autocommit=True, charset="utf8mb4")
  16. cur = conn.cursor()
  17. cur.execute("delete from yoshop_coupon where coupon_id in (10001,10002)")
  18. cur.execute("""
  19. insert into yoshop_coupon
  20. (coupon_id,name,coupon_type,reduce_price,discount,min_price,expire_type,expire_day,
  21. start_time,end_time,apply_range,apply_range_config,total_num,receive_num,`describe`,
  22. status,sort,is_delete,store_id,create_time,update_time)
  23. values
  24. (10001,'TESTJ满减券',10,10.00,0,100.00,10,7,0,0,10,'[]',-1,0,'自动测试用',1,100,0,10001,%s,%s),
  25. (10002,'TESTJ折扣券',20,0.00,99,50.00,20,1,%s,%s,20,%s,5,0,'',1,90,0,10001,%s,%s)
  26. """, (created, created, start_ts, end_ts,
  27. json.dumps({"goodsIds": ["10004"]}, ensure_ascii=False), created, created))
  28. cur.execute("delete from yoshop_recharge_plan where plan_id=10001")
  29. cur.execute("""
  30. insert into yoshop_recharge_plan
  31. (plan_id,plan_name,money,gift_money,sort,is_delete,store_id,create_time,update_time)
  32. values (10001,'TESTJ充值套餐',100.00,10.00,100,0,10001,%s,%s)
  33. """, (created, created))
  34. print("inserted coupons + plan")
  35. cur.execute("select coupon_id,name,discount,start_time,end_time,apply_range_config from yoshop_coupon")
  36. for row in cur.fetchall():
  37. print(row)
  38. conn.close()