entranceFeeBillList.py 20.7 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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
# -*- coding: utf-8 -*-

# @Time    : 2021/7/29 16:48
# @Author  : Ljq
# @File    : entranceFeeBillList.py
# @Software: PyCharm

"""
进门单列表接口封装
"""

import json,time,random,re
from commons.scripts import dealContentType as dct
from commons.scripts import jsonToUrlcode
from commons.api.entranceFeeBillList import jmsfToken as jT
from bs4 import BeautifulSoup
import urllib.parse

def listPage(session=None,host="",attrName="收费单号",attrValue=None,**kwargs):
    """
    进门单列表查询接口
    :param kwargs:
                rows=10
                page=1
                sort=et.created
                order=desc
                attr=number
                attrValue=11
                carTypeId=53
                categoryId=14152
                productName=1
                status=2
                tradeTypeId=70
                tareOperatorName=11
                startTime=2021-07-29 00:00:00
                endTime=2021-07-29 23:59:59
                startPayTime=2021-07-29 00:00:00
                endPayTime=2021-07-29 23:59:59
                startRefundTime=2021-07-29 00:00:00
                endRefundTime=2021-07-29 23:59:59
    """

    headers = dct.urlCode()
    url = host + "/entranceFeeBill/listPage.action"
    attr_list = {"收费单号": "number", "车号": "likePlate", "商品": "goods", "收费员": "pay", "客户姓名": "cname",
            "客户卡号": "ic", "手机号码": "phone"}
    data = {"rows": "10", "page": "1", "sort": "et.created", "order": "desc",
            "metadata[created]": {"provider": "datetimeProvider", "index": 10, "field": "created"},
            "metadata[totalPrice]": {"provider": "moneyProvider", "index": 20, "field": "totalPrice"},
            "metadata[paymentTime]": {"provider": "datetimeProvider", "index": 30, "field": "paymentTime"},
            "metadata[type]": {"provider": "entranceFeeBillTypeProvider", "index": 40, "field": "type"},
            "metadata[status]": {"provider": "entranceFeeBillStateProvider", "index": 50, "field": "status"},
            "attr": "number"}

    # 查询类型处理
    attr = attr_list[attrName]
    data["attr"] = attr
    if attrValue != None:
        data["attrValue"]=attrValue

    # 参数替换与部分参数数据格式处理
    data = dict(data, **kwargs)
    data["metadata[created]"] = json.dumps(data["metadata[created]"])
    data["metadata[totalPrice]"] = json.dumps(data["metadata[totalPrice]"])
    data["metadata[paymentTime]"] = json.dumps(data["metadata[paymentTime]"])
    data["metadata[type]"] = json.dumps(data["metadata[type]"])
    data["metadata[status]"] = json.dumps(data["metadata[status]"])

    # 请求接口
    res = session.useHeadersRequests(method="POST", url=url, data=data, headers=headers)
    return res

def get_OrderDetails(session=None,host="",orderId=None):
    """获取订单详情"""
    headers = dct.urlCode()
    url = host + f"/entranceFeeBill/pay/{orderId}.action"
    res = session.useHeadersRequests("get", url=url, headers=headers)
    return res

def get_orderUnfreeze(session=None,host="",orderId=None):
    """获取订单详情"""
    headers = dct.urlCode()
    url = host + f"/entranceFeeBill/unfreeze/{orderId}.action"
    res = session.useHeadersRequests("get", url=url, headers=headers)
    return res

def get_orderView(session=None,host="",orderId=None):
    """获取订单详情"""
    headers = dct.urlCode()
    url = host + f"/entranceFeeBill/view/{orderId}.action"
    res = session.useHeadersRequests("get", url=url, headers=headers)
    return res

def get_icCheck(session=None,host="",ic=None):
    """进门缴费单详情页面刷卡刷卡"""
    headers = dct.urlCode()
    url = host + f"/api/jmsf/ajax/icCheck?ic={ic}"
    res = session.useHeadersRequests("get", url=url,headers=headers)
    return res

def get_city(session=None,host="",name=None):
    """进门缴费单缴费金额计算"""
    headers = dct.urlCode()
    url = host + f"/api/jmsf/ajax/city/?name={name}&query={name}"
    res = session.useHeadersRequests("get", url=url,headers=headers)
    return res

