do { xxx }while(false); 是什么操作

这个主要用于有逻辑判断的代码。
比如 里面要处理一些内容,但是又要控制一些输出或者什么逻辑的。
XXX 代码又是一个整体,里面可以直接break等处理的时候,就很有用

<?php
do{
    if(is_fail($balance_result)){
        $response = $balance_result;
        break;
    }
    $balance = $balance_result["data"]["balance"];
    if($balance < $order["diamond_num"]){
        if(! $is_retry){
            Model_Failorder::instance()->insert(array(
                'order_id' => $order['order_id'],
            ), true);
        }
        $money_as_str = Common_Money::format_money(self::balance2money($balance));
        $response = fail(__(sprintf("余额不足(余额只有%s元)", $money_as_str)));
        break;
    }
    $consume_result = $this->consume($user, $yyb_user, $order);
    if(is_fail($consume_result)){
        $response = $consume_result;
        if($response['data']['yyb_code'] == Common_Yyb::YYB_CODE_AUTH_FAIL){
            Model_Loginretryorder::instance()-> ins_by_ignore(array(
                'order_id' => $order['order_id'],
                'user_id' => $order['user_id'],
            ));
        }
        break;
    }
    $channel_status = Common_Pay::CS_SUCCESS;
    Model_Order::instance()->update_by_order_num($order_num, array(
        'channel_status' => $channel_status,
    ));
    $response = Common_Pay::complete_order_by_order_num($order_num, $is_inject);
    Common_Yyb::on_gdt_complete_order($order);
    $response['data']['consume_success'] = true;
}while(false);

if(is_fail($response)){
    //记录订单失败原因
    Model_Order::instance()->update_by_order_num($order_num, array(
        'channel_status' => $channel_status,
        'fail_reason' => $response['msg'],
    ));
}
return $response;

 

posted @ 2020-05-26 10:35  北七星  阅读(237)  评论(0编辑  收藏  举报
F**k me on Gitee