def _sj_sms(expr, msg): start = time.time() shortened_url = tiny_url("http://cha.123feng.com/#/order/list/mobile/%s" % expr.number) sms_content = "您好, 您的快件(单号: {number})已由风先生配送, 追踪运单请点击: {url}【风先生】".format( number=expr.number, url=shortened_url ) async_send_sms(expr["node"]["node_n"]["tel"], sms_content, SMS_TYPE_NORMAL) end = time.time() logging.info('@@@: [_sj_sms] = %s' % (datetime.timedelta(seconds=(end - start))))
def api_working_relation_apply_unbind_manager(): # 输入: man_id kw = ctx.request.input() man = Man.objects(id=kw.man_id).first() if man and man.my_manager: manager_id = man.my_manager['id'] manager = Man.objects(id=manager_id).first() if manager and manager.tel: # 给manager发短信 async_send_sms(manager.tel, '派件员%s %s 申请解除绑定关系,请尽快处理!' % (man.name, man.tel), sms_type=SMS_TYPE_NORMAL) else: raise ValueError("找不到相关人员.")
def api_working_relation_del_man(): # 输入: manager_id, man_id kw = ctx.request.input() manager = Man.objects(id=kw.manager_id).first() man = Man.objects(id=kw.man_id).first() err_str = "Unbind man[%s][%s] for manager[%s][%s] failed." % ( kw.man_id, man.name, kw.manager_id, manager.name) # 检查从属关系 if not man or not manager: raise ValueError("解绑工作关系失败:找不到相关人员.") if not man.my_manager or not manager.my_man: logging.error(err_str) raise ValueError("解绑工作关系失败:关联人员不一致.") if str(man.my_manager['id']) != str(manager.pk): logging.error(err_str) raise ValueError("解绑工作关系失败:关联人员不一致.") if str(Man.objects(my_man__id=kw.man_id).first().pk) != str(manager.pk): logging.error(err_str) raise ValueError("解绑工作关系失败:关联人员不一致.") # 我是区域经理: bind_time = man.my_manager['bind_time'] one_man = dict(id=kw.man_id, name=man.name, tel=man.tel, bind_time=bind_time) # 1. 去掉我的Document下的那个小弟 # result = Man.objects(my_man__id=kw.man_id).update_one(full_result=True, **{'unset__my_man__$': 1}) result = manager.update(pull__my_man__id=kw.man_id, full_result=True) if result['nModified'] == 0: logging.error(err_str) raise ValueError("解绑工作关系失败.") # 2. 去掉小弟Document下的my_manager result = man.update(my_manager=None, full_result=True) if result['nModified'] == 0: manager.update(add_to_set__my_man=one_man) logging.error(err_str) raise ValueError("解绑工作关系失败.") # 移除小弟成功: 发短信通知小弟 async_send_sms(man.tel, '您好,您与区域经理%s %s 的工作关系已解除,请知悉.' % (manager.name, manager.tel), sms_type=SMS_TYPE_NORMAL)
def update_status(cls, operator_type, shop, event, current_status=None, **kwargs): """ 更新对象的状态 :param operator_type: 'OUTSIDE'/'FE_INSIDE' :param shop: Shop 对象 :param current_status: 当前状态, 如果为None就拿obj的status字段 :param event: 派件员事件类型 :param kwargs: 目前支持: operator_id: 操作人id remark: 操作备注 :return: obj 或 None, None表示出错 """ if current_status is None: current_status = shop.status if shop.status else cls.STATUS_INIT next_state = cls.get_next_state(operator_type, current_status, event) next_status = next_state['next'] if next_state else None if operator_type == 'FE_INSIDE': # ===> 上帝操作!!! <=== if event == cls.EVENT_RESET: next_status = cls.STATUS_INIT # ===> 拉黑操作!!! <=== elif event == cls.EVENT_BAN: next_status = cls.STATUS_BANNED # ===> 修改资料!!! <=== elif event == cls.EVENT_ALTER_INFO: next_status = current_status # 日志 debug_str = 'shop_id[%s][%s]: from [%s] to [%s], event[%s].' % ( shop.id, shop.name, current_status, next_status, event) logging.info(debug_str) if next_status else logging.warning(debug_str) if next_status: # 更新状态 from_status = current_status kwargs['status'] = next_status # 过滤掉不需要的字段 kw = ShopLogic.filter_shop(kwargs, excludes=('shop_id', 'password'), includes=('fee__fh', 'fee__ps', 'fee__fh_base')) shop.modify(**kw) shop.reload() # 事件记录 fsm_log = dict(shop_id=str(shop.pk), shop_name=shop.name, from_status=from_status, to_status=next_status, event=event, operator_type=operator_type, operator_id=kwargs.get('operator_id', ''), remark=kwargs.get('remark', None), create_time=utc_8_now(ret='datetime')) ShopFSMLogLogic.create(**fsm_log) # 判断是否要发送短信提醒: 有remark的话,添加到文案中. if next_state and 'send_sms' in next_state: if kwargs.get('remark'): msg = next_state['send_sms'].format(remark=', 理由: %s。' % kwargs['remark']) else: msg = next_state['send_sms'] async_send_sms(shop.tel, msg=msg, sms_type=SMS_TYPE_NORMAL) return shop else: return None
def _no_cash_sms(expr, msg): msg = '很遗憾,您的运单未通过认证%s。' % msg async_send_sms(expr.assignee['tel'], msg, SMS_TYPE_NORMAL)
def _tt_sms(expr, msg): msg = "您的包裹已妥投,妥投类型:%s,风先生期待再次为您服务!" % (msg if msg else '本人签收') async_send_sms(expr['node']['node_n']['tel'], msg, SMS_TYPE_NORMAL)
def update_status(cls, operator_type, man, event, current_status=None, **kwargs): """ 更新对象的状态 :param operator_type: 'APP'/'FE' :param man: Man 对象 :param current_status: 当前状态, 如果为None就拿obj的status字段 :param event: 派件员事件类型 :param kwargs: 目前支持: operator_id: 操作人id remark: 操作备注 :return: obj 或 None, None表示出错 """ if current_status is None: current_status = man.status if man.status else cls.STATUS_INIT # 构造传入状态机本身的参数 kw = { 'man_id': man.id, } next_state = cls.get_next_state(operator_type, current_status, event, **kw) next_status = next_state['next'] if next_state else None if operator_type == 'FE': # ===> 上帝操作!!! <=== if event == cls.EVENT_RESET: next_status = cls.STATUS_INIT # ===> 拉黑操作!!! <=== elif event == cls.EVENT_BAN: next_status = cls.STATUS_BANNED # ===> 修改资料!!! <=== elif event == cls.EVENT_COMPLETE_INFO: next_status = current_status # 日志 debug_str = 'man_id[%s][%s]: from [%s] to [%s], event[%s].' % ( man.id, man.name, current_status, next_status, event) logging.info(debug_str) if next_status else logging.warning(debug_str) if next_status: # 更新状态 from_status = current_status kwargs['status'] = next_status kw = ManLogic.filter_man(kwargs) man.modify(**kw) # 事件记录 fsm_log = dict(man_id=str(man.pk), man_name=man.name, from_status=from_status, to_status=next_status, event=event, operator_type=operator_type, operator_id=kwargs.get('operator_id', ''), remark=kwargs.get('remark', None), create_time=utc_8_now(ret='datetime')) ManFSMLogLogic.create(**fsm_log) # 判断是否要发送短信提醒: 有remark的话,添加到文案中. if next_state and 'send_sms' in next_state: if kwargs.get('remark'): msg = next_state['send_sms'].format(remark=', 理由: %s。' % kwargs['remark']) else: msg = next_state['send_sms'] async_send_sms(man.tel, msg=msg, sms_type=SMS_TYPE_NORMAL) return man else: return None
def _will_come(call, msg, operator): async_send_sms( call['shop_tel'], '您已呼叫成功,收件员%s %s 即将上门,请耐心等待。' % (operator.get('name', ''), operator.get('tel', '')))