def get_calculateRes(session=None,host="",autocompletecartype=None,**kwargs):
    """缴费金额获取
    :params kwargs:
                protocolId:
				pwd:
				clientRedirectTag:
				viewType:pay
				optType:${optType}
				optUrl:
				correctInfo:${correctInfo}
				weightType:${weightType}
				id:${orderId}
				goodsId:${goodsId}
				number:${number}
				modified:${__time(yyyy-MM-dd HH:mm:ss,)}
				status:${status}
				source:${source}
				updateFeeItems:
				correctDiscount:${correctDiscount}
				totalAmount:
				customerId:0
				fundAccount:
				ic:
				customerName:
				customerPhone:
				payway:刷卡
				plate:${plate}
				autocomplete-cartype:${carTypeCode}(${carTypeName})
				carTypeName:${carTypeName}
				carTypeCode:${carTypeCode}
				carTypeId:${carTypeId}
				carTypeWeight:${carTypeWeight}
				storeTareWeight:
				proveType:${proveTypeCode}
				grossWeight:${grossWeight}
				tareWeight:${tareWeight}
				weight:${grossWeight}
				goodsNum:
				itemWeight:
				productPrice:1
				unitPrice:${unitPrice}
				depName:${feeDepName}
				calcDepId:${feeDepId}
				regionName:
				regionId:0
				productName:${productName}
				productId:${productId}
				productArea:万州区
				parentId:
				levelType:
				originId:${originId}
				tradeTypeId:${tradeTypeId}
				chargeTotalAmount:
				chargeTotalAmountYuan:
				freezeMoneySymbol:
				comparisonFreezeAmount:
				created:${created}
				remark:
				goodsTagIds:${goodsTagIds}
				shareRatio:${shareRatio}
				handlingTeam:
				handlingRatio:
				handActualAmount:
				handManageAmount:
				handCollectionAmount:
				receivableAmount:
				categoryName:${productName}
				categoryId:${productId}
				driverTel:
				grossWeightDate:${grossWeightDate}
				tareWeightDate:${tareWeightDate}
				grossPathName:
				grossPathId:
				tarePathId:
				goodsRemark:
				inGreeterName:
				inGreeterId:0
				outGreeterId:
				sumPrice:${sumPrice}
				shipperName:
				shipperId:
				shipperPhone:
				feeDepName:
				calcFeeDepId:
    """
    url = host + "/calculate/index.action"
    headers = dct.urlCode()

    data = {"protocolId": "", "pwd": "", "clientRedirectTag": "", "viewType": "pay", "optType": "optType", "optUrl": "",
            "correctInfo": "correctInfo", "weightType": "weightType", "id": "orderId", "goodsId": "goodsId",
            "number": "number", "modified": "time", "status": "status", "source": "source", "updateFeeItems": "",
            "correctDiscount": "correctDiscount", "totalAmount": "", "customerId": "0", "fundAccount": "",
            "accountId":"","ic": "","customerName": "", "customerPhone": "", "payway": "刷卡", "plate": "plate",
            "autocomplete-cartype": "carTypeCode(carTypeName)", "carTypeName": "carTypeName",
            "carTypeCode": "carTypeCode", "carTypeId": "carTypeId", "carTypeWeight": "carTypeWeight",
            "storeTareWeight": "", "proveType": "proveTypeCode", "grossWeight": "grossWeight",
            "tareWeight": "tareWeight", "weight": "grossWeight", "goodsNum": "", "itemWeight": "",
            "productPrice": "1.00000", "unitPrice": "unitPrice", "depName": "feeDepName", "calcDepId": "feeDepId",
            "regionName": "", "regionId": "0", "productName": "productName", "productId": "productId",
            "productArea": "重庆,重庆市,万州区", "parentId": "", "levelType": "", "originId": "originId", "tradeTypeId": "tradeTypeId",
            "chargeTotalAmount": "", "chargeTotalAmountYuan": "", "freezeMoneySymbol": "", "comparisonFreezeAmount": "",
            "created": "created", "remark": "false", "goodsTagIds": "goodsTagIds", "shareRatio": "shareRatio",
            "handlingTeam": "", "handlingRatio": "", "handActualAmount": "", "handManageAmount": "",
            "handCollectionAmount": "", "receivableAmount": "", "categoryName": "productName",
            "categoryId": "productId", "driverTel": "", "grossWeightDate": "grossWeightDate",
            "tareWeightDate": "tareWeightDate", "grossPathName": "", "grossPathId": "", "tarePathId": "",
            "goodsRemark": "", "inGreeterName": "", "inGreeterId": "0", "outGreeterId": "", "sumPrice": "sumPrice",
            "shipperName": "", "shipperId": "", "shipperPhone": "", "feeDepName": "", "calcFeeDepId": ""}
    data["autocomplete-cartype"]=autocompletecartype
    data = dict(data,**kwargs)
    print("get_calculateRes",data)
    res = session.useHeadersRequests("post", url=url,data=data,headers=headers)
    return res

