def get(self, app_id, platform, action): log.access_log.info("GET uri: %s, argument: (%s)" % (self.request.uri, str(self.request.arguments))) # def on_app_found(app): # self._app = app # self.find_handler(app,platform,action,self.on_find_handler) # self.find_app(app_id, on_app_found ) ip = self.get_argument("ip") if ip: query_cond = ["ip = {0}", ip] table_name = "gateways" fields = "id,url_zone,url_user,redis_server_id" sql = construct_select_sql( "select %s from %s" % (fields, table_name), query_cond) def cb(result, ex): if ex: log.app_log.error("find_app:sql:%s", sql, exc_info=ex) self.finish() else: app_info = result[0] print(app_info) self.finish("%s,%s,%s,%s;" % (app_info["id"], app_info["url_zone"], app_info["url_user"], app_info["url_user"])) self._mysql.query_hash(sql, callback=cb)
def find_handler(self, app, platform_name, action, on_find_handler): platform_id = platform_defines.name_to_id(platform_name) if platform_id: query_cond = [ "app_id = {0} and distributor_id = {1} ", int(app["id"]), platform_id ] table_name = "distribution_infos" fields = "app_id, user_id, distributor_id, dist_app_id, dist_app_key, dist_app_secret, dist_app_vendor, meta, dist_app_public_key,dist_app_private_key" sql = construct_select_sql( "select %s from %s inner join apps on %s.app_id = apps.id " % (fields, table_name, table_name), query_cond) def cb(result, ex): try: if ex: log.app_log.error("find_handler:sql:%s", sql, exc_info=ex) else: if len(result) == 1: platform_info = result[0] handlers = platform_defines.get_platform_by_id( platform_id) if handlers: if action in handlers: handler = handlers[action]( self._gateway, mysql=self._mysql, platform_info=platform_info, app=app) if not handler: raise NameError( "action %s not exists" % action) else: self.set_status(constant.HTTP_405, reason='handler not found') raise NameError( "(platform,action)(%s,%s) not exists" % (platform_name, action)) else: raise NameError( "platform_handler id %s not exists" % platform_id) else: raise NameError( "distribution_info(%s,%s) not exists" % (app["id"], platform_id)) except: self.finish() raise on_find_handler(handler) self._mysql.query_hash(sql, callback=cb) else: raise NameError("platform %s not exists" % platform_name)
def checkout_order(self, app_id, app_order, callback): query_cond = ["app_id={0} and my_order_id like {1}",app_id, "%s%%"%app_order] table_name = self.get_order_table_name() sql = construct_select_sql("select * from %s" % table_name, query_cond) def cb(result,ex): if ex: self.log_error("checkout_order error:sql(%s)", sql, exc_info=ex) else: callback(result,ex) self._mysql.query_hash(sql,callback=cb)
def is_order_exists(self, app_order_id, callback): query_cond = ["my_order_id = {0}",app_order_id] table_name = self.get_order_table_name() sql = construct_select_sql("select count(*) as order_count from %s" % table_name, query_cond) def cb(result,ex): if ex: self.log_error("is_order_exists:sql:%s", sql, exc_info=ex) else: callback(result,ex) self._mysql.count(sql,'order_count',callback=cb)
def find_by_my_order_id( self, my_order_id, callback ): query_cond = [ "my_order_id = {0}", my_order_id ] table_name = "creating_orders" fields = "ext, url" sql = construct_select_sql("select %s from %s inner join notify_urls on %s.notify_url_id = notify_urls.id " % (fields, table_name, table_name), query_cond) def on_found(result, ex): if ex: pass else: self.set(my_order_id, result[0]) callback(result[0],ex) self._mysql.query_hash( sql, callback=on_found)
def on_found(result,ex): if ex: self.log_error("save_order_extend on_found err,err = %s"%ex) else: if len(result) <= 0: self.log_error("creating_orders not find order_id = %s"%packet.szGameOrder) return; new_params.update(creating_order_id = result[0].get("id",0)); query_cond = [ "my_order_id = {0}", packet.szGameOrder] table_name = "orders" sql = construct_select_sql("select id from %s"%(table_name),query_cond); self._mysql.query_hash( sql, callback=on_found2)
def get_orders_confirmed(self,my_order_id,callback): query_cond = ["my_order_id = {0}",my_order_id] table_name = self.get_order_table_name() field = "confirmed" sql = construct_select_sql("select %s from %s"%(field,table_name),query_cond) def get_confirmed(result,ex): if ex: self.log_error("get_orders_confirmed err,sql = %s"%sql,exc_info=ex) callback(1) else: callback(result[0].get("confirmed")) self._mysql.query_hash(sql,callback=get_confirmed)
def find_app(self, app_id, on_app_found): if app_id: query_cond = ["id = {0}", app_id] table_name = "apps" fields = "id, simple_name, user_id, `key`, pay_notice_url, active, approved" sql = construct_select_sql( "select %s from %s" % (fields, table_name), query_cond) def cb(result, ex): if ex: log.app_log.error("find_app:sql:%s", sql, exc_info=ex) else: app_info = result[0] on_app_found(app_info) self._mysql.query_hash(sql, callback=cb)
def save_order_extend(self,packet,value_pairs = {}): new_params = dict( created_at = MysqlExpr("NOW()") ) new_params.update(value_pairs); def on_found2(result,ex): if ex: self.log_error("save_order_extend on_found2 err,err = %s"%ex) else: if len(result) <= 0: self.log_error("orders not find order_id = %s"%packet.szGameOrder) return; new_params.update(order_id = result[0].get("id",0)); sql = construct_insert_sql("payment_extensions",new_params); self._mysql.insert(sql,callback = None); def on_found(result,ex): if ex: self.log_error("save_order_extend on_found err,err = %s"%ex) else: if len(result) <= 0: self.log_error("creating_orders not find order_id = %s"%packet.szGameOrder) return; new_params.update(creating_order_id = result[0].get("id",0)); query_cond = [ "my_order_id = {0}", packet.szGameOrder] table_name = "orders" sql = construct_select_sql("select id from %s"%(table_name),query_cond); self._mysql.query_hash( sql, callback=on_found2) query_cond = [ "my_order_id = {0}", packet.szGameOrder] table_name = "creating_orders" sql = construct_select_sql("select id from %s"%(table_name),query_cond); self._mysql.query_hash( sql, callback=on_found)
def is_creating_order_exists(self,my_order_id,callback): query_cond = ["my_order_id = {0}",my_order_id] table_name = "creating_orders" #field = ["field"] sql = construct_select_sql("select * from %s"%(table_name),query_cond) self._mysql.query_hash(sql,callback=callback)