public function get_init_params($chargers, $applicant, $options) { $param = json_decode($_REQUEST['adids'], true)['range']; $ad_service = new AD(); $invoice_service = new Invoice(); $quote_res = array(); $ad_id = ''; foreach ($param as $str) { $ad_id = $str['ad_ids'][0]; $res = $ad_service->get_quote_by_ads($str['start'], $str['end'], implode("','", $str['ad_ids'])); foreach ($res as $quote) { // 判断是否存在已经开过发票的广告 $nums = $invoice_service->is_invoice($quote['ad_id'], $quote['quote_start_date'], $quote['quote_end_date']); if ($nums > 0) { $this->exit_with_error(50, '此广告已开过发票,点击确定返回发票页!', 403); } if (isset($quote['cpa_after'])) { unset($quote['cpa_after']); } if (isset($quote['quote_rmb_after'])) { unset($quote['quote_rmb_after']); } array_push($quote_res, $quote); } } $ad_info = $ad_service->get_ad_info_by_id($ad_id); $agreement_service = new Agreement(); $agreement = $agreement_service->get_agreement_by_id(array('id' => $ad_info['agreement_id'])); // 结算单收款方信息 $accept = InvoiceModel::$ACCEPT[$agreement['company_dianjoy']]; $init = array('apply_time' => date('Y-m-d'), 'start' => date_format(date_create($quote_res[0]['quote_start_date']), 'Y-m'), 'agreement_number' => $agreement['agreement_id'], 'company' => $agreement['company'], 'company_short' => $agreement['company_short'], 'cycle' => $agreement['cycle'], 'rmb' => $agreement['rmb'], 'agreement_comment' => $agreement['comment'], 'ad_name' => $agreement['ad_name'], 'sign_date' => $agreement['sign_date'], 'type' => 0, 'content_type' => 0, 'company_dianjoy' => $agreement['company_dianjoy'], 'accept_company' => $accept['accept_company'], 'accept_bank' => $accept['accept_bank'], 'accept_account' => $accept['accept_account'], 'chargers' => $chargers, 'applicant' => $applicant['NAME'], 'products' => $quote_res); $this->output(array('code' => 0, 'msg' => 'init', 'invoice' => $init, 'options' => array_merge(array('init' => true), $options))); }
public function re_choice_ads($attr, $old_invoice) { $DB = $this->get_read_pdo(); $invoice_service = new Invoice(); $invoice_adids = $invoice_service->get_invoice_adids_by_invoiceid($this->id); if (is_array($attr['ids'])) { $del_adids = array_diff($invoice_adids, $attr['ids']); $ins_adids = array_diff($attr['ids'], $invoice_adids); } else { $adids = array(); array_push($adids, $attr['ids']); $del_adids = array_diff($invoice_adids, $adids); $ins_adids = array_diff($adids, $invoice_adids); } if (count($del_adids) > 0) { $del_rows = $invoice_service->delete_invoice_ad_by_invoiceid_adid($this->id, implode("','", $del_adids)); } $ad_service = new AD(); $start = $old_invoice['start']; $end = $old_invoice['end']; if (count($ins_adids) > 0) { $quote_res = $ad_service->get_quote_by_ads($start, $end, implode("','", $ins_adids)); $invoice_arr = $this->construct_invoice_ads($quote_res, $this->id); $this->save_invoice_ad_info($DB, $invoice_arr); } $res = $invoice_service->get_invoice_ad_by_invoiceid($this->id); $invoice_attr = $this->get_params_by_income($res, $old_invoice['comment']); $check = SQLHelper::update($DB, self::$T_INVOICE, $invoice_attr, $this->id); if (!$check && $check != 0) { throw new Exception('更新发票信息失败。', 21); } $attr = array_merge(array('id' => $this->id, 'products' => $res)); return $attr; }