operationDoCorrect.py 18.5 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/8/13 14:21
# @Author  : Ljq
# @File    : operationDoCorrect.py
# @Software: PyCharm

"""

"""

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


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


def get_calculateRes(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:
    """
    url = host + "/calculate/index.action"
    headers = dct.urlCode()

    data = {"protocolId": "", "pwd": "", "clientRedirectTag": "", "viewType": "correct", "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",
            "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": ""}
    data["autocomplete-cartype"]=autocompletecartype
    data = dict(data,**kwargs)
    print("get_calculateRes",data)
    res = my.useHeadersRequests("post", url=url,data=data,headers=headers)
    return res

def do_doCorrect(host="",autocompletecartype=None,fee_str="",**kwargs):
    """进门单缴费"""
    url = host + "/entranceFeeBill/doCorrect.action"
    headers = dct.urlCode()

    # data = {"protocolId":"","pwd":"","clientRedirectTag":"","viewType":"unfreeze","optType":"0","optUrl":"","correctInfo":"1","weightType":"1","id":"3968","goodsId":"3982","number":"202108110900122","modified":"2021-08-11+17:32:50","status":"3","source":"1","updateFeeItems":"","correctDiscount":"1","totalAmount":"800","customerId":"389","fundAccount":"105847","accountId":"105847","ic":"888810032426","customerName":"长歌买家省内啊啊啊嘿","customerPhone":"18011501258","payway":"刷卡","plate":"川B00001","autocomplete-cartype":"003(板车)","carTypeName":"板车","carTypeCode":"003","carTypeId":"53","carTypeWeight":"333","storeTareWeight":"","proveType":"1621","grossWeight":"353","tareWeight":"333","weight":"20","goodsNum":"","itemWeight":"","productPrice":"1.00000","unitPrice":"100.0","depName":"水果部","dep":"58","regionId":"72","productName":"雪莲果","productId":"14158","productArea":"重庆,重庆市,万州区","originId":"500101","tradeTypeId":"71","chargeTotalAmount":"800","chargeTotalAmountYuan":"8","freezeMoneySymbol":"13","comparisonFreezeAmount":"13","created":"2021-08-11+17:32:27","remark":"备注","goodsTagIds":"1900","shareRatio":"0","handlingTeam":"","steveTeamId":"","handlingRatio":"","handActualAmount":"0","handManageAmount":"0","handCollectionAmount":"0","marketFlag":"sy","totalMoney":"800","receivable":"1300","collectionPrice":"0","discountAmount":"500","handReceivableAmount":"0","itemReceivableAmount":"1300","receivableAmount":"1300","categoryName":"水果","categoryId":"14436","driverTel":"","grossWeightDate":"2021-08-11+17:32:27","tareWeightDate":"2021-08-11+17:32:27","grossPathName":"","grossPathId":"","tarePathId":"","goodsRemark":"备注","inGreeterName":"通用测试","inGreeterId":"274","outGreeterId":"","sumPrice":"2000","shipperName":"","shipperId":"","shipperPhone":"","feeDepId":"0"}
    data = {"protocolId": "", "pwd": "", "clientRedirectTag": "", "viewType": "correct", "optType": "0", "optUrl": "",
            "correctInfo": "1", "weightType": "1", "id": "3968", "goodsId": "3982", "number": "202108110900122",
            "modified": "2021-08-11+17:32:50", "status": "2", "source": "1", "updateFeeItems": "2",
            "correctDiscount": "2", "totalAmount": "800", "customerId": "389", "fundAccount": "105847",
            "accountId": "105847", "ic": "888810032426", "customerName": "长歌买家省内啊啊啊嘿", "customerPhone": "18011501258",
            "payway": "刷卡", "plate": "川B00001", "autocomplete-cartype": "003(板车)", "carTypeName": "板车",
            "carTypeCode": "003", "carTypeId": "53", "carTypeWeight": "333", "storeTareWeight": "", "proveType": "1621",
            "grossWeight": "353", "tareWeight": "333", "weight": "20", "goodsNum": "", "itemWeight": "",
            "productPrice": "1.00000", "unitPrice": "100.0", "depName": "水果部", "dep": "58", "regionId": "72",
            "productName": "雪莲果", "productId": "14158", "productArea": "重庆,重庆市,万州区", "originId": "500101",
            "tradeTypeId": "71", "chargeTotalAmount": "800", "chargeTotalAmountYuan": "8", "freezeMoneySymbol": "13",
            "comparisonFreezeAmount": "13", "created": "2021-08-11+17:32:27", "remark": "备注", "goodsTagIds": "1900",
            "shareRatio": "0", "handlingTeam": "", "steveTeamId": "", "handlingRatio": "", "handActualAmount": "0",
            "handManageAmount": "0", "handCollectionAmount": "0", "marketFlag": "sy", "totalMoney": "800",
            "receivable": "1300", "collectionPrice": "0", "discountAmount": "500", "handReceivableAmount": "0",
            "itemReceivableAmount": "1300", "receivableAmount": "1300", "categoryName": "水果", "categoryId": "14436",
            "driverTel": "", "grossWeightDate": "2021-08-11+17:32:27", "tareWeightDate": "2021-08-11+17:32:27",
            "grossPathName": "", "grossPathId": "", "tarePathId": "", "goodsRemark": "备注", "inGreeterName": "通用测试",
            "inGreeterId": "274", "outGreeterId": "", "sumPrice": "2000", "shipperName": "", "shipperId": "",
            "shipperPhone": "", "feeDepId": "0","bskinWithGoods":"-1","outGreeterName":"","proveTypeName":"",
            "feeDepName":"","calcFeeDepId":"","backSkinTwo":"-1"}

    data["autocomplete-cartype"] = autocompletecartype
    data = dict(data, **kwargs)
    data_uc = jsonToUrlcode.jsonToUrlcode(data_json=data)+fee_str
    print("================开始请求================")
    res = my.useHeadersRequests("post", url=url, data=data_uc, headers=headers)
    return res

def do_correctOrder(host="http://test.jmsf.diligrp.com:8385",attrName="收费单号",attrValue="202108060900032",pwd="111111"):
    a = eFBL.listPage(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_orderCorrect(host=host, orderId=orderId)
    # print(resOrderDetails.text)

    # bs取值
    orderDetailsSoup = BeautifulSoup(resOrderDetails.text, "html.parser")


    # 第一种取法
    orderDetailsList = orderDetailsSoup.findAll("input")
    orderDetailsDict = {i.get("name"): i.get("value") for i in orderDetailsList}
    print("orderDetailsDict",orderDetailsDict)
    unitPrice = orderDetailsDict["unitPrice"]
    regionId=orderDetailsDict["regionId"]
    goodsId = orderDetailsDict["goodsId"]
    status = orderDetailsDict["status"]
    source = orderDetailsDict["source"]
    optType = orderDetailsDict["optType"]
    correctInfo = orderDetailsDict["correctInfo"]
    weightType = orderDetailsDict["weightType"]
    correctDiscount = "2"
    goodsTagIds = orderDetailsDict["goodsTagIds"]
    sumPrice = orderDetailsDict["sumPrice"]
    shareRatio = orderDetailsDict["shareRatio"]
    plate = orderDetailsDict["plate"]
    carTypeName = orderDetailsDict["carTypeName"]
    carTypeCode = orderDetailsDict["carTypeCode"]
    carTypeId = orderDetailsDict["carTypeId"]
    carTypeWeight = orderDetailsDict["carTypeWeight"]

    grossWeight = orderDetailsDict["grossWeight"]
    tareWeight = orderDetailsDict["tareWeight"]
    depName = orderDetailsDict["depName"]
    dep = orderDetailsDict["dep"]
    productName = orderDetailsDict["productName"]
    productId = orderDetailsDict["productId"]
    grossWeightDate = orderDetailsDict["grossWeightDate"]
    tareWeightDate = orderDetailsDict["tareWeightDate"]
    weight = orderDetailsDict["weight"]
    categoryName = orderDetailsDict["categoryName"]
    categoryId = orderDetailsDict["categoryId"]
    inGreeterName = orderDetailsDict["inGreeterName"]
    inGreeterId = orderDetailsDict["inGreeterId"]
    productArea = orderDetailsDict["productArea"]
    productPrice = orderDetailsDict["productPrice"]
    proveTypeName = orderDetailsDict["proveTypeName"]

    # 第二种取法
    selectList = orderDetailsSoup.findAll("select")
    selectDict = {i.get("name"): a.get("value") for i in selectList for a in i.findAll("option")}
    print("selectDict",selectDict)
    tradeTypeId = selectDict["tradeTypeId"]
    proveType = selectDict["proveType"]



    # 用户信息获取
    # res = eFBL.get_icCheck(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"]

    customerId = ""
    customerName = ""
    accountId = ""
    mobile = ""

    # 省市区获取
    res = eFBL.get_city(host=host, name="万州")
    print(res.text)
    originId = res.json()["suggestions"][0]["id"]

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

    # 获取缴费金额
    res = get_calculateRes(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, 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
    cNum = 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:
                if i.get("type") == "text":
                    cNum = random.randint(10,100)
                    fee_int = fee_int + int(float(i.get("value")))+cNum
                if "billItemsDic" == i.get("name"):
                    discount_amount = discount_amount + int(json.loads(i.get("value"))["receivable"]) / 100
                billItems = i.get("value")
                if "{" not in billItems and i.get("name") != "billItemCheckIds" and i.get("name")!="billItemDicCheckIds":
                    billItems = str(int(float(billItems)) + cNum)
                elif "{" in billItems and i.get("name")!="billItemsDic":
                    billItemsDict = json.loads(billItems)
                    billItemsDict["receivable"] = int(billItemsDict["receivable"]) + cNum * 100
                    billItems = json.dumps(billItemsDict,ensure_ascii=False,separators=(',', ':'))
                fee_str = fee_str + "&" + i.get("name") + "=" + urllib.parse.quote_plus(billItems)

    id = orderId
    # totalAmount = totalMoney
    totalAmount = int(fee_int)*100-int(discount_amount)*100
    # print("totalAmount",totalAmount)
    customerPhone = mobile
    # chargeTotalAmount = totalMoney
    chargeTotalAmount = totalAmount
    # receivable
    receivable = fee_int*100
    chargeTotalAmountYuan = fee_int - int(discount_amount)
    freezeMoneySymbol = fee_int
    comparisonFreezeAmount = fee_int
    modified = created
    firmCode = my.userInfo["data"]["user"]["firmCode"]
    marketFlag = firmCode
    itemReceivableAmount = receivable
    receivableAmount = receivable
    tareWeightDate = tareWeightDate

    res = do_doCorrect(host=host, 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="", 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, dep=dep,
                  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,
                  categoryId=carTypeId, grossWeightDate=grossWeightDate, tareWeightDate=tareWeightDate,
                  sumPrice=sumPrice,proveTypeName=proveTypeName,
                  chargeTotalAmountYuan=chargeTotalAmountYuan)

    print("res.text",res.text)
    print("totalAmount",totalAmount)
    return res,totalAmount

# do_correctOrder(attrValue="202108160900001")