sellingGoods.py 10.5 KB
# -*- 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)
    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)