def do_doPay(session=None,host="",jmsfToken=None,autocompletecartype=None,fee_str="",**kwargs):
    """进门单缴费"""
    url = host + "/entranceTrade/doPay.action"
    headers = dct.urlCode()
    headers["jmsf_duplicate_commit_token"]=jmsfToken

    data = {"protocolId": "", "pwd": "{pwd}", "clientRedirectTag": "", "viewType": "pay", "optType": "{optType}",
            "optUrl": "", "correctInfo": "{correctInfo}", "weightType": "{weightType}", "id": "{orderId}",
            "goodsId": "{goodsId}", "number": "{number}", "modified": "{created}", "status": "{status}",
            "source": "{source}", "updateFeeItems": "", "correctDiscount": "{correctDiscount}",
            "totalAmount": "{totalMoney}", "customerId": "{customerId}", "fundAccount": "{accountId}", "ic": "{ic}",
            "customerName": "{customerName}", "customerPhone": "{mobile}", "payway": "刷卡", "plate": "{plate}",
            "autocomplete-cartype": "{carTypeCode}({carTypeName})", "carTypeName": "{carTypeName}",
            "carTypeCode": "{carTypeCode}", "carTypeId": "{carTypeId}", "carTypeWeight": "{carTypeWeight}",
            "storeTareWeight": "", "proveType": "{proveTypeCode}", "grossWeight": "{grossWeight}",
            "tareWeight": "{tareWeight}", "weight": "{newWeight}", "goodsNum": "", "itemWeight": "",
            "productPrice": "{productPrice}", "unitPrice": "{unitPrice}", "depName": "{feeDepName}",
            "calcDepId": "{feeDepId}", "dep": "{feeDepId}", "regionName": "{regionName}", "regionId": "{regionId}",
            "productName": "{productName}", "productId": "{productId}", "productArea": "{origin}", "parentId": "",
            "levelType": "", "originId": "{originId}", "tradeTypeId": "{tradeTypeId}",
            "chargeTotalAmount": "{totalMoney}", "chargeTotalAmountYuan": "{chargeTotalAmountYuan}",
            "freezeMoneySymbol": "{chargeTotalAmountYuan}", "comparisonFreezeAmount": "{chargeTotalAmountYuan}",
            "created": "{created}", "remark": "", "goodsTagIds": "", "marketFlag": "{firmCode}",
            "totalMoney": "{totalMoney}", "receivable": "{receivable}", "collectionPrice": "{discountAmount}",
            "discountAmount": "{discountAmount}", "handReceivableAmount": "{handReceivableAmount}",
            "itemReceivableAmount": "{receivable}", "correctDiscount": "{correctDiscount}",  "shareRatio": "0",
            "handlingTeam": "", "handActualAmount": "0", "handManageAmount": "0", "handCollectionAmount": "0",
            "receivableAmount": "{receivable}", "categoryName": "{productName}", "categoryId": "{productId}",
            "driverTel": "", "grossWeightDate": "{grossWeightDate}", "tareWeightDate": "{tareWeightDate}",
            "grossPathName": "", "grossPathId": "", "tarePathId": "", "goodsRemark": "", "inGreeterName": "",
            "inGreeterId": "0", "outGreeterId": "", "sumPrice": "{sumPrice}", "shipperName": "", "shipperId": "",
            "shipperPhone": "", "feeDepName": "", "calcFeeDepId": "", "feeDepId": "","accountId":""}
    data["autocomplete-cartype"] = autocompletecartype
    data = dict(data, **kwargs)

    # 当模板没有配置货物标签时,参数不能传递货物标签所以需要删除
    if kwargs["goodsTagIds"] =="":
        del kwargs["goodsTagIds"]
        del data["goodsTagIds"]

    data_uc = jsonToUrlcode.jsonToUrlcode(data_json=data)+fee_str
    print("================开始请求================")
    res = session.useHeadersRequests("post", url=url, data=data_uc, headers=headers)
    return res



