Пример #1
0
/**
 * 删除账户
 */
function delete_account()
{
    $userId = $_SESSION['userId'];
    $accountId = $_REQUEST['accountId'];
    $accountTypeFlag = $_REQUEST['accountTypeFlag'];
    $code = '0';
    // 校验该用户下的账户数
    $accountService = new AccountService();
    $accountCount = $accountService->countAccount($userId, $accountTypeFlag);
    if ($accountCount == 1) {
        // 只剩一组帐户不能再删除
        $code = 'mustHaveAccount';
    } else {
        $billService = new BillService();
        //校验账户下是否有记账
        if ($billService->countBill(null, $accountId, null) > 0 || $billService->countBillDebtRelated($accountId) > 0) {
            $code = 'existBillInAccount';
        } else {
            $accountDefault = get_user_config('accountDefault');
            if ($accountId == $accountDefault) {
                //如果删除的是默认账户
                //取按照accountId排序最小的账户作为默认
                $minId = $accountService->getMinAccountId($userId);
                set_user_config('accountDefault', $minId);
                //更新到用户表
                $userService = new UserService();
                $userService->updateConfig($userId, $_SESSION['userDetail']['user_config']);
            }
            $accountService->deleteAccount($accountId);
        }
    }
    $output = array('retCode' => $code);
    echo get_json($output);
}
Пример #2
0
/**
 * 删除收支类别
 */
function delete_bill_type()
{
    $billTypeId = $_REQUEST['billTypeId'];
    $code = '0';
    $billService = new BillService();
    // 校验类别下是否有记账
    if ($billService->countBill(null, null, $billTypeId) > 0) {
        $code = 'existBillInBillType';
    } else {
        $billTypeService = new BillTypeService();
        $billTypeService->deleteBillType($billTypeId);
    }
    $output = array('retCode' => $code);
    echo get_json($output);
}