def bankcard_approve(rst_id, bankcard_id): args = _get_bankcard_args() args.update({ 'id': bankcard_id, "status": RstBankCard.STATUS_VALID, "rst_id": rst_id }) rst_admin = get_rst_admin(rst_id) current_zeus_bankcard = None mobile = None if rst_admin: current_zeus_bankcard = \ user_base.get_bankcard(rst_admin.get('user_id')) mobile = rst_admin.get("mobile") try: if rst_admin: _unbind_admin_mobile(rst_admin.get('user_id')) _unbind_admin_bankcard(rst_admin.get('user_id')) bankcard_base.super_user_bind(username=args['username'], mobile=args['mobile'], restaurant_id=rst_id, bank_id=args['bank_id'], card_id=args['card_id'], cardholder_name=args['cardholder_name'], process_user_id=current_user.id) _current_to_history(rst_id) bankcard_base.update_bankcard(**args) bankcard_base.add_bankcard_processing_record( rst_id=rst_id, bankcard_id=bankcard_id, process_user_id=current_user.id, messages=u'审核通过该银行卡信息', status_to=RstBankCard.STATUS_VALID, ) rst = rst_base.get(rst_id) bank = bankcard_base.get_bank(int(args['bank_id'])) async .send_task(send_bankcard_approve_sms, phone=args['mobile'], params={ "restaurant_name": rst.get('name'), "card_holder": args["cardholder_name"], "bank": bank.bank_name, "card_tail_number": args["card_id"][-4:] }) except thirdparty_svc.eus.EUSUserException as e: # rollback bankcard and mobile if mobile and rst_admin.get("is_mobile_valid") == 1: user_base.bind_mobile(rst_admin.get("user_id"), mobile) if current_zeus_bankcard: user_base.bankcard_bind( user_id=current_zeus_bankcard.user_id, cardholder_name=current_zeus_bankcard.cardholder_name, bank_id=current_zeus_bankcard.bank_id, card_id=current_zeus_bankcard.card_id) raise_user_exc(BANKCARD_APPROVE_ERR, error_msg=e.message)
def get(restaurant_id): certification='' try: certification = cert_base.get(int(restaurant_id)) except BaseException as e: raise_user_exc(CERT_NOT_EXISTS_ERR, restaurant_id=restaurant_id) return {'certification': certification}
def get(restaurant_id): certification = "" try: certification = cert_base.get(int(restaurant_id)) except BaseException as e: raise_user_exc(CERT_NOT_EXISTS_ERR, restaurant_id=restaurant_id) return {"certification": certification}
def voice_call_handler(call_id): """ handle only one call each time. """ STATUS_PROCESSING = thirdparty_svc.eos.ORDER_STATUS.STATUS_PROCESSING voice_call = VoiceCall.get(call_id) if not voice_call: raise_user_exc(VOICE_CALL_NOT_FOUND, call_id=call_id) voice_orders = VoiceOrder.get_by_call_id(voice_call.id) # recheck with thrift_client('eos') as eos_client: order_ids = [order.order_id for order in voice_orders] t_orders = eos_client.mget(order_ids) t_orders = filter( lambda _o: _o.status_code == STATUS_PROCESSING, t_orders) t_order_ids = [order.id for order in t_orders] voice_orders = [v_order for v_order in voice_orders if v_order.order_id in t_order_ids] if not voice_orders: return call_params = _generate_call_params(voice_call, voice_orders) call_status = _send_call(call_params) voice_call.call_status = call_status
def voice_call_handler(call_id): """ handle only one call each time. """ STATUS_PROCESSING = thirdparty_svc.eos.ORDER_STATUS.STATUS_PROCESSING voice_call = VoiceCall.get(call_id) if not voice_call: raise_user_exc(VOICE_CALL_NOT_FOUND, call_id=call_id) voice_orders = VoiceOrder.get_by_call_id(voice_call.id) # recheck with thrift_client('eos') as eos_client: order_ids = [order.order_id for order in voice_orders] t_orders = eos_client.mget(order_ids) t_orders = filter(lambda _o: _o.status_code == STATUS_PROCESSING, t_orders) t_order_ids = [order.id for order in t_orders] voice_orders = [ v_order for v_order in voice_orders if v_order.order_id in t_order_ids ] if not voice_orders: return call_params = _generate_call_params(voice_call, voice_orders) call_status = _send_call(call_params) voice_call.call_status = call_status
def _check_region_json(area): if area is not None: try: geojson.loads(json.dumps(area)) except ValueError: raise_user_exc(REGION_INVALID) return True
def get_pay_records(rst_id, activity_id=None, activity_category_id=None, offset=None, limit=None): records_paging = query_paylog_by_rst(rst_id, activity_id, activity_category_id, offset, limit) total_num = count_paylog_by_rst(rst_id, activity_id, activity_category_id) record_process_ids = [r[9] for r in records_paging if r[9]] record_process_logs = query_process_records_by_ids(record_process_ids) process_log_map = {r.id: r for r in record_process_logs} records = [] for record in records_paging: new_record = { 'record_id': record[0], 'first_date': record[4], 'last_date': record[5], 'quantity': to_int(record[6]), 'audit_time': record[8], 'total_subsidy': to_float(record[7]), 'activity_id': record[1], 'activity_category_id': record[2], } process_log = process_log_map.get(record[9], None) new_record['card_id'] = process_log.card_id \ if process_log else None new_record['cardholder_name'] = process_log.cardholder_name \ if process_log else None if process_log: new_record['status'] = process_log.status elif record[3] == ActivityStats.STATUS_PAY_RECORD_GENERATED: new_record['status'] = 1 else: raise_user_exc(ACTIVITY_PAYMENT_PROC_ILL_ERR) if new_record['status'] == SubsidyProcessRecord.STATUS_SUBMITTED: new_record['submit_time'] = process_log.processed_at elif new_record['status'] in [3, 4]: new_record['success_time'] = process_log.processed_at records.append(new_record) for record in records: # set activity name try: record['activity_name'] = act_base.get_name( record['activity_id'], record['activity_category_id']) except: # Fix history problem record['activity_name'] = '' record_results = set_null(records, ['card_id', 'cardholder_name', 'audit_time', 'submit_time', 'success_time']) return record_results, total_num
def bankcard_approve(rst_id, bankcard_id): args = _get_bankcard_args() args.update({'id': bankcard_id, "status": RstBankCard.STATUS_VALID, "rst_id": rst_id}) rst_admin = get_rst_admin(rst_id) current_zeus_bankcard = None mobile = None if rst_admin: current_zeus_bankcard = \ user_base.get_bankcard(rst_admin.get('user_id')) mobile = rst_admin.get("mobile") try: if rst_admin: _unbind_admin_mobile(rst_admin.get('user_id')) _unbind_admin_bankcard(rst_admin.get('user_id')) bankcard_base.super_user_bind( username=args['username'], mobile=args['mobile'], restaurant_id=rst_id, bank_id=args['bank_id'], card_id=args['card_id'], cardholder_name=args['cardholder_name'], process_user_id=current_user.id) _current_to_history(rst_id) bankcard_base.update_bankcard(**args) bankcard_base.add_bankcard_processing_record( rst_id=rst_id, bankcard_id=bankcard_id, process_user_id=current_user.id, messages=u'审核通过该银行卡信息', status_to=RstBankCard.STATUS_VALID, ) rst = rst_base.get(rst_id) bank = bankcard_base.get_bank(int(args['bank_id'])) async.send_task(send_bankcard_approve_sms, phone=args['mobile'], params={"restaurant_name": rst.get('name'), "card_holder": args["cardholder_name"], "bank": bank.bank_name, "card_tail_number": args["card_id"][-4:]}) except thirdparty_svc.eus.EUSUserException as e: # rollback bankcard and mobile if mobile and rst_admin.get("is_mobile_valid") == 1: user_base.bind_mobile(rst_admin.get("user_id"), mobile) if current_zeus_bankcard: user_base.bankcard_bind(user_id=current_zeus_bankcard.user_id, cardholder_name=current_zeus_bankcard.cardholder_name, bank_id=current_zeus_bankcard.bank_id, card_id=current_zeus_bankcard.card_id) raise_user_exc(BANKCARD_APPROVE_ERR, error_msg=e.message)
def get_event(event_id, with_records=True, with_name=True): event = inner.get_event(event_id) if not event: raise_user_exc(CS_EVENT_NOT_EXIST, event_id=event_id) event = event.to_dict() if with_records: records = get_records(event['id'], with_name=with_name) event['records'] = records return event
def update_event(event_id, compensation=None, user_id=None, content=None): event = inner.get_event(event_id) if not event: raise_user_exc(CS_EVENT_NOT_EXIST, event_id=event_id) if compensation is not None: event.update(compensation=compensation) if user_id and content: inner.add_record(event_id, user_id, content, event.status) return True
def set_valid(cls): """ 设置banner是否有效 """ args_spec = { 'id': Arg(int), 'is_valid': Arg(int), } args = args_parser.parse(args_spec) if not len(args.values()) == 2 or args.get('is_valid') is None: # TODO raise incorrect args exception raise_user_exc(BANNER_ARGS_ERR) cls.update(args) return ''
def update(cert): with thrift_client('ers') as ers: db_cert = ers.get_restaurant_certification(cert.restaurant_id) if not db_cert: raise_user_exc(CERT_UPDATE_ERR, restaurant_id=cert.restaurant_id) with thrift_client('ers') as ers: ers.update_restaurant_certification(cert) record_process_base.add(cert.restaurant_id, cert.type, cert.status, STATUS_PENDING, comment='修改认证信息') return ''
def processing(): args = args_parser.parse_all() status_to = int(args.get("status")) comment = args.get("comment", "") restaurant_id = int(args.get("restaurant_id")) cert = cert_base.get(restaurant_id) if status_to != CERTIFICATION_CONST.STATUS_PASSED and status_to != CERTIFICATION_CONST.STATUS_FAILED: raise_user_exc(CERT_PROC_ILL_ERR) if cert.status != CERTIFICATION_CONST.STATUS_PENDING: raise_user_exc(CERT_NOT_PENDING_ERR) cert_base.process_certification(restaurant_id, status_to) record_base.add(restaurant_id, cert.type, cert.status, status_to, comment) return ""
def update(cert): with thrift_client('ers') as ers: db_cert = ers.get_restaurant_certification(cert.restaurant_id) if not db_cert: raise_user_exc(CERT_UPDATE_ERR, restaurant_id=cert.restaurant_id) with thrift_client('ers') as ers: ers.update_restaurant_certification(cert) record_process_base.add( cert.restaurant_id, cert.type, cert.status, STATUS_PENDING, comment='修改认证信息') return ''
def check_same(new_city): lcdist = new_city.get('_districts', []) if len(lcdist) == 0: # no dist,no ploblem,over return 0 distname = set([item.get('name', '') for item in lcdist]) if len(distname) < len(lcdist): raise_user_exc(DIST_NAME_REDUNDANCE) for item in lcdist: zones = item.get('_zones', []) if len(zones) == 0: break else: zonename = set([item.get('name', '') for item in zones]) if len(zonename) < len(zones): raise_user_exc(ZONE_NAME_REDUNDANCE)
def check_same(new_city): lcdist = new_city.get('_districts', []) if len(lcdist) == 0: # no dist,no ploblem,over return 0 distname = set([item.get('name', '') for item in lcdist]) if len(distname) < len(lcdist): raise_user_exc(DIST_NAME_REDUNDANCE) for item in lcdist: zones = item.get('_zones', []) if len(zones) == 0: break else: zonename = set([item.get('name', '') for item in zones]) if len(zonename) < len(zones): raise_user_exc(ZONE_NAME_REDUNDANCE)
def post(cls): args = get_args() regions = cls._region_list2map(args.pop('cities'), args.pop('region_groups'), args.pop('regions')) args['regions'] = regions b_type = args.pop('type') if b_type == banner_client.banner_type.NON_INTERACTIVE: banner_id = banner_client.add_non_interactive_banner(args) elif b_type == banner_client.banner_type.LINK: banner_id = banner_client.add_link_banner(args) elif b_type == banner_client.banner_type.ACTIVITY: banner_id = banner_client.add_activity_banner(args) else: # TODO raise_user_exc(BANNER_TYPE_ERR) return {'id': banner_id}
def process_event(event_id, status, handler_id=None): if status is None: return False if status == CSEvent.STATUS_FORWARD and handler_id is None: raise_dev_exc(DEV_BAD_REQUEST_ERROR, arg='handler_id') event = inner.get_event(event_id) if not event: raise_user_exc(CS_EVENT_NOT_EXIST, event_id=event_id) if event.status == CSEvent.STATUS_DONE: raise_dev_exc(CS_EVENT_PROCESS_STATUS_INVALID, event_id=event_id, status=event.status) event.update(status=status, handler_id=handler_id) return True
def _get_modify_permission(cls, banner_id): banner = banner_client.get(banner_id) if not banner: raise_user_exc(BANNER_NOT_EXISTS_ERR, banner_id=banner_id) banner_regions = banner.regions if not banner_regions or not banner_regions.keys(): return True banner_city_ids = banner_regions.keys() if current_user.has_groups(['activity_manager', 'marketing_manager']): return True elif current_user.has_groups(['city_director']): user_city_ids = city_base.get_city_ids_by_user() return all([banner_city_id in user_city_ids for banner_city_id in banner_city_ids]) return False
def processing(): args = args_parser.parse_all() status_to = int(args.get('status')) comment = args.get('comment', '') restaurant_id = int(args.get('restaurant_id')) cert = cert_base.get(restaurant_id) if status_to != CERTIFICATION_CONST.STATUS_PASSED and \ status_to != CERTIFICATION_CONST.STATUS_FAILED: raise_user_exc(CERT_PROC_ILL_ERR) if cert.status != CERTIFICATION_CONST.STATUS_PENDING: raise_user_exc(CERT_NOT_PENDING_ERR) cert_base.process_certification(restaurant_id, status_to) record_base.add(restaurant_id, cert.type, cert.status, status_to, comment) return ''
def update(cls, id, **bankcard_dict): query = Session().query(cls) query = query.filter(cls.id == id) rst_bankcard = query.first() if not rst_bankcard: return '' status = bankcard_dict.get('status') if status == cls.STATUS_VALID \ and rst_bankcard.status == cls.STATUS_VALID: raise_user_exc(BANKCARD_UPDATE_ERR) if rst_bankcard.status == cls.STATUS_HISTORY: raise_user_exc(BANKCARD_STATUS_INVALID) for k, v in bankcard_dict.iteritems(): if hasattr(rst_bankcard, k): setattr(rst_bankcard, k, v) Session().add(rst_bankcard)
def update(cls, id, **bankcard_dict): query = Session().query(cls) query = query.filter(cls.id == id) rst_bankcard = query.first() if not rst_bankcard: return '' status = bankcard_dict.get('status') if status == cls.STATUS_VALID \ and rst_bankcard.status == cls.STATUS_VALID: raise_user_exc(BANKCARD_UPDATE_ERR) if rst_bankcard.status == cls.STATUS_HISTORY: raise_user_exc(BANKCARD_STATUS_INVALID) for k, v in bankcard_dict.iteritems(): if hasattr(rst_bankcard, k): setattr(rst_bankcard, k, v) Session().add(rst_bankcard)
def save(): args_spec = { 'coupon_type': Arg(int, required=True, validate=lambda t: t in COUPON_TYPE, error='Invalid coupon type'), 'batch_sn': Arg(str, required=True), 'deadline': Arg(str, required=True), 'sn': Arg(str), 'remain': Arg(int), 'count': Arg(int), } args = args_parser.parse(args_spec) if args['coupon_type'] == GENERIC_COUPON: if args.get('sn') is None: raise_user_exc(COUPON_SN_REQUIRED) if not _check_sn_length(args['sn']): raise_user_exc(COUPON_SN_INVALID) remain = args.get('remain') or GENERAL_COUPON_DEFAULT_REMAIN result = coupon_base.save_generic_coupon(batch_sn=args['batch_sn'], deadline=args['deadline'], sn=args['sn'], remain=remain) result = [ result.get('sn'), ] else: if args.get('count') is None: raise_user_exc(COUPON_COUNT_REQUIRED) if int(args.get('count')) > 500: raise_user_exc(COUPON_COUNT_INVALID) result = coupon_base.save_onetime_coupon(batch_sn=args['batch_sn'], remain=1, deadline=args['deadline'], remarks=u"后台生成", count=args['count']) return result
def save(): args_spec = { 'batch_type': Arg(int, required=True, validate=lambda t: t in BATCH_TYPE_LIST, error='Invalid batch type'), 'rst_ids': Arg(str, allow_missing=True) } args = args_parser.parse(args_spec) # check restaurant ids when the batch bound with restaurant if args['batch_type'] in BATCH_TYPE_RST: if args.get('rst_ids') is None: raise_user_exc(RST_IDS_REQUIRED) args['rst_ids'] = [int(rst_id) for rst_id in args['rst_ids'].split()] batch_sn = coupon_batch_base.save( args['batch_type'], current_user.id, current_user.name, args.get('rst_ids', None) ) return { 'batch_sn': batch_sn }
def save(): args_spec = { 'batch_type': Arg(int, required=True, validate=lambda t: t in BATCH_TYPE_LIST, error='Invalid batch type'), 'rst_ids': Arg(str, allow_missing=True) } args = args_parser.parse(args_spec) # check restaurant ids when the batch bound with restaurant if args['batch_type'] in BATCH_TYPE_RST: if args.get('rst_ids') is None: raise_user_exc(RST_IDS_REQUIRED) args['rst_ids'] = [int(rst_id) for rst_id in args['rst_ids'].split()] batch_sn = coupon_batch_base.save(args['batch_type'], current_user.id, current_user.name, args.get('rst_ids', None)) return {'batch_sn': batch_sn}
def save(): args_spec = { 'coupon_type': Arg(int, required=True, validate=lambda t: t in COUPON_TYPE, error='Invalid coupon type'), 'batch_sn': Arg(str, required=True), 'deadline': Arg(str, required=True), 'sn': Arg(str), 'remain': Arg(int), 'count': Arg(int), } args = args_parser.parse(args_spec) if args['coupon_type'] == GENERIC_COUPON: if args.get('sn') is None: raise_user_exc(COUPON_SN_REQUIRED) if not _check_sn_length(args['sn']): raise_user_exc(COUPON_SN_INVALID) remain = args.get('remain') or GENERAL_COUPON_DEFAULT_REMAIN result = coupon_base.save_generic_coupon( batch_sn=args['batch_sn'], deadline=args['deadline'], sn=args['sn'], remain=remain ) result = [result.get('sn'), ] else: if args.get('count') is None: raise_user_exc(COUPON_COUNT_REQUIRED) if int(args.get('count')) > 500: raise_user_exc(COUPON_COUNT_INVALID) result = coupon_base.save_onetime_coupon( batch_sn=args['batch_sn'], remain=1, deadline=args['deadline'], remarks=u"后台生成", count=args['count'] ) return result
def to_float(something, silence=True): """ transform to int silently. return: int if ok None if error. """ error = False try: return float(something) except TypeError: error = True raise_user_exc(FORMAT_ERR, src_type='None', target_type="Float") except ValueError: error = True raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float") except Exception: error = True raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float") finally: if error and silence: return None
def to_float(something, silence=True): """ transform to int silently. return: int if ok None if error. """ error = False try: return float(something) except TypeError: error = True raise_user_exc(FORMAT_ERR, src_type='None', target_type="Float") except ValueError: error = True raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float") except Exception: error = True raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float") finally: if error and silence: return None
def add_or_update(city_id, date_from, date_end): if not _check_city_exists(city_id): raise_user_exc(CITY_NOT_EXISTS, city_id) trs_query_cfg = inner.add_or_update_trs_query_cfg(city_id, date_from, date_end) return {'city_transaction_query_config_id': trs_query_cfg.id}
def add_or_update(city_id, date_from, date_end): if not _check_city_exists(city_id): raise_user_exc(CITY_NOT_EXISTS, city_id) trs_query_cfg = inner.add_or_update_trs_query_cfg(city_id, date_from, date_end) return {'city_transaction_query_config_id': trs_query_cfg.id}
def _check_region_type(type_code): if type_code is not None: if int(type_code) not in (RegionBrand.TYPE_CBD, RegionBrand.TYPE_SCHOOL): raise_user_exc(REGION_TYPE_INVALID) return True