def card_info_all(): try: limit = request.args.get('limit') page = request.args.get('page') field = request.args.get('field') value = request.args.get('value') if field == "card_cus": account_id = SqlData.search_user_field_name('id', value) sql = "WHERE user_id=" + str(account_id) elif field: sql = "WHERE " + field + " LIKE '%" + value + "%'" else: # 如果没有搜索条件,则分页查询MYSQL,加快速度 start_index = (int(page) - 1) * int(limit) sql = 'limit ' + str(start_index) + ", " + limit + ';' results = dict() results['code'] = RET.OK results['msg'] = MSG.OK info_list = SqlData.search_card_info_admin(sql) if not info_list: results['code'] = RET.OK results['msg'] = MSG.NODATA return jsonify(results) results['data'] = info_list results['count'] = SqlData.search_table_count('card_info') return jsonify(results) except Exception as e: logging.error(str(e)) return jsonify({'code': RET.SERVERERROR, 'msg': MSG.SERVERERROR})
def update_trans_balance(): card_info = SqlData.search_card_info_admin("WHERE status='T'") for i in card_info: card_id = i.get('card_id') card_number = i.get('card_no').strip() n = 0 res = {} while n <= 5: res = svb.card_detail(card_id) if res: break else: n += 1 continue if res: available_balance = res.get('data').get('available_balance') SqlData.update_card_balance(int(available_balance / 100), card_id) authorizations = res.get('data').get('authorizations') for c in authorizations: acquirer_ica = c.get('acquirer_ica') approval_code = c.get('approval_code') billing_amount = float(c.get('billing_amount') / 100) billing_currency = c.get('billing_currency') issuer_response = c.get('issuer_response') mcc = c.get('mcc') mcc_description = c.get('mcc_description') merchant_amount = float(c.get('merchant_amount') / 100) merchant_currency = c.get('merchant_currency') merchant_id = c.get('merchant_id') merchant_name = c.get('merchant_name') transaction_date_time = c.get('transaction_date_time') transaction_type = c.get('transaction_type') vcn_response = c.get('vcn_response') if 'Decline' in issuer_response or 'Decline' in vcn_response: status = 'F' else: status = 'T' SqlData.insert_card_trans( card_number, acquirer_ica, approval_code, billing_amount, billing_currency, issuer_response, mcc, mcc_description, merchant_amount, merchant_currency, merchant_id, merchant_name, transaction_date_time, transaction_type, vcn_response, card_id, status) clearings = res.get('data').get('clearings') for n in clearings: acquirer_ica = n.get('acquirer_ica') approval_code = n.get('approval_code') authorization_date = n.get('authorization_date') billing_amount = float(n.get('billing_amount') / 100) billing_currency = n.get('billing_currency') clearing_type = n.get('clearing_type') exchange_rate = n.get('exchange_rate') mcc = n.get('mcc') mcc_description = n.get('mcc_description') merchant_amount = float(n.get('merchant_amount') / 100) merchant_currency = n.get('merchant_currency') merchant_id = n.get('merchant_id') merchant_name = n.get('merchant_name') settlement_date = n.get('settlement_date') SqlData.insert_card_trans_settle( card_number, acquirer_ica, approval_code, authorization_date, billing_amount, billing_currency, clearing_type, exchange_rate, mcc, mcc_description, merchant_amount, merchant_currency, merchant_id, merchant_name, settlement_date, card_id) else: logging.error('定时查询卡交易失败,card_id: ' + str(card_id)) t = xianzai_time() SqlData.update_admin_field('up_remain_time', t)