物业,增加月份


public function changeMonth()
{
    $origin_month = $this->input_data['origin_month'];
    $add_month = $this->input_data['add_month'];
    if (!Verify::checkMonthDate($origin_month)) {
        return false;
    }

    list($month, $day) = explode('-', $origin_month);
    $month = (int)$month;
    $day = (int)$day;

    $new_month = $month + $add_month;
    if ($new_month > 12) {
        $new_month -= 12;
    }

    $new_month = (int)$new_month;
    $new_day = $day;
    // 31天
    if (in_array($new_month, [1, 3, 5, 7, 8, 10, 12], true)) {
        $new_day = $day;
    }

    // 30天
    if (in_array($new_month, [4, 6, 9, 11], true)) {
        $new_day = ($day > 30) ? 30 : $day;
    }

    // 28天
    if ($new_month === 2) {
        $new_day = ($day > 28) ? 28 : $day;
    }

    $new_month = StrUtil::numberAddZero($new_month);
    $new_day = StrUtil::numberAddZero($new_day);
    $response = $new_month.'-'.$new_day;
    $this->json->ok($response);
}
posted @ 2021-11-17 10:47  TBHacker  阅读(93)  评论(0编辑  收藏  举报