namespace yapserver

1.namespace使用

namespace yapserver{

  class A{
    public:
    int get(){}
    int a;
  }
}
使用类A定义对象:
yapserver::A& a;

3.

bool refund_trans_service<payment_mode>::handle_detail(const common_data_t &common_data, refund_trans_data &service_data)
{
    bool is_sys_reentry = false;

    //读取参数
    UB_LOG_TRACE("read params...");
    read_param(common_data, service_data);
    
    //检测权限
    UB_LOG_TRACE("check permission...");
    check_permission(common_data, service_data);
    
    //检测参数
    UB_LOG_TRACE("check param...");
    check_param(common_data, service_data);
    
    for (int index_refund = 0, refund_count = 1; index_refund < refund_count; index_refund++) //refund_count执行次数可以在循环体内增加
    {
        refund_trans_data deal_service_data(service_data);

        try
        {
            //开启事务
            UB_LOG_TRACE("start transaction...");
            start_transaction(common_data, deal_service_data);

            //若为重入返回true,由pay_base_service返回redis内的数据
            UB_LOG_TRACE("check system reentry...");
            if (is_system_reentry(common_data, deal_service_data))
            {
                UB_LOG_TRACE("handle system reentry...");
                system_reentry(common_data, deal_service_data);
                is_sys_reentry = true;
            }
            else
            {
                //前置处理
                UB_LOG_TRACE("front handles...");
                front_handles(common_data, deal_service_data);
 
                //检测是否已成功执行过
                UB_LOG_TRACE("check already handled...");
                check_handled(common_data, deal_service_data);

                if (0 == index_refund)
                {
                    //检测降级
                    UB_LOG_TRACE("check demote...");
                    check_demote(common_data, deal_service_data);
                }

                //处理业务逻辑
                UB_LOG_TRACE("handle service...");
                handle_service(common_data, deal_service_data);
                
                //收集记账信息
                UB_LOG_TRACE("keep accounts...");
                keep_accounts(common_data, deal_service_data);
                
                //提交事务
                UB_LOG_TRACE("commit transaction...");
                commit_transaction(common_data, deal_service_data);
  
                //埋点
                UB_LOG_TRACE("collect trace...");
                collect_trace(common_data, deal_service_data);
               
                //输出数据
                UB_LOG_TRACE("output pack...");
                output_pack(common_data, deal_service_data);
            }
        }
        catch (service_exception& e)
        {
            //返现退款时买家余额不足
            if (PAY_ERR_REFUND_CASHBACK_NOT_ENOUGH == e.code())
            {
                if (!service_data.cashback_failed_once)
                {
                    session_.roll_back();
                    service_data.cashback_failed_once = true;
                    //再退一次
                    refund_count++;
                }
                else
                {
                    throw service_exception(PAY_ERR_BALANCE_NOT_ENOUGH_TO_PAY, e.what());
                }
            }
            //待结算交易退款时卖家余额不足
            else if (PAY_ERR_REFUND_SELLER_UNSETTLED_NOT_ENOUGH == e.code())
            {
                //待结算账户资金不足时现金账户替补
                if (!service_data.seller_unsettled_not_enough)
                {
                    session_.roll_back();
                    service_data.seller_unsettled_not_enough = true;
                    
                    //再退一次
                    refund_count++;

                    UB_LOG_TRACE("seller refund: unsettled balance not enough");
                }
                else
                {
                    //抛出原来的错误码,业务方已兼容
                    throw service_exception(PAY_ERR_BALANCE_NOT_ENOUGH_TO_PAY, e.what());
                }
            }
            else
            {
                throw e;
            }
        }
    }

    return is_sys_reentry;
}

 

posted @ 2021-03-04 14:04  dsfsadfdgd  阅读(75)  评论(0编辑  收藏  举报