/** * 更新账目 */ function update_bill() { $userId = (int) $_SESSION['userId']; $op = $_REQUEST['op']; $billTypeFlag = (int) $_REQUEST['billTypeFlag']; $billId = is_empty($_REQUEST['billId']) ? null : (int) $_REQUEST['billId']; $billTime = $_REQUEST['billTime']; $billTypeId = is_empty($_REQUEST['billTypeId']) ? null : (int) $_REQUEST['billTypeId']; $accountId = (int) $_REQUEST['accountId']; $account2Id = is_empty($_REQUEST['account2Id']) ? null : $_REQUEST['account2Id']; $billSum = is_empty($_REQUEST['billSum']) ? null : (double) $_REQUEST['billSum']; $billDesc = is_empty($_REQUEST['billDesc']) ? null : $_REQUEST['billDesc']; $repayArray = is_empty($_REQUEST['repayArray']) ? null : $_REQUEST['repayArray']; $code = '0'; if ($op == 'add') { $billId = -1; } $billService = new BillService(); if ($op == 'add') { // 新增 switch ($billTypeFlag) { case 0: case 1: $billService->insertNormalBill($userId, $billTypeFlag, $billTime, $billTypeId, $accountId, $billSum, $billDesc); break; case 2: case 3: $billService->insertTransferBill($userId, $billTypeFlag, $billTime, $billTypeId, $accountId, $account2Id, $billSum, $billDesc); break; case 5: case 6: $billService->insertDebtBill($userId, $billTypeFlag, $billTime, $billTypeId, $accountId, $account2Id, $billSum, $billDesc); break; case 4: case 7: $repayArray = json_to_array(urldecode($repayArray)); //校验还款、收款合法性 foreach ($repayArray as $repay) { if ($billService->checkRepay((int) $repay['billId'], (double) $repay['repaySum']) == false) { $code = 'mustRefreshRepayList'; break; } } if ($code == '0') { //插入还款、收款记录 foreach ($repayArray as $repay) { $billService->insertRepayBill($userId, $billTypeFlag, $billTime, $accountId, $billDesc, (int) $repay['billId'], (double) $repay['repaySum']); } } break; } } else { if ($op == 'edit') { // 修改 switch ($billTypeFlag) { case 0: case 1: $billService->updateNormalBill($userId, $billTypeFlag, $billId, $billTime, $billTypeId, $accountId, $billSum, $billDesc); break; case 2: case 3: $billService->updateTransferOutBill($userId, $billTypeFlag, $billId, $billTime, $billTypeId, $accountId, $account2Id, $billSum, $billDesc); break; case 5: case 6: //校验要修改的记录是否已经有了关联记录 if ($billService->countBillRepayRelated($billId) > 0) { $code = 'existBillRelated'; } else { $billService->updateDebtBill($userId, $billTypeFlag, $billId, $billTime, $billTypeId, $accountId, $account2Id, $billSum, $billDesc); } break; case 4: case 7: $billService->updateRepayBill($userId, $billTypeFlag, $billId, $billTime, $accountId, $billSum, $billDesc); break; } } } $output = array('retCode' => $code); echo get_json($output); }