sellingGoods.py
10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# -*- coding: utf-8 -*-
# @Time : 2021/9/10 11:06
# @Author : Ljq
# @File : sellingGoods.py
# @Software: PyCharm
"""
商品售卖
"""
import json,time,random,re
from commons.scripts import dealContentType as dct
from commons.scripts import jsonToUrlCode
from commons.scripts import replaceJsonData as rJD
import urllib.parse
from commons.MySession import sessionHg
host = "http://test.gateway.diligrp.com:8285"
def queryRegister(session=None,host=None,**kwargs):
"""
查询登记单
:param batchCode:登记单号
"""
url = host+"/hg-trading/api/registerRecord/queryRegister"
headers = {}
data = {"recordQueryDto":{"batchCode":"2109000250"}}
data = rJD.replaceJsonData(json=data,data=kwargs)
res = session.useHeadersRequests(method="post",url=url,data=json.dumps(data),headers=headers)
return res
# res = queryRegister(session=sessionHg,host=host,batchCode="2109000266")
# print(res.json())
def getBySheetNoAndBizNo(session=None,host=None,bizNo="2109000250"):
"""
查询登记单
:param batchCode:登记单号
"""
url = host+"/wms-service/api/sheet/manage/getBySheetNoAndBizNo"
headers = {}
data = {"bizNo":bizNo}
res = session.useHeadersRequests(method="get",url=url,params=data,headers=headers)
return res
# res = getBySheetNoAndBizNo(session=sessionHg,host=host,bizNo="2109000250")
# print(res.json())
def getArea(session=None,host=None,**kwargs):
"""
查询登记单
:param batchCode:登记单号
"""
url = host+"/assets-service/api/district/search"
headers = dct.jsonCode()
data = {"id":272,"marketId":15,"departmentId":177}
data = dict(data,**kwargs)
res = session.useHeadersRequests(method="post",url=url,data=json.dumps(data),headers=headers)
return res
# res = getArea(session=sessionHg,host=host,bizNo="2109000250")
# print(res.json())
def validateReduce(session=None,host=None,**kwargs):
"""
查询登记单
:param batchCode:登记单号
"""
url = host+"/wms-service/api/sheet/manage/validateReduce"
headers = dct.jsonCode()
data = {"bizNo":"2109000250","firmId":15,"kid":36,"weight":50}
data = dict(data,**kwargs)
res = session.useHeadersRequests(method="post",url=url,data=json.dumps(data),headers=headers)
return res
# res = validateReduce(session=sessionHg,host=host,bizNo="2109000250")
# print(res.json())
def listByExample(session=None,host=None,**kwargs):
"""
查询登记单
:param IsEnable:是否可用
:param MarketId:登记单号
:param BusinessType:身份类型,hg_trading_buyer,hg_trading_seller
"""
url = host+"/assets-service/api/businessChargeItem/listByExample"
headers = dct.jsonCode()
data = {"IsEnable":1,"MarketId":15,"BusinessType":"hg_trading_buyer"}
data = dict(data,**kwargs)
res = session.useHeadersRequests(method="post",url=url,data=json.dumps(data),headers=headers)
return res
# res = listByExample(session=sessionHg,host=host,bizNo="2109000250")
# print(res.json())
def queryFee(session=None,host=None,**kwargs):
"""
查询登记单
:param batchCode:登记单号
"""
url = host+"/dili-rule/api/chargeRule/queryFee"
headers = dct.jsonCode()
data = {"marketId": 15, "businessType": "hg_trading_buyer", "chargeItem": 521, "calcParams": {"amount": 150.0},
"conditionParams": {"payment": 150.0, "categoryId": 754107}}
data = dict(data,**kwargs)
res = session.useHeadersRequests(method="post",url=url,data=json.dumps(data),headers=headers)
return res
# res = queryFee(session=sessionHg,host=host)
# print(res.json())
def get_simpleInfo(session=None,host=None,ic="888800010592"):
url = host+"/account-service/api/account/simpleInfo"
headers=dct.jsonCode()
data={"cardNo":ic}
res = session.useHeadersRequests(method="GET",url=url,params=data,headers=headers)
return res
# res = get_simpleInfo(session=sessionHg,host=host,ic="888800010592")
# print(res.text)
def getCustomerInfoExpireState(session=None,host=None,customerId="141963"):
url = host+"/customer-service/api/customerMarket/getCustomerInfoExpireState"
headers=dct.jsonCode()
data={"customerId":customerId}
res = session.useHeadersRequests(method="post",url=url,params=data,headers=headers)
return res
# res = getCustomerInfoExpireState(session=sessionHg,host=host,customerId="141963")
# print(res.text)
def createAndTrade(session=None,host=None,**kwargs):
url = host+"/hg-trading/api/tradingOrder/createAndTrade"
headers=dct.jsonCode()
data = {"sellerId": 142000, "sellerName": "史东晶", "sellerAccountId": 107796, "sellerCardNo": "888800010591",
"buyerId": 141963, "buyerName": "杭果客户长歌一", "buyerAccountId": 107667, "buyerCardNo": "888800010592",
"posCode": "123", "tradePassword": "111111", "orderItemList": [
{"number": 0, "batchCode": "2109000262", "productId": 36, "productCode": "754107", "productName": "葡萄",
"categoryId": 754107, "weightType": 2, "quantity": 1, "pieceWeight": None, "grossWeight": 0,
"tareWeight": 0, "weight": 50, "price": 200, "PriceStr": "2", "amount": 10000, "amountStr": 100.0,
"originId": 500101, "originName": "万州区",
"feeItemList": [{"type": 1, "chargeItemId": 521, "chargeItemName": "买家手续费", "amount": 1122.00},
{"type": 2, "chargeItemId": 522, "chargeItemName": "卖家手续费", "amount": 610.0},
{"type": 2, "chargeItemId": 527, "chargeItemName": "卖家仓储服务费", "amount": 522.00}]}]}
data = rJD.replaceJsonData(json=data,data=kwargs)
data["orderItemList"][0]["feeItemList"]=kwargs["feeItemList"]
print("data",data)
res = session.useHeadersRequests(method="post",url=url,data=json.dumps(data),headers=headers)
return res
# res = createAndTrade(session=sessionHg,host=host)
# print(res.text)
def doCreateAndTrade(session=None,host=None,batchCode=None,weight="50",PriceStr="2",posCode="123",tradePassword="111111",
ic="888800010592"):
# 获取订单信息
resQuery = queryRegister(session=session,host=host,batchCode=batchCode)
# print(resQuery.json())
# 订单信息中提取卖家信息
sellerId = resQuery.json()["data"][0]["registerRecord"]["customerId"]
sellerName = resQuery.json()["data"][0]["registerRecord"]["customerName"]
sellerAccountId = resQuery.json()["data"][0]["registerRecord"]["accountId"]
sellerCardNo = resQuery.json()["data"][0]["registerRecord"]["cardNo"]
posCode=posCode
tradePassword=tradePassword
# 订单信息中提取商品信息
productId = resQuery.json()["data"][0]["product"]["id"]
productCode = resQuery.json()["data"][0]["product"]["categoryCode"]
productName = resQuery.json()["data"][0]["product"]["categoryName"]
categoryId = resQuery.json()["data"][0]["product"]["categoryId"]
originId = resQuery.json()["data"][0]["product"]["originId"]
originName = resQuery.json()["data"][0]["product"]["originName"]
# 获取信息
res = getBySheetNoAndBizNo(session=session,host=host,bizNo=batchCode)
# print(res.json())
# 打印客户信息
id = resQuery.json()["data"][0]["registerDetail"]["areaId"]
departmentId = session.userInfo["data"]["user"]["departmentId"]
marketId = session.userInfo["data"]["user"]["firmId"]
resArea = getArea(session=session,host=host,id=id,departmentId=departmentId,marketId=marketId)
print(resArea.json())
# 称重信息
weightType = resQuery.json()["data"][0]["registerDetail"]["weightType"]
weight=weight
PriceStr = PriceStr
price = int(float(PriceStr)*100)
amount = int(float(weight)*price)
amountStr = str(float(amount)/100)
# 判断库存
resValidate = validateReduce(session=session,host=host,bizNo=batchCode,firmId=marketId,kid=productId,weight=weight)
# print(resValidate.json())
# 费用信息获取,初始化费用信息
feeItemList=[]
# 买家身份费用获取
BusinessType = "hg_trading_buyer"
resExample = listByExample(session=session,host=host,marketId=marketId,BusinessType=BusinessType)
chargeItemList = [i["id"] for i in resExample.json()["data"]]
for item in chargeItemList:
res = queryFee(session=session,host=host,businessType=BusinessType,marketId=marketId,chargeItem=item,
amount=amount,payment=amount,categoryId=categoryId)
feeItem = {}
feeItem["type"]=1
feeItem["chargeItemId"]=item
feeItem["chargeItemName"]=[i["chargeItem"] for i in resExample.json()["data"] if i["id"] == item][0]
feeItem["amount"]=float(res.json()["data"]["totalFee"])*100
feeItemList.append(feeItem)
# 卖家费用获取
BusinessType = "hg_trading_seller"
resExample = listByExample(session=session,host=host,marketId=marketId,BusinessType=BusinessType)
chargeItemList = [i["id"] for i in resExample.json()["data"]]
for item in chargeItemList:
res = queryFee(session=session,host=host,businessType=BusinessType,marketId=marketId,chargeItem=item,
amount=amount,payment=amount,categoryId=categoryId)
feeItem = {}
feeItem["type"]=2
feeItem["chargeItemId"]=item
feeItem["chargeItemName"]=[i["chargeItem"] for i in resExample.json()["data"] if i["id"] == item][0]
feeItem["amount"]=float(res.json()["data"]["totalFee"])*100
feeItemList.append(feeItem)
print(feeItemList)
# 获取买家信息
resSimpleInfo = get_simpleInfo(session=session,host=host,ic=ic)
# print(resSimpleInfo.json())
buyerId = resSimpleInfo.json()["data"]["accountInfo"]["customerId"]
buyerName = resSimpleInfo.json()["data"]["accountInfo"]["customerName"]
buyerAccountId = resSimpleInfo.json()["data"]["accountInfo"]["accountId"]
buyerCardNo = resSimpleInfo.json()["data"]["accountInfo"]["cardNo"]
resCAT = createAndTrade(session=session,host=host,sellerId=sellerId,sellerName=sellerName,sellerAccountId=sellerAccountId,
sellerCardNo=sellerCardNo,posCode=posCode,tradePassword=tradePassword,productId=productId,
productCode=productCode,productName=productName,categoryId=categoryId,originId=originId,
originName=originName,weightType=weightType,weight=weight,PriceStr=PriceStr,price=price,
amount=amount,amountStr=amountStr,batchCode=batchCode,buyerId=buyerId,
buyerName=buyerName,buyerAccountId=buyerAccountId,buyerCardNo=buyerCardNo,feeItemList=feeItemList)
return resCAT
# res = doCreateAndTrade(session=sessionHg,host=host,batchCode="2109000289",ic="888800010592")
# print(res.text)