From 08812498da22d97bbeacfdaee542f5b07d39c439 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Mon, 5 Feb 2024 00:01:17 +0800 Subject: [PATCH] add --- cronjob/vas/vas_deal.py | 36 ++++++++++++++++++++++++++---------- lib/util.py | 9 --------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cronjob/vas/vas_deal.py b/cronjob/vas/vas_deal.py index a1002a1..f10440f 100644 --- a/cronjob/vas/vas_deal.py +++ b/cronjob/vas/vas_deal.py @@ -19,26 +19,42 @@ class S: sql = ''' select * from vas_order where ct<{} and order_status=1 and product_id='membership' '''.format(int(time.time()) - 86400 * 7) - print(sql) + logger.Info("sql: {}".format(sql)) docs = self.mysql_db_vas.query(sql) - if not docs: - return - print(type(docs), docs) - return + return docs + + # 结算一个订单 + @staticmethod + def deal_one_order(order_id): + url = "https://api.tiefen.fun/api/vas/deal_one_order" + param = { + "order_id": order_id + } + res = call_service(url, param) + return res # 获取订单 def get_coin_orders(self): - sql = ''' - select * from vas_coin_order where ct<{} and order_status=1 and product_id='membership' - '''.format(int(time.time()) - 86400 * 7) - print(sql) + sql = "select * from vas_coin_order where ct<{} and order_status=1 and product_id='membership'".format(int(time.time()) - 86400 * 7) + logger.Info("get_coin_orders sql: {}".format(sql)) docs = self.mysql_db_vas.query(sql) if not docs: return - print(type(docs), docs) return def proc(self): + logger.Info("==== start: {} ====".format(get_time_str_by_ts(int(time.time())))) + logger.Info("==== start_order: {} ====".format(get_time_str_by_ts(int(time.time())))) + orders = self.get_orders() + logger.Info("len(orders): {}".format(len(orders))) + idx = 0 + for order in orders: + idx += 1 + order_id = safe_get_str(order, "id") + res = self.deal_one_order(order_id) + logger.Info("{}/{} deal_one_order, {}, {}, {}".format(idx, len(orders), order_id, res, order)) + return + return diff --git a/lib/util.py b/lib/util.py index 458a77f..7390715 100644 --- a/lib/util.py +++ b/lib/util.py @@ -84,21 +84,12 @@ def display_time(seconds, max_unit='D', granularity=2): # 请求服务 def call_service(service_url, req_param, timeout=10, headers=None, params=None): res = requests.post(service_url, json=req_param, timeout=timeout, headers=headers, params=params) - # print(service_url, req_param) - # print(res.text) st_code = res.status_code if st_code != 200: return None r = json.loads(res.text) - ret = r.get('ret', 0) - if ret is None: - ret = r.get('errcode', None) - - if ret != 1: - return None - return r