async def balance_add(request): if request.method == 'GET': return jinja.render("admin/balance-add.html", request,message='') if request.method == "POST": money = request.form.get("money") try: float(money) except: return jinja.render("admin/balance-add.html", request,message="输入金额错误") cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get('id') pay_orders = PayOrders() pay_orders.user_id = user_id pay_orders.product = '单号储值{0}'.format(money) pay_orders.out_trade_no =str(int(time.time()*1000))+str(user_id) pay_orders.total_fee=float(money) pay_orders.status = 0 pay_orders.notify_url=app_notify_url order_string = _alipay.api_alipay_trade_page_pay(out_trade_no=pay_orders.out_trade_no, total_amount=money, subject=pay_orders.product) pay_orders.ali_pay_str = order_string pay_orders.save() return response.redirect('https://openapi.alipay.com/gateway.do?'+order_string)
async def area_update(request,show_id=''): ''' 更新地址 :param request: :param show_id: :return: ''' if request.method == 'GET': show_id = request.args.get("show_id") areas = Areas.select().filter(Areas.parent_code == '+86').order_by(Areas.order.asc()) send = SendAddress.get(SendAddress.id == request.app.get_id_by_show_id(show_id)) return jinja.render("admin/area_update.html", request, send=send, areas=areas) if request.method == 'POST': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) data = request.form kargs = {key: value[0] for key, value in data.items()} {'sender_name': '赵六', 'sender_mobile': '1221212121', 'sender_prov': '14', 'sender_city': '杭州市', 'sender_area': '余杭区', 'sender_address': '231312312'} try: prov_code = int(kargs.pop('sender_prov')) sender_prov = Areas.get(Areas.code==prov_code).name city_code = int(kargs.pop('sender_city')) sender_city = Areas.get(Areas.code == city_code).name area_code = int(kargs.pop('sender_area')) sender_area = Areas.get(Areas.code == area_code).name except: pass kargs.update({'sender_prov':sender_prov,'sender_city':sender_city,'sender_area':sender_area}) SendAddress.update(**kargs).where(SendAddress.id == request.app.get_id_by_show_id(show_id), SendAddress.user_id == request.app.get_id_by_show_id(user.get('show_id'))).execute() return text('修改成功')
async def balance_list(request): cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN,cookie) phone = user.get('phone') user_id = user.get('id') data = Balance().filter(Balance.user_id==user_id,Balance.phone==phone) return jinja.render("admin/balance-list.html", request, data=data)
async def user_list(request): """ 用户列表 :param request: :return: """ if request.method == 'GET': user_query = Users.select().filter(Users.deleted == 0) cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) username = user.get('username') is_admin = user.get('is_admin') kargs = {} kargs['username'] = username kargs['is_admin'] = is_admin kargs['id'] = request.args.get("id", "") kargs['phone'] = request.args.get("phone", "") kargs["username"] = request.args.get("username", "") kargs["level"] = request.args.get("level", "") kargs["agent_id"] = request.args.get("agent_id", "") kargs["is_admin"] = request.args.get("is_admin", "") query = UserService().user_list(**kargs) data = get_page_data(request, query) return jinja.render("admin/user-list.html", request, kargs=kargs, data=data, user_query=user_query) elif request.method == "POST": id = request.form.get("id") Users.update({Users.deleted: 1}).where(Users.id == id).execute() return text("已删除")
async def area_add(request): ''' 添加地址 :param request: :return: ''' if request.method == 'GET': send = SendAddress.select().filter(SendAddress.deleted == 0) areas = Areas.select().filter(Areas.parent_code == '+86').order_by(Areas.order.asc()) return jinja.render("admin/area_add.html", request, areas=areas, send=send) elif request.method == "POST": cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") data = request.form if request.form.get("sender_prov", ""): data["sender_prov"] = Areas.get(Areas.code==request.form.get("sender_prov", "")).name else: data["sender_prov"] = request.form.get("sender_prov", "") if request.form.get("sender_city", ""): data["sender_city"] = Areas.get(Areas.code == request.form.get("sender_city", "")).name else: data["sender_city"] = request.form.get("sender_city", "") if request.form.get("sender_area", ""): data["sender_area"] = Areas.get(Areas.code == request.form.get("sender_area", "")).name else: data["sender_area"] = request.form.get("sender_area", "") AreaService().add_Area(data, user_id) return text("添加完成")
async def pay_report_info(request): if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") pay_report = PayOrders.select().filter(PayOrders.deleted == 0,PayOrders.user_id == user_id) kargs = {} kargs['user_id'] = request.args.get("user_id", "") kargs["out_trade_no"] = request.args.get("out_trade_no", "") # kargs["pay_trade_no"] = request.args.get("pay_trade_no","") query = PayService().query_pay_report(kargs,user_id) data = get_page_data(request, query) return jinja.render("admin/pay_report.html", request, data=data, kargs=kargs, pay_report=pay_report)
async def commission_info(request): if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) kargs = {} kargs["user_id"] = request.args.get("user_id", "") kargs["from_user_id"] = request.args.get("from_user_id", "") query = UserService().query_commission(user, **kargs) data = get_page_data(request, query) return jinja.render("admin/commission_list.html", request, data=data, kargs=kargs)
def check_agent_authorization(request): '''校验cookie''' flag = True try: cookies = request.cookies.get('agent_user', '') if not cookies: flag = False else: agent_user = get_cookies(AGENT_COOKIE_TOKEN, cookies) setattr(request.app, 'agent_user', agent_user) except: logging.error(traceback.format_exc()) flag = False return flag
async def agent_info(request): if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) kargs = {} kargs["agent_id"] = request.args.get("agent_id", "") kargs["username"] = request.args.get("username", "") kargs["user_id"] = request.args.get("user_id", "") query = UserService().query_invite(user, **kargs) data = get_page_data(request, query) return jinja.render("admin/invite_report.html", request, data=data, kargs=kargs)
def check_admin_authorization(request): '''校验cookie''' flag = True try: cookies = request.cookies.get('user', '') if not cookies: flag = False else: user = get_cookies(COOKIE_TOKEN, cookies) setattr(request.app, 'user', user) if not hasattr(request.app, 'user'): flag = False except: logging.error(traceback.format_exc()) flag = False return flag
async def agent_info(request): ''' 个人信息展示 :param request: :return: ''' if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") query = Users().select().filter(Users.deleted == 0, Users.id == user_id) code = Users().get(id=user_id) invite_url = "http://{}/change_pwd/?user_code={}".format( request.host, code.user_code) return jinja.render("admin/user_info.html", request, data=query, invite_url=invite_url)
async def commission_info(request): if request.method == 'POST': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) commission = request.form.get("commission") amount = request.form.get("amount") error = "" try: new_amount = float(amount) + float(commission) Balance().update({ "commission": 0, "amount": new_amount }).where(Balance.user_id == user.get("id", "")).execute() except Exception as e: error = str(e) if error: return json({'code': 0, 'info': '提现失败'}) else: return json({'code': 1, 'info': '提现成功'})
async def area_list(request): ''' 地址管理 :param request: :return: ''' if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") send = SendAddress.select().filter(SendAddress.user_id==user_id,SendAddress.deleted == 0) areas = Areas.select().filter(Areas.parent_code == '+86').order_by(Areas.order.asc()) kargs = {} kargs["sender_name"] = request.args.get("sender_name", "") kargs["sender_mobile"] = request.args.get("sender_mobile", "") query = AreaService().query_list(user_id,**kargs) data = get_page_data(request, query) return jinja.render("admin/area_list.html", request, kargs=kargs, data=data, areas=areas,send=send) elif request.method == "POST": id = request.form.get("id") SendAddress.update({SendAddress.deleted: 1}).where(SendAddress.id == id).execute() return text("已删除")
async def device_list(request): """ 条件查询 :param request: :return: """ if request.method == 'GET': # 产品 product = Product.select().filter(Product.deleted == 0) # 广告组 advertise_group = AdvertiseGroup.select().filter( AdvertiseGroup.deleted == 0) # 代理人 device_agent = AgentMerchant.select().filter( AgentMerchant.deleted == 0) # APPLY_ID apply_id = DeviceBatchApply.select().filter( DeviceBatchApply.deleted == 0) cookie = request.cookies.get('agent_user') print("当前代理用户返回的cookies为 %s " % cookie) agent_dict = get_cookies(AGENT_COOKIE_TOKEN, cookie) print(agent_dict) username = agent_dict.get('username') level = agent_dict.get('level') agent_id = request.app.get_id_by_show_id(agent_dict.get('show_id')) agents = AgentMerchant.select().filter(AgentMerchant.deleted == 0) kargs = {} kargs['username'] = username kargs['level'] = level kargs['agent_id'] = agent_id kargs["sn_no"] = request.args.get("sn_no", "") kargs["province"] = request.args.get("province", "") kargs["area"] = request.args.get("area", "") kargs["space_tag"] = request.args.get("space_tag", "") kargs["product_name"] = request.args.get("product_name", "") kargs["group_name"] = request.args.get("group_name", "") kargs["agent_name"] = request.args.get("agent_name", "") kargs["apply_id"] = request.args.get("apply_id", "") kargs["status"] = request.args.get("status", "") kargs["produce_version"] = request.args.get("produce_no", "") # query = DeviceService().query_list(**kargs) query = DeviceService().query_child_device(agent_id) page = get_page_data(request, query) data = {"render": page.render(), "result": []} for i in page.result: one_result = model_to_dict(i) # 代理 if i.agent_id == 0: one_result["agent_company"] = "无" else: agent = AgentMerchant.get(AgentMerchant.id == i.agent_id) one_result["agent_company"] = agent.agent_company # # 广告组 # if i.advertise_group_id == 0: # one_result["group_name"] = "无" # else: # group = AdvertiseGroup.get(AdvertiseGroup.id == i.advertise_group_id) # one_result["group_name"] = group.group_name # 分成 if i.profit_id == 0: one_result["profit_name"] = "无" else: profit = AdvertiseProfit.get(AdvertiseProfit.id == i.profit_id) one_result["profit_name"] = profit.profit_name data["result"].append(one_result) return jinja.render("agent/device-list.html", request, data=data, kargs=kargs, products=product, agents=device_agent, groups=advertise_group, apply_ids=apply_id) # 删除 elif request.method == "POST": id = request.form.get("id") Devices.update({Devices.deleted: 1}).where(Devices.id == id).execute() device = Devices.select().filter(Devices.id == id).get() agent_id = device.agent_id if agent_id != 0: id = AgentMerchant.select().filter( AgentMerchant.id == agent_id).get() AgentMerchant.update({ AgentMerchant.device_count: int(id.device_count) - 1 }).where(AgentMerchant.id == id).execute() return response.redirect('/agent_device/list')
async def order_add(request): if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") area = SendAddress.get(SendAddress.deleted == 0, SendAddress.user_id == user_id) orders = UserLogistic.select().filter( UserLogistic.deleted == 0, UserLogistic.user_id == user_id).order_by( UserLogistic.create_time.desc()) old_balance = Balance.get(Balance.user_id == user_id) if orders.count() > 0: order = orders[0] data = orders[0] else: order = None data = None if old_balance.amount < 1.8: return response.html( '<html><center><h1>余额不足,请充值 <a href="/balance/add" target="_blank">点击充值</a></h1></center></html>' ) else: if order and order.items: items = order.items.split('-') try: item = [it.split(":")[1] for it in items] except: item = [] else: item = [] return jinja.render("/admin/order-add.html", request, area=area, data=data, item=item) elif request.method == "POST": data = request.form cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") if not user.get('is_admin'): balance = Balance.get(Balance.user_id == user_id) if balance and balance.amount < 1.8: return response.html( '<html><center><h1>余额不足,请充值 <a href="/balance/add">点击充值</a></h1></center></html>' ) keys = [ 'sender_name', 'sender_mobile', 'sender_prov', 'sender_city', 'sender_address', 'recive_name', 'recive_mobile', 'recive_prov', 'recive_city', 'recive_address', 'itemName', 'number' ] for key in keys: if not request.form.get(key, '').strip(): return json({'code': 0, 'msg': '参数{0}'.format(key) + '不能为空'}) if len(request.form.get(key)) > 256: return json({ 'code': 0, 'msg': '参数{0}'.format(key) + '长度不能超过256' }) params = request.form sender.update({ "name": params.get('sender_name'), "mobile": params.get('sender_mobile'), "prov": params.get('sender_prov'), "city": params.get('sender_city'), "address": params.get('sender_address') }) recive.update({ "name": params.get('recive_name'), "mobile": params.get('recive_mobile'), "prov": params.get('recive_prov'), "city": params.get('recive_city'), "address": params.get('recive_address') }) items = [] itemNames = request.form.get('itemName') numbers = request.form.get('number') itemValues = request.form.get('itemValue') weight = request.form.get('weight') items.append({ "itemName": itemNames, "number": numbers, "itemValue": itemValues, "weight": weight }) order_id = str(int(time.time() * 1000000)) + str( random.randint(10, 1000)) data = { 'clientID': config.get('ClientID'), 'logisticProviderID': 'YTO', 'customerId': config.get('ClientID'), 'txLogisticID': order_id, 'tradeNo': '', 'orderType': 1, 'serviceType': 0, 'itemsWeight': 0.0, 'flag': 0, 'goodsValue': 0, 'special': 0, 'insuranceValue': 0.0, 'totalServiceFee': 0.0, 'codSplitFee': 0.0 } data.update({"sender": sender, "receiver": recive, 'items': items}) xml_body = dicttoxml(data, root=True, custom_root=custom_root, attr_type=False) xml_body = xml_body.decode().replace( '<?xml version="1.0" encoding="UTF-8" ?>', '') # xml_body='<RequestOrder><clientID>K11122126</clientID><logisticProviderID>YTO</logisticProviderID><customerId>K11122126</customerId><txLogisticID>K11122126abc1004</txLogisticID><tradeNo>K11122126</tradeNo><orderType>1</orderType><serviceType>0</serviceType><itemsWeight>1.2</itemsWeight><flag>0</flag><goodsValue>0</goodsValue><special>0</special><insuranceValue>0.0</insuranceValue><totalServiceFee>0.0</totalServiceFee><codSplitFee>0.0</codSplitFee><sender><name>张三</name><mobile>13550031574</mobile><prov>浙江省</prov><city>杭州市</city><address>滨江区网商路599号</address></sender><receiver><name>李四</name><mobile>13550031578</mobile><prov>四川省</prov><city>成都市</city><address>龙泉驿区西河镇</address></receiver><items><item><itemName>男式衣服</itemName><number>1</number><itemValue>25</itemValue></item></items></RequestOrder>' data_digest = signatral(xml_body, config.get('ClientSec')) # print(data_digest) # data_digest='E9yeCCnxCFLmQs8bHM+oZQ==' params = { 'clientId': config.get('ClientID'), 'data_digest': data_digest, 'logistics_interface': xml_body } # data = urllib.parse.urlencode(params) config.get('UrlOrder') + '?' + urllib.parse.urlencode(params) # print(urllib.parse.urlencode(params)) res = requests.post( config.get('UrlOrder') + '?' + urllib.parse.urlencode(params)) content = res.text res_data = xmltodict.parse(content) level = request.app.user.get('level', 0) if level == 1: level_proce = 1.8 if level == 2: level_proce = 1.5 if res_data.get('Response').get('success') in ('true', True): address = res_data['Response'].pop('distributeInfo') res_data = dict(res_data['Response'].items()) res_data.update({'distributeInfo': dict(address)}) res_data.update(data) old_shop = [ i['itemName'] + ',' + i['number'] + ',' + i['itemValue'] for i in res_data.get('items') ] shop = old_shop[0].split(",") kargs = { 'user_id': user_id, 'logisticProviderID': res_data.get('logisticProviderID', ''), 'txLogisticID': res_data.get('txLogisticID', ''), 'clientID': res_data.get('clientID', ''), 'mailNo': res_data.get('mailNo', ''), 'customerId': res_data.get('customerId', ''), 'tradeNo': res_data.get('tradeNo', ''), 'orderType': res_data.get('orderType', ''), 'serviceType': res_data.get('serviceType'), 'itemsWeight': res_data.get('itemsWeight'), 'flag': res_data.get('flag'), 'goodsValue': res_data.get('goodsValue', ''), 'special': res_data.get('special', ''), 'insuranceValue': res_data.get('insuranceValue', ''), 'totalServiceFee': res_data.get('totalServiceFee', ''), 'codSplitFee': res_data.get('codSplitFee', ''), 'sender_name': res_data.get('sender').get('name', ''), 'sender_mobile': res_data.get('sender').get('mobile', ''), 'sender_prov': res_data.get('sender').get('prov', ''), 'sender_city': res_data.get('sender').get('city', ''), 'sender_address': res_data.get('sender').get('address', ''), 'recive_name': res_data.get('receiver').get('name', ''), 'recive_mobile': res_data.get('receiver').get('mobile', ''), 'recive_prov': res_data.get('receiver').get('prov', ''), 'recive_city': res_data.get('receiver').get('city', ''), 'recive_address': res_data.get('receiver').get('address', ''), 'items': "名称:{}-数量:{}-价值:{}".format(shop[0], shop[1], shop[2]), "weight": weight, "price": level_proce } UserLogistic.create(**kargs) # 减余额 if not user.get('is_admin'): old_balance = Balance.get(Balance.user_id == user_id) Balance().update({ Balance.amount: old_balance.amount - level_proce }).where(Balance.user_id == user_id).execute() # 佣金操作 order_user = Users.get(Users.id == user_id) if order_user.agent_id != 0: once_amount = level_proce * 0.05 detail = "你邀请ID为{}的下单奖励".format(user_id) Commission().create(user_id=order_user.agent_id, from_user_id=user_id, once_amount=once_amount, detail=detail) agent_old_balance = Balance.get( Balance.user_id == order_user.agent_id) Balance().update({ Balance.commission: agent_old_balance.commission + once_amount }).where(Balance.user_id == order_user.agent_id).execute() # 存库 if request.form.get('weight', ''): paramSetWeight = { 'waybillNo': order_id, 'weight': weight, 'customerCode': config.get('ClientID'), 'clientId': config.get('WeightSec') } req = requests.get(config.get('UrlWeight'), params=paramSetWeight) w_text = req.text content = """ <html> <script> alert("下单成功"); window.location.href='http://{0}/order/add'; </script> </html> """.format(request.host) return response.html(content) else: # data = dict(res_data['Response'].items()) # return json({'code': 0, 'data': data}) content = """ <html> <script> alert("下单失败"); window.location.href='http://{0}/order/add'; </script> </html> """.format(request.host) return response.html(content)
async def excel_upload(request): if request.method == 'GET': return jinja.render("admin/excel.html", request) else: cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") img_file = request.files.get('ytofile') if img_file: file_parameters = { 'body': img_file.body, 'name': img_file.name, 'type': img_file.type, } filename = img_file.name f = open(filename, 'wb') f.write(img_file.body) f.close() # 只能读不能写 book = xlrd.open_workbook(filename) # 打开一个excel sheet = book.sheet_by_index(0) # 根据顺序获取sheet if not user.get('is_admin'): balance = Balance.get(Balance.user_id == user_id) if balance and balance.amount < 1.8 * sheet.nrows: return response.html( '<html><center><h1>余额不足,请充值 <a href="/balance/add">点击充值</a></h1></center></html>' ) fail = [] level_proce = "" area = SendAddress.get(SendAddress.user_id == user_id, SendAddress.deleted == 0) for i in range(sheet.nrows): if i == 0: continue row_values = sheet.row_values(i) if area and not row_values[0]: name = area.sender_name else: name = row_values[0] if area and not row_values[1]: mobile = area.sender_mobile else: mobile = row_values[1] if area and not row_values[2]: prov = area.sender_prov else: prov = row_values[2] if area and not row_values[3]: city = area.sender_city else: city = row_values[3] if area and not row_values[4]: address = area.sender_address else: address = row_values[4] sender = { "name": name, "mobile": mobile, "prov": prov, "city": city, "address": address } recive = { "name": row_values[5], "mobile": row_values[6], "prov": row_values[7], "city": row_values[8], "address": row_values[9] } items = [{ "itemName": row_values[10], "number": int(row_values[11]), "itemValue": row_values[12] }] weight = row_values[13] order_id = str(int(time.time() * 1000000)) + str( random.randint(10, 1000)) data = { 'clientID': config.get('ClientID'), 'logisticProviderID': 'YTO', 'customerId': config.get('ClientID'), 'txLogisticID': order_id, 'tradeNo': '', 'orderType': 1, 'serviceType': 0, 'itemsWeight': 0.0, 'flag': 0, 'goodsValue': 0, 'special': 0, 'insuranceValue': 0.0, 'totalServiceFee': 0.0, 'codSplitFee': 0.0 } data.update({ "sender": sender, "receiver": recive, 'items': items }) xml_body = dicttoxml(data, root=True, custom_root=custom_root, attr_type=False) xml_body = xml_body.decode().replace( '<?xml version="1.0" encoding="UTF-8" ?>', '') data_digest = signatral(xml_body, config.get('ClientSec')) params = { 'clientId': config.get('ClientID'), 'data_digest': data_digest, 'logistics_interface': xml_body } config.get('UrlOrder') + '?' + urllib.parse.urlencode(params) res = requests.post( config.get('UrlOrder') + '?' + urllib.parse.urlencode(params)) content = res.text res_data = xmltodict.parse(content) level = request.app.user.get('level', 0) if level == 1: level_proce = 1.8 if level == 2: level_proce = 1.5 if res_data.get('Response').get('success') in ('true', True): address = res_data['Response'].pop('distributeInfo') res_data = dict(res_data['Response'].items()) res_data.update({'distributeInfo': dict(address)}) res_data.update(data) kargs = { 'user_id': user_id, 'logisticProviderID': res_data.get('logisticProviderID', ''), 'txLogisticID': res_data.get('txLogisticID', ''), 'clientID': res_data.get('clientID', ''), 'mailNo': res_data.get('mailNo', ''), 'customerId': res_data.get('customerId', ''), 'tradeNo': res_data.get('tradeNo', ''), 'orderType': res_data.get('orderType', ''), 'serviceType': res_data.get('serviceType', ''), 'itemsWeight': res_data.get('itemsWeight', ''), 'flag': res_data.get('flag', ''), 'goodsValue': res_data.get('goodsValue', ''), 'special': res_data.get('special', ''), 'insuranceValue': res_data.get('insuranceValue', ''), 'totalServiceFee': res_data.get('totalServiceFee', ''), 'codSplitFee': res_data.get('codSplitFee', ''), 'sender_name': res_data.get('sender').get('name', ''), 'sender_mobile': str(int(res_data.get('sender').get('mobile', ''))), 'sender_prov': res_data.get('sender').get('prov', ''), 'sender_city': res_data.get('sender').get('city', ''), 'sender_address': res_data.get('sender').get('address', ''), 'recive_name': res_data.get('receiver').get('name', ''), 'recive_mobile': str(int(res_data.get('receiver').get('mobile', ''))), 'recive_prov': res_data.get('receiver').get('prov', ''), 'recive_city': res_data.get('receiver').get('city', ''), 'recive_address': res_data.get('receiver').get('address', ''), 'items': "名称:{}-数量:{}-价值:{}".format(items[0]["itemName"], items[0]["number"], items[0]["itemValue"]), "weight": weight, "price": level_proce } UserLogistic.create(**kargs) if not user.get('is_admin'): old_balance = Balance.get(Balance.user_id == user_id) Balance().update({ Balance.amount: old_balance.amount - level_proce }).where(Balance.user_id == user_id).execute() # 佣金操作 order_user = Users.get(Users.id == user_id) if order_user.agent_id != 0: once_amount = level_proce * 0.05 detail = "你邀请ID为{}的下单奖励".format(user_id) Commission().create(user_id=order_user.agent_id, from_user_id=user_id, once_amount=once_amount, detail=detail) agent_old_balance = Balance.get( Balance.user_id == order_user.agent_id) Balance().update({ Balance.commission: agent_old_balance.commission + once_amount }).where( Balance.user_id == order_user.agent_id).execute() # if request.form.get('weight', ''): # paramSetWeight = {'waybillNo': order_id, 'weight':weight, 'customerCode': config.get('ClientID'), # 'clientId': config.get('WeightSec')} # req = requests.get(config.get('UrlWeight'), params=paramSetWeight) # w_text = req.texts else: fail.append(i + 1) if fail: return text('失败行数') else: return text('全部执行成功') else: return text('没有上传文件')