Recursive tree wording - to pay a variety of designs - ON -celery order to pay rollback achieve

Written with recursive tree

data:

data=[
    {"cat_id":1,"name":"北京","parent_id":0},
    {"cat_id":2,"name":"上海","parent_id":0},
    {"cat_id":3,"name":"沙河","parent_id":1},
    {"cat_id":4,"name":"sb镇","parent_id":3},
    {"cat_id":5,"name":"昌平","parent_id":1},
    {"cat_id":6,"name":"青浦","parent_id":2},
]
# Demand 
'' ' 
question: 
we data is not ordered, but we want to sort and categorize the parent set in front of a subset of seniority level by level marked 

' ''

 

 The way to achieve

res=[]
def get_son(data,level=0,parent_id=0,is_clear=True):
    if is_clear:
        res.clear()
    for item in data:
        if item['parent_id']==parent_id:
            item['level']=level
            res.append(item)
            get_son(data,level=level+1,parent_id=item['cat_id'],is_clear=False)
    return res

 

Implement hierarchical classification tree

'' ' 
Problem: 

because the front end, as required by the number of cycles to show multiple levels 
for in the Data Item: 
    Print (item.name) 
    for ITEM1 in item.children 
        item1.name 
        
Archive: I want my subsets are on my list of children inside 
         
'' '
def get_tree(data):
    lists=[]
    tree={}
    for i in data:
        tree[i['cat_id']]=i
    for item in data:
        if not item['parent_id']:
            lists.append(tree[item['cat_id']])
        else:
            if "children" not in tree[item['parent_id']]:
                tree[item['parent_id']]['children']=[]
            tree[item['parent_id']]['children'].append(tree[item['cat_id']])
    return lists

analysis

 

 

 The design of a variety of payment

  Implemented, for example, or micro-channel package interface Alipay payment.

 

 

 

The method of payment interface package

class Notity(APIView):
    def post(self,request,paymethon):
        pay_file = importlib.import_module(f"app01.Pay.{paymethon}")
        pay_class = getattr(pay_file, paymethon)
        data=pay_class().notity(request.data)
        if data['status']=="success":
            models.Order.objects.filter(order_id=data['order']).updata(pay_status=1)

 

pay.Alipay.py

class Alipay():
    def pay(self):
        pass
        "order/notify/Alipay"

    def notity(self,data):
        data['shangcheng_id']
        data['sucess']
        if data['sucess']="00":
            return_data['stauts']="success"
            return_data['order_id'] = data['shangcheng_id']
            return  return_data
        else:
            pass

 

pay.Wxpay.py

import time
from app01.wx import settings
class Wxpay:
    def pay(self,order_data):
        self.order_id = order_data["order_id"]
        self.open_id = order_data['open_id']
        self.ip = order_data['ip']
        data_body = self.get_body_data()
        import requests
        url = "https://api.mch.weixin.qq.com/pay/unifiedorder"
        response = requests.post(url, data_body.encode("utf-8"), headers={'content-type': "application/xml"})
        res_dict = self.xml_to_dic(response.content)
        timeStamp = str(int(time.time()))
        paySign = self.get_pay_sign(res_dict, timeStamp)

        data_dic = {
            'timeStamp': timeStamp,
            'nonceStr': res_dict['nonce_str'],
            'package': f"prepay_id={res_dict['prepay_id']}",
            'signType': 'MD5',
            "paySign": paySign,
        }

        return data_dic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/Gaimo/p/11830626.html