def get_advertiser_info(): dbg('get_advertiser_info') reply ,status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() advertiser_id = data['advertiser_id'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) advertiser = dbapi.get_advertiser(id=advertiser_id) if not advertiser: raise ApiError('ERROR_ADVERTISER_NOT_FOUND', error.ERROR_ADVERTISER_NOT_FOUND) reply['data'] = { 'id': advertiser.id, 'name': advertiser.name, 'phone': advertiser.phone, 'email': advertiser.email, 'desc': advertiser.desc, 'address': advertiser.address, 'remark': advertiser.remark } return make_response(jsonify(reply), status_code)
def machine_restart(): dbg('machine_restart') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() record_id = data['record_id'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) record = dbapi.get_record(record_id=record_id) if not record: dbg('record_id: %d' % record_id) raise ApiError('ERROR_RECORD_NOT_FOUND', error.ERROR_RECORD_NOT_FOUND) # pay = dbapi.get_pay(pay_id=record.pay_id) # imei = pay.imei # delta = record.etime - datetime.now() # value = delta.seconds # if value > 0: # succ, result = launch_relay_signal_deivce_v2(imei, value) reply['data'] = { 'id': record.id, 'stime': int(record.stime.timestamp()), 'etime': int(record.etime.timestamp()), 'now': int(time.time()) } return make_response(jsonify(reply), status_code)
def get_machine_record(): dbg('get_machine_record') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('get machine record error', error.ERROR_PARAM) record = dbapi.get_record(imei=imei, recent=1) if not record: raise ApiError('ERROR_RECORD_NOT_FOUND', error.ERROR_RECORD_NOT_FOUND) now = int(time.time()) etime = int(record.etime.timestamp()) if record.status == 1: etime = now reply['data'] = { 'id': record.id, 'stime': int(record.stime.timestamp()), 'etime': etime, 'now': now, 'user_id': record.user_id, } return make_response(jsonify(reply), status_code)
def get_wallet_products(): dbg('get_wallet_products') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('get products error', error.ERROR_PARAM) device = dbapi.get_device(imei=imei) if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) agent_id = device.owner_agent_id products = dbapi.get_product(agent_id=agent_id, cat=99) data = [] if products: for product in products: dic = { 'id': product.id, 'title': product.title, 'body': product.body, 'value': product.value, 'price': product.price, } data.append(dic) reply['data'] = data return make_response(jsonify(reply), status_code)
def get_ads(): dbg('get_ads') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) device = dbapi.get_device(imei=imei) if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) ads = dbapi.get_ad(agent_id=device.owner_agent_id, using=1) data = [] for ad in ads: info = { 'id': ad.id, 'name': ad.name, 'desc': ad.desc, 'img': url_for('static', filename=ad.img), 'url': ad.url } data.append(info) reply['data'] = data return make_response(jsonify(reply), status_code)
def get_top_wechat_agent_id(agent_id): dbg('get_top_wechat_agent_id') agent_wechat = dbapi.get_agent_wechat(agent_id=agent_id) if agent_wechat: min_agent_wechat = dbapi.get_agent_wechat( wechat_config_id=agent_wechat.wechat_config_id, min=True) return min_agent_wechat.agent_id
def get_god_info_common(agent): dbg('get_god_info_common') God = dbapi.God if 'God' in str(agent): god = agent god_id = god.id else: # 1. 先查agent_info是否存在 agent_info = dbapi.get_agent_info(agent_id=agent.id) if agent_info: return agent_info # 2. 若不存在,则查god_info while agent.hook_agent_id != 0: agent = dbapi.get_agent(id=agent.hook_agent_id) god_agent = dbapi.get_god_agent(agent_id=agent.id) god = dbapi.get_god(id=god_agent.god_id) god_id = god.id god_info = dbapi.get_god_info(god_id=god_id) if not god_info: god_info = dbapi.make_new_god_info(god_id) dbapi.db.session.commit() return god_info
def search_unknow_device(): dbg('search_unknow_device') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data.get('imei') device_id = data.get('device_id') dbg(data) except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) role_bit = int(current_user.role[5]) if role_bit != 2: raise ApiError('ERROR_AGENT_NO_PERMISSION', error.ERROR_AGENT_NO_PERMISSION) device = None dbsession = dbapi.db.session Device = dbapi.Device query = dbsession.query(Device).filter(Device.agent_id == 0) if imei: device = query.filter(Device.imei == imei).first() elif device_id: device = query.filter(Device.id == int(device_id)).first() if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) reply['data'] = {'id': device.id, 'imei': device.imei} return make_response(jsonify(reply), status_code)
def fuzzy_get_agent_name(): dbg('fuzzy_get_agent_name') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() name = data['name'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) role_bit = int(current_user.role[5]) if role_bit != 2: raise ApiError('ERROR_AGENT_NO_PERMISSION', error.ERROR_AGENT_NO_PERMISSION) dbsession = dbapi.db.session Agent = dbapi.Agent agents = dbsession.query(Agent).filter(Agent.name.like("%%%s%%" % name)).\ filter(Agent.level==4).limit(5) data = [] for agent in agents: info = {'name': agent.name, 'id': agent.id} data.append(info) reply['data'] = {'names': data} return make_response(jsonify(reply), status_code)
def get_wallet_receipt(): dbg('get_wallet_receipt') reply ,status_code = {'code': 0, 'msg': ''}, 200 try: page = int(request.args.get('page', 1)) psize = int(request.args.get('psize', 10)) except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) user_id = current_user.id count, wallet_receipts = dbapi.get_wallet_receipt(user_id=user_id, agent_id=current_user.agent_id, no_zero=1, page=page, psize=psize) data = [] if count and wallet_receipts: for wallet_receipt in wallet_receipts: info = { 'time': int(wallet_receipt.ctime.timestamp()), 'receipt': int(wallet_receipt.receipt), 'withdrawable_receipt' : int(wallet_receipt.withdrawable_receipt), 'trade_type': wallet_receipt.trade_type, 'remark': wallet_receipt.remark } data.append(info) reply['data'] = { 'count': count, 'wallet_receipts': data } return make_response(jsonify(reply), status_code)
def get_unknow_device(): dbg('get_unknow_device') reply, status_code = {'code': 0, 'msg': ''}, 200 role_bit = int(current_user.role[5]) if role_bit != 2: raise ApiError('ERROR_AGENT_NO_PERMISSION', error.ERROR_AGENT_NO_PERMISSION) page = request.args.get('page', 1, type=int) psize = request.args.get('psize', 10, type=int) data = [] dbsession = dbapi.db.session Device = dbapi.Device query = dbsession.query(Device).filter(Device.agent_id == 0) count = query.count() devices = query.slice(psize * (page - 1), psize * page).all() if count: for device in devices: info = {'id': device.id, 'imei': device.imei} data.append(info) reply['data'] = {'count': count, 'devices': data} return make_response(jsonify(reply), status_code)
def get_wechat_withdraw(): dbg('get_wechat_withdraw') reply ,status_code = {'code': 0, 'msg': ''}, 200 try: page = int(request.args.get('page', 1)) psize = int(request.args.get('psize', 10)) except: print_exception_info() raise ApiError('get_wechat_withdraw error', error.ERROR_PARAM) user_id = current_user.id count, res = dbapi.get_pay_to_user(user_id=user_id, page=page, psize=psize) data = [] if count and res: for pay_to_user in res: info = { 'time': int(pay_to_user.ctime.timestamp()), 'to_nickname': pay_to_user.to_nickname, 'fee' : pay_to_user.total_fee, 'remark': pay_to_user.remark } data.append(info) reply['data'] = { 'count': count, 'pays': data } return make_response(jsonify(reply), status_code)
def get_wallet(): dbg('get_wallet') reply ,status_code = {'code': 0, 'msg': ''}, 200 user_id = current_user.id agent_id = current_user.agent_id wallet = dbapi.get_wallet(user_id=user_id, agent_id=agent_id) wechat_user = dbapi.get_wechat_user(admin_uid=user_id) nickname = '' if not wechat_user: nickname = '未绑定微信' else: nickname = wechat_user.nickname total_fee_sum = dbapi.get_pay_to_user(user_id=user_id, total=True) wallet = dbapi.get_wallet(user_id=user_id, agent_id=agent_id) receipt_sum = dbapi.get_agent_wallet_receipt_sum(wallet.id) reply['data'] = { 'balance': int(wallet.balance), 'withdrawable_balance': int(wallet.withdrawable_balance), 'nickname': nickname, 'total_fee_sum': total_fee_sum, 'receipt_sum': receipt_sum, } return make_response(jsonify(reply), status_code)
def get_agent_sub_advertiser(): dbg('get_agent_sub_advertiser') reply ,status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() agent_id = data['agent_id'] page = request.args.get('page', 1, type=int) psize = request.args.get('psize', 10, type=int) except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) count, advertisers = dbapi.get_advertiser(hook_agent_id=agent_id, page=page, psize=psize) data = [] if count: for advertiser in advertisers: info = { 'id': advertiser.id, 'name': advertiser.name, 'phone': advertiser.phone, 'email': advertiser.email, 'desc': advertiser.desc, 'address': advertiser.address, 'remark': advertiser.remark } data.append(info) reply['data'] = { 'count': count, 'advertisers': data } return make_response(jsonify(reply), status_code)
def _get_common(self, query, **kwargs): # 筛选 query = self._model_filter(query, **kwargs) # 排序 if 'sorter' in kwargs: # 包含排序字段和排序方式 # ?sorter=-ctime,sort sorter = kwargs['sorter'] try: attrs = sorter.split(',') or [] for attr in attrs: if attr[0] == '-': query = query.order_by( getattr(self.Model, attr[1:]).desc()) else: query = query.order_by(getattr(self.Model, attr)) except: dbg(sorter) print_exception_info() # 单条数据查询 obj = self._model_one_query(query, **kwargs) if obj != 'not one query': return obj # 是否分页 return self._query_by_page_common(query, **kwargs)
def god_recycle_device(): dbg('god_recycle_device') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('update devices error', error.ERROR_PARAM) god = dbapi.get_god(openluat_user_id=current_user.id) if not god: raise ApiError('ERROR_GOD_NOT_FOUND', error.ERROR_GOD_NOT_FOUND) role_bit = int(current_user.role[5]) if role_bit not in (1, 2): raise ApiError('ERROR_AGENT_NO_PERMISSION', error.ERROR_AGENT_NO_PERMISSION) device = dbapi.get_device(imei=imei) if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) if role_bit == 1: god_agents = dbapi.get_god_agent(god_id=god.id) g = (god_agent.agent_id for god_agent in god_agents) if device.agent_id not in g: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) update = {} update['agent_id'] = 0 update['address_id'] = 0 update['salesman_agent_id'] = 0 update['l4'] = 1 update['l3'] = 0 update['l2'] = 0 update['l1'] = 0 device = dbapi.update_device(device, **update) # device_distribution dbapi.delete_device_distribution_total(imei) # device_distribution_salesman dbapi.delete_device_distribution_salesman(imei) # device_product dbapi.delete_device_product(device.id) # pay dbapi.delete_pays_and_records(imei) try: db.session.commit() except: db.session.rollback() raise return make_response(jsonify(reply), status_code)
def check_joinup_available(agent_id): dbg('check_joinup_available') info = {'wechat': 0, 'ali': 0} db = dbapi.db Pay = dbapi.Pay Device = dbapi.Device DeviceDistribution = dbapi.DeviceDistribution order = db.session.query(Pay).join(Device, Pay.imei==Device.imei).\ join(DeviceDistribution, Device.id==DeviceDistribution.device_id).\ filter(DeviceDistribution.to_agent==agent_id).\ filter(Pay.status==1).filter(Pay.deleted!=1).first() if not order: # 没有订单,可以随便对接 info['wechat'] = 1 info['ali'] = 1 else: # 有订单,则微信不可对接,如果微信已对接,则支付宝可以对接 agent_wechat = dbapi.get_agent_wechat(agent_id=agent_id) if not agent_wechat: agent_wechat = dbapi.make_new_agent_wechat(agent_id) dbapi.db.session.commit() if agent_wechat.wechat_config_id != 1 or agent_id == 1: info['ali'] = 1 return info
def get_agent_info(): dbg('get_agent_info') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() agent_id = data['agent_id'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) agent = dbapi.get_agent(id=agent_id) if not agent: raise ApiError('ERROR_AGENT_NOT_FOUND', error.ERROR_AGENT_NOT_FOUND) reply['data'] = { 'id': agent.id, 'salesman': agent.salesman, 'level': agent.level, 'slevel': agent.slevel, 'name': agent.name, 'phone': agent.phone, 'email': agent.email, 'desc': agent.desc, 'address': agent.address, 'remark': agent.remark, 'expandable': agent.expandable, 'withdrawable': agent.withdrawable } return make_response(jsonify(reply), status_code)
def wechat_qrcode_update(pay, product, trade_no, user_id, imei=''): params = { 'product_id': str(product.id), 'body': product.title, 'out_trade_no': trade_no, 'total_fee': product.price, 'spbill_create_ip': current_app.config['SELF_IP'], 'notify_url': current_app.config['NOTIFY_URL'], 'trade_type': 'NATIVE', 'agent_id': product.agent_id } err, payRequest = wechatpay.get_native_pay_request(**params) dbg((err, payRequest)) if not err: prepay_id = payRequest["prepay_id"] qrcode = payRequest['code_url'] pay = dbapi.update_pay(pay, prepay_id=prepay_id, qrcode=qrcode) try: db.session.commit() except: db.session.rollback() raise return pay else: return pay
def update_agent(): dbg('update_agent') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() agent_id = data['agent_id'] update = data['update'] keys = ('name', 'desc', 'address', 'remark', 'expandable', 'withdrawable') for k in update: assert (k in keys) except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) agent = dbapi.get_agent(id=agent_id) if not agent: raise ApiError('ERROR_AGENT_NOT_FOUND', error.ERROR_AGENT_NOT_FOUND) cur_agent_id = current_user.agent_id print(agent_id, cur_agent_id, agent.hook_agent_id) if cur_agent_id not in (agent_id, agent.hook_agent_id): raise ApiError('ERROR_AGENT_NO_PERMISSION', error.ERROR_AGENT_NO_PERMISSION) agent = dbapi.update_agent(agent, **update) db.session.commit() return make_response(jsonify(reply), status_code)
def get_auth_access_token(app_id, auth_code, key_path): dbg('get_auth_access_token') url = 'https://openapi.alipay.com/gateway.do' data = { 'app_id': app_id, 'method': 'alipay.system.oauth.token', 'charset': 'utf-8', 'sign_type': 'RSA2', 'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'version': '1.0', 'grant_type': 'authorization_code', 'code': auth_code } _tmp = "&".join(['%s=%s' % (k, data[k]) for k in sorted(data)]) dbg(key_path) try: sign = gen_sign256(key_path, _tmp) except: sign = tool.gen_sign(key_path, _tmp) data['sign'] = sign r = requests.get(url, params=data) if r.status_code == 200: result = json.loads(r.text) if "error_response" not in result: return True, result else: return False, result else: return False, r.text
def get_sub_agent(): dbg('get_sub_agent') reply, status_code = {'code': 0, 'msg': ''}, 200 page = request.args.get('page', 1, type=int) psize = request.args.get('psize', 10, type=int) agent_id = current_user.agent_id count, agents = dbapi.get_agent(hook_agent_id=agent_id, salesman=0, page=page, psize=psize) data = [] if count: for agent in agents: info = { 'id': agent.id, 'name': agent.name, 'level': agent.level, 'phone': agent.phone, 'address': agent.address, 'expandable': agent.expandable, 'withdrawable': agent.withdrawable, 'remark': agent.remark } data.append(info) reply['data'] = {'count': count, 'agents': data} return make_response(jsonify(reply), status_code)
def get_products(): dbg('get_products') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('get products error', error.ERROR_PARAM) device = dbapi.get_device(imei=imei) if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) device_products = dbapi.get_device_product(device_id=device.id) data = [] if device_products: for device_product in device_products: product = dbapi.get_product(product_id=device_product.product_id) if not product: continue dic = { 'id': product.id, 'title': product.title, 'body': product.body, 'value': product.value, 'price': product.price, 'unit': device.product_unit, 'number': str(Fraction(product.value, device.product_unit_pluse)), } data.append(dic) reply['data'] = data return make_response(jsonify(reply), status_code)
def get_agent_setting(): dbg('get_agent_setting') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() target_agent_id = data['target_agent_id'] except: print_exception_info() raise ApiError('update agent setting error', error.ERROR_PARAM) agent_id = current_user.agent_id target_agent = dbapi.get_agent(id=target_agent_id) if not target_agent: raise ApiError('ERROR_AGENT_NOT_FOUND', error.ERROR_AGENT_NOT_FOUND) agent_setting = dbapi.get_agent_setting(agent_id=target_agent_id) reply['data'] = { 'min_withdraw': agent_setting.min_withdraw, 'withdraw_fee': agent_setting.withdraw_fee, 'wallet_pay_enable': agent_setting.wallet_pay_enable, 'trans_url': agent_setting.trans_url } return make_response(jsonify(reply), status_code)
def get_pay(): dbg('get_pay') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() pay_id = data['pay_id'] except: print_exception_info() raise ApiError('get pay error', error.ERROR_PARAM) pay = dbapi.get_pay(pay_id=pay_id) if not pay: raise ApiError('get pay error', error.ERROR_PAY_NOT_FOUND) data = { 'trade_no': pay.trade_no, 'title': pay.title, 'body': pay.body, 'total_fee': pay.total_fee, 'time': int(pay.utime.timestamp()), 'status': pay.status } reply['data'] = data return make_response(jsonify(reply), status_code)
def get_cur_agent(): dbg('get_cur_agent') reply, status_code = {'code': 0, 'msg': ''}, 200 agent_id = current_user.agent_id agent = dbapi.get_agent(id=agent_id) if not agent: raise ApiError('get_cur_agent error', error.ERROR_AGENT_NOT_FOUND) joinup = check_joinup_available(agent_id) reply['data'] = { 'id': agent.id, 'salesman': agent.salesman, 'level': agent.level, 'slevel': agent.slevel, 'expandable': agent.expandable, 'name': agent.name, 'phone': agent.phone, 'email': agent.email, 'desc': agent.desc, 'address': agent.address, 'remark': agent.remark, 'joinup': joinup } return make_response(jsonify(reply), status_code)
def get_nopay_count(): dbg('get_nopay_count') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) device = dbapi.get_device(imei=imei) if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) if not device.nopay: raise ApiError('ERROR_DEVICE_NOT_SUP_NOPAY', error.ERROR_DEVICE_NOT_SUP_NOPAY) user_id = g.oauth_user.user_id user_start_counter = dbapi.get_user_start_counter(user_id=user_id, imei=imei) if not user_start_counter: user_start_counter = dbapi.make_new_user_start_counter(user_id, imei) db.session.commit() user_start_counters = dbapi.get_user_start_counter( user_id=user_id, address_id=device.address_id) count = 0 for user_start_counter in user_start_counters: count += user_start_counter.count reply['data'] = {'count': count, 'nopay': device.nopay} return make_response(jsonify(reply), status_code)
def get_jsapi_pay_request(**kwargs): err, unifiedorder = get_unifiedorder(**kwargs) if err is not None: return (err, None) try: assert("result_code" in unifiedorder) assert(unifiedorder["result_code"] == "SUCCESS") assert("prepay_id" in unifiedorder) assert(len(unifiedorder["prepay_id"]) > 0) except: dbg("[api.get_pay_request] unifiedorder error.\n\t%s" % str(unifiedorder)) return (unifiedorder, None) payRequest = { "appId" : unifiedorder["appid"], "timeStamp": str(int(time.time())), "nonceStr" : nonce_str_gen(), "package" : "prepay_id=%s" %(unifiedorder["prepay_id"]), "signType" : "MD5" } wechat_config = dbapi.get_wechat_config(agent_id=kwargs['agent_id']) key = wechat_config.mchkey sign_str = params_sign(payRequest, key) payRequest['paySign'] = sign_str return (None, payRequest)
def get_wallet_balance(): dbg('get_wallet_balance') reply, status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() imei = data['imei'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) device = dbapi.get_device(imei=imei) if not device: raise ApiError('ERROR_DEVICE_NOT_FOUND', error.ERROR_DEVICE_NOT_FOUND) user_id = g.oauth_user.user_id wallet = dbapi.get_wallet(role=0, user_id=user_id, agent_id=device.owner_agent_id) agent_setting = dbapi.get_agent_setting(agent_id=device.agent_id) wallet_pay_enable = 1 if agent_setting and agent_setting.wallet_pay_enable == 0: wallet_pay_enable = 0 reply['data'] = { 'balance': wallet.balance, 'wallet_pay_enable': wallet_pay_enable } return make_response(jsonify(reply), status_code)
def add_advertiser(): dbg('add_advertiser') reply ,status_code = {'code': 0, 'msg': ''}, 200 try: data = request.get_json() name = data['name'] email = data['email'] phone = data['phone'] address = data['address'] desc = data['desc'] remark = data['remark'] except: print_exception_info() raise ApiError('ERROR_PARAM', error.ERROR_PARAM) target_advertiser = dbapi.get_advertiser(phone=phone) if target_advertiser: raise ApiError('ERROR_PHONE_EXISTS', error.ERROR_PHONE_EXISTS) agent = dbapi.get_agent(phone=phone) if agent: raise ApiError('ERROR_PHONE_EXISTS', error.ERROR_PHONE_EXISTS) openluat_user = dbapi.get_openluat_user(phone=phone) if not openluat_user: openluat_user = dbapi.make_new_openluat_user(name, email, phone) db.session.commit() agent_id = current_user.agent_id hook_agent_id = agent_id new_agent = dbapi.make_new_advertiser(openluat_user.id, hook_agent_id, name, phone, email, desc, address, remark) db.session.commit() return make_response(jsonify(reply), status_code)