# 可以指定商品数量,不指定的话默认随机random
def DataCenterCreate(appoint_num=None):
i = 0
dataall = []
order_amount = 0
format_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
order_num = 'CS' + datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')
if appoint_num == None:
appoint_num = random.randint(2, 5)
while i < appoint_num:
code = sqlSelect('goods')
price = round(random.uniform(1, 10), 2)
print("price=====", price)
number = random.randint(1, 10)
print("number=====", number)
subtotal = round(price * number, 2)
print("subtotal=====", subtotal)
order_amount = round((order_amount + subtotal), 2)
dataall.append({"order_num": order_num, "goods_sn": code[0][0], "price": price,
"number": number, "order_amount": order_amount, "time": format_time})
i += 1
print("dataall====", dataall)
print("dataall最大值====", dataall[len(dataall) - 1]["order_amount"])
return dataall
def OrderInsert():
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", 'Connection': 'close'}
url = 'http://test/submit'
arra = []
# 传参需要的商品数量
dataset = DataCenterCreate()
for data in dataset:
arra.append({
"sku": data["goods_sn"],
"price": data["price"],
"num": data["number"]
})
data = {
"token": "BE3DBFD76E",
"orderid": dataset[0]["order_num"],
"sku": json.dumps(arra),
"name": "测试",
"email": "123456@163.com",
"remark": "",
"dep_code": "DW44556565512",
"dep_name": "",
"invoice_title": "中",
"invoice_type": "2",
"invoice_org_code": "45521454122",
"invoice_name": "测试",
"invoice_phone": "010-23524154",
"payment": 2,
"orderprice": dataset[len(dataset) - 1]["order_amount"]
}
print("data===", data)
payload = urlencode(data)
print("payload===", payload)
response = requests.post(url=url, data=payload, headers=headers)
print(response.json())
def InsertOrder(num):
i = 0
while i < num:
minn = False
while minn == False:
OrderInsert()
minn = True
i += 1
InsertOrder(1)
注意: