def order_status(order_id, new_status): """Edits the status of specific order.""" if new_status in remote_statuses(): new_status = new_status.decode(sys.stdin.encoding) else: status_list = ', '.join(remote_statuses()) bcolors.fail('status must be one of %s' % status_list) return order = HoardOrder.get(order_id) if not order: bcolors.fail('order not found') return profile = HoardProfile.get(order.user_id) matched_index = [ index for index, order_info in enumerate(profile.person_account_info) if order_info['finOrderNo'] == order.fin_order_id ] if not matched_index: bcolors.fail('failed') return account_info = list(profile.person_account_info) account_info[matched_index[0]]['finOrderStatus'] = unicode(new_status) profile.person_account_info = account_info bcolors.success('done')
def total_orders(self): from core.models.hoarder.order import HoarderOrder yx_orders = HoardOrder.get_total_orders(self.user_id) zw_orders = ZhiwangOrder.get_total_orders(self.user_id) xm_orders = XMOrder.get_total_orders(self.user_id) sxb_orders = HoarderOrder.get_order_amount_by_user(self.user_id) return yx_orders + zw_orders + xm_orders + sxb_orders
def has_bought_newcomer_product(self): """判断是否购买了新手产品 暂时适用于2016年5月1日之后购买第一笔订单的用户""" from core.models.hoarder.order import HoarderOrder if ZhiwangOrder.has_wrapped_product(self.user_id): return True start_time = datetime(2016, 05, 01, 0, 0, 0) xm_orders = XMOrder.get_multi_by_user(self.user_id) xm_orders = [ o for o in xm_orders if o.status in [ XMOrder.Status.committed, XMOrder.Status.shelved, XMOrder.Status.paying, XMOrder.Status.success ] ] xm_order = xm_orders[-1] if len(xm_orders) > 0 else None condition_xm_orders = bool(xm_order and xm_order.creation_time < start_time) orders = HoarderOrder.get_multi_by_user(self.user_id) orders = [ o for o in orders if o.status in [ HoarderOrder.Status.committed, HoarderOrder.Status.shelved, HoarderOrder.Status.paying, HoarderOrder.Status.success ] ] order = orders[-1] if len(orders) > 0 else None condition_orders = bool(order and order.creation_time < start_time) if any([ HoardOrder.get_total_orders(self.user_id) > 0, ZhiwangOrder.get_total_orders(self.user_id) > 0, condition_xm_orders, condition_orders ]): return True return False
def hoard_yrd_withdrawing(order_id): """设置宜人贷提现银行卡.""" from core.models.hoard import YixinAccount, HoardOrder order = HoardOrder.get(order_id) if order.fetch_status() != u'已转出': token = YixinAccount.get_by_local(order.user_id).p2p_token order.register_for_withdrawing(yixin.client, token)
def hoard_yrd_payment_tracking(order_id): """同步用户宜人贷订单支付状态""" from core.models.hoard import HoardOrder, HoardProfile from core.models.hoard.profile import fetch_account_info, clear_account_info_cache order = HoardOrder.get(order_id) # take account info fetch as payment status sync trick profile = HoardProfile.add(order.user_id) clear_account_info_cache(order.user_id) fetch_account_info(profile) order = HoardOrder.get(order_id) rsyslog.send('%s\t%s' % (order_id, order.status), tag='yixin_payment_track') if not order.is_success and not order.is_failure: raise WorkerTaskError(hoard_yrd_payment_tracking.tube)
def hoard_yrd_confirming(order_id): """确认宜人贷订单状态""" from core.models.hoard import YixinAccount, HoardOrder from core.models.hoard.order import RemoteStatus order = HoardOrder.get(order_id) token = YixinAccount.get_by_local(order.user_id).p2p_token response = yixin.query.order_status(token, order.order_id, max_retry=3) status = RemoteStatus(response.data.status) if status == RemoteStatus.success: order.mark_as_confirmed() elif status == RemoteStatus.unknown: raise WorkerTaskError(hoard_yrd_confirming.tube) # let it fail elif status == RemoteStatus.failure: order.mark_as_failure() raise WorkerTaskError(hoard_yrd_confirming.tube) # let it fail else: raise WorkerTaskError(hoard_yrd_confirming.tube) # let it fail
def hoard_yrd_exiting_checker(order_id): """确认宜人贷订单转出状态.""" from core.models.hoard import HoardOrder, HoardProfile from core.models.hoard.profile import clear_account_info_cache order = HoardOrder.get(order_id) profile = HoardProfile.get(order.user_id) orders = profile.orders() if order.fetch_status(orders) == u'已转出': order.mark_as_exited() elif order.fetch_status(orders) == u'已结束': order.mark_as_exited() else: clear_account_info_cache(order.user_id) orders = profile.orders() if order.fetch_status(orders) == u'已转出': order.mark_as_exited() if order.fetch_status(orders) == u'已结束': order.mark_as_exited()
def hoard_yrd_sms_sender(order_id): """宜人贷转出订单发送到期短信""" from core.models.sms import ShortMessage from core.models.sms.kind import savings_order_exited_sms from core.models.hoard import HoardOrder, HoardProfile from core.models.hoard.profile import clear_account_info_cache order = HoardOrder.get(order_id) user = Account.get(order.user_id) profile = HoardProfile.get(order.user_id) if not user.has_mobile(): return # 更新订单最新信息 clear_account_info_cache(order.user_id) orders = profile.orders() profit = order.fetch_profit_until(datetime.date.today(), orders) # 发送短信 sms = ShortMessage.create(user.mobile, savings_order_exited_sms, order_amount=int(order.order_amount), profit=str(round_half_up(profit, 2))) sms.send_async()