seed_market_golden.py 2.0 KB

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