def do_payOrder(session=None,host="http://test.jmsf.diligrp.com:8385",attrName="收费单号",attrValue="202108060900032",pwd="111111",
                ic=888810032426):
    a = listPage(session=session,host=host, attrName=attrName, attrValue=attrValue)
    print("listPage", a.json())
    orderId = a.json()["rows"][0]["id"]
    number = a.json()["rows"][0]["number"]
    created = a.json()["rows"][0]["created"]
    print(orderId)

    # # 订单详情获取
    resOrderDetails = get_OrderDetails(session=session,host=host, orderId=orderId)

    # 正则取值
    regionId = re.findall('<option value="(.*?)" bind-name="', resOrderDetails.text)[0]
    regionName=re.findall('" bind-name="(.*?)"  bind-index', resOrderDetails.text)[0]
    print("regionName",regionName)

    # bs取值
    orderDetailsList = BeautifulSoup(resOrderDetails.text, "html.parser").findAll("input")
    orderDetailsDict = {i.get("name"): i.get("value") for i in orderDetailsList}
    print("orderDetailsDict",orderDetailsDict)
    unitPrice = orderDetailsDict["unitPrice"]
    goodsId = orderDetailsDict["goodsId"]
    status = orderDetailsDict["status"]
    source = orderDetailsDict["source"]
    optType = orderDetailsDict["optType"]
    correctInfo = orderDetailsDict["correctInfo"]
    weightType = orderDetailsDict["weightType"]
    correctDiscount = orderDetailsDict["correctDiscount"]

    # goodsTagIds = orderDetailsDict["goodsTagIds"]
    # 货物标签特别判断
    if "goodsTagIds" in orderDetailsDict.keys():
        goodsTagIds = orderDetailsDict["goodsTagIds"]
    else:
        goodsTagIds = ""

    sumPrice = orderDetailsDict["sumPrice"]
    tradeTypeId = orderDetailsDict["tradeTypeId"]
    shareRatio = orderDetailsDict["shareRatio"]
    plate = orderDetailsDict["plate"]
    carTypeName = orderDetailsDict["carTypeName"]
    carTypeCode = orderDetailsDict["carTypeCode"]
    carTypeId = orderDetailsDict["carTypeId"]
    carTypeWeight = orderDetailsDict["carTypeWeight"]
    proveType = orderDetailsDict["proveType"]
    grossWeight = orderDetailsDict["grossWeight"]
    tareWeight = orderDetailsDict["tareWeight"]
    depName = orderDetailsDict["depName"]
    feeDepId = orderDetailsDict["calcDepId"]
    productName = orderDetailsDict["productName"]
    productId = orderDetailsDict["productId"]
    grossWeightDate = orderDetailsDict["grossWeightDate"]
    tareWeightDate = orderDetailsDict["tareWeightDate"]
    weight = orderDetailsDict["weight"]
    calcDepId = orderDetailsDict["calcDepId"]
    categoryName = orderDetailsDict["categoryName"]
    categoryId = orderDetailsDict["categoryId"]
    inGreeterName = orderDetailsDict["inGreeterName"]
    inGreeterId = orderDetailsDict["inGreeterId"]
    productArea = orderDetailsDict["productArea"]
    productPrice = orderDetailsDict["productPrice"]


    # 用户信息获取
    res = get_icCheck(session=session,host=host, ic=ic)
    print(res.text)
    customerId = res.json()["data"]["aInfo"]["customerId"]
    customerName = res.json()["data"]["aInfo"]["customerName"]
    accountId = res.json()["data"]["aInfo"]["accountId"]
    mobile = res.json()["data"]["aInfo"]["mobile"]

    # 省市区获取
    res = get_city(session=session,host=host, name="万州")
    print('res.json()["suggestions"]',res.json()["suggestions"])
    originId = res.json()["suggestions"][0]["id"]
    parentId = res.json()["suggestions"][0]["parentId"]
    productArea = res.json()["suggestions"][0]["value"]

    # # 获取缴费金额
    autocompletecartype = f"{carTypeCode}({carTypeName})"
    print(autocompletecartype)
    modified = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    print("categoryId",categoryId)

    # 获取缴费金额
    res = get_calculateRes(session=session,host=host, autocompletecartype=autocompletecartype, optType=optType, correctInfo=correctInfo,
                           weightType=weightType, id=orderId, goodsId=goodsId, number=number, modified=modified,
                           status=status,
                           source=source, correctDiscount=correctDiscount, plate=plate, carTypeName=carTypeName,
                           carTypeCode=carTypeCode,
                           carTypeId=carTypeId, carTypeWeight=carTypeWeight, proveType=proveType,
                           grossWeight=grossWeight,
                           tareWeight=tareWeight, unitPrice=unitPrice, depName=depName, productName=productName,
                           productId=productId, originId=originId, tradeTypeId=tradeTypeId, created=created,
                           goodsTagIds=goodsTagIds,
                           shareRatio=shareRatio, categoryName=categoryName, categoryId=categoryId,
                           grossWeightDate=grossWeightDate,
                           tareWeightDate=tareWeightDate, sumPrice=sumPrice, calcDepId=calcDepId, weight=weight,
                           inGreeterName=inGreeterName, inGreeterId=inGreeterId)

    # 缴费信息
    totalMoney = re.findall('name="totalMoney" value="(.*?)">', res.text)[0]
    discountAmount = re.findall('name="discountAmount" value="(.*?)">', res.text)[0]
    handReceivableAmount = re.findall('name="handReceivableAmount" value="(.*?)">', res.text)[0]
    correctDiscount = re.findall('id="correctDiscount" name="correctDiscount" value="(.*?)">', res.text)[0]
    receivable = re.findall('id="creceivableLong" name="receivable" value="(.*?)">', res.text)[0]
    collectionPrice = re.findall('name="collectionPrice" value="(.*?)"', res.text)[0]

    # 查找dl标签class为包含'ui-font-'字符的所有dl标签
    soup = BeautifulSoup(res.text, "html.parser")
    fee_str = "correctDiscount=1&billItems=&billItemsDic="
    fee_int = 0
    discount_amount = 0
    for tag in soup.findAll("div", class_="d-flex align-items-center"):
        c = tag.findAll("input")
        for i in c:
            if i.get("name") != None:
                fee_str = fee_str + "&" + i.get("name") + "=" + urllib.parse.quote(i.get("value"))
                if i.get("type") == "text":
                    fee_int = fee_int + int(float(i.get("value")))
                if "优惠" in i.get("value"):
                    discount_amount = discount_amount + int(json.loads(i.get("value"))["receivable"]) / 100

    id = orderId
    totalAmount = totalMoney
    customerPhone = mobile
    dep = feeDepId
    chargeTotalAmount = totalMoney
    chargeTotalAmountYuan = fee_int - int(discount_amount)
    freezeMoneySymbol = fee_int
    comparisonFreezeAmount = fee_int
    modified = created
    firmCode = session.userInfo["data"]["user"]["firmCode"]
    marketFlag = firmCode
    itemReceivableAmount = receivable
    receivableAmount = receivable
    tareWeightDate = tareWeightDate

    # 获取防重token
    tAmount = chargeTotalAmountYuan
    jmsfToken = jT.get_jmsfDuplicateCommitToken(session=session,host=host,cardNo=ic,fundId=accountId,amount=tAmount,
                                                customerName=customerName,entranceId=orderId)
    print("jmsfToken",jmsfToken)

    aa = do_doPay(session=session,host=host,jmsfToken=jmsfToken, autocompletecartype=autocompletecartype, fee_str=fee_str,
                  pwd=pwd, optType=optType,
                  weightType=weightType, id=id, goodsId=goodsId, number=number, created=created, status=status,
                  source=source,
                  correctDiscount=correctDiscount, totalAmount=totalAmount, customerId=customerId,
                  fundAccount=accountId,
                  accountId=accountId, ic=ic, customerName=customerName, customerPhone=customerPhone, plate=plate,
                  carTypeName=carTypeName, carTypeCode=carTypeCode, carTypeId=carTypeId, carTypeWeight=carTypeWeight,
                  proveType=proveType, grossWeight=grossWeight, tareWeight=tareWeight, weight=weight,
                  productPrice=productPrice,
                  unitPrice=unitPrice, depName=depName, calcDepId=calcDepId, dep=dep, regionName=regionName,
                  regionId=regionId,
                  productName=productName, productId=productId, productArea=productArea, originId=originId,
                  tradeTypeId=tradeTypeId, correctInfo=correctInfo, chargeTotalAmount=chargeTotalAmount,
                  freezeMoneySymbol=freezeMoneySymbol, comparisonFreezeAmount=comparisonFreezeAmount, modified=modified,
                  goodsTagIds=goodsTagIds, marketFlag=marketFlag, totalMoney=totalMoney, receivable=receivable,
                  collectionPrice=collectionPrice, discountAmount=discountAmount,
                  handReceivableAmount=handReceivableAmount,
                  itemReceivableAmount=itemReceivableAmount, receivableAmount=receivableAmount,
                  categoryName=categoryName,inGreeterName=inGreeterName,inGreeterId=inGreeterId,
                  categoryId=categoryId, grossWeightDate=grossWeightDate, tareWeightDate=tareWeightDate,
                  sumPrice=sumPrice,parentId=parentId,
                  chargeTotalAmountYuan=chargeTotalAmountYuan)

    print(aa.text)
    return aa
# do_payOrder(attrValue="202108100900016")