isAjax()) { $subject = Db::name('InvoiceSubject')->order('create_time asc')->select(); return to_assign(0, '', $subject); } else { return view(); } } //提交保存分类 public function subject_add() { if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { validate(InvoiceSubjectCheck::class)->scene('edit')->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } $param['update_time'] = time(); $res = InvoiceSubject::strict(false)->field(true)->update($param); if ($res) { if($param['status'] == 0){ add_log('disable', $param['id'], $param); } else if($param['status'] == 1){ add_log('recovery', $param['id'], $param); } else{ add_log('edit', $param['id'], $param); } } return to_assign(); } else { try { validate(InvoiceSubjectCheck::class)->scene('add')->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } $param['create_time'] = time(); $insertId = InvoiceSubject::strict(false)->field(true)->insertGetId($param); if ($insertId) { add_log('add', $insertId, $param); } return to_assign(); } } } public function get_list($param = [], $where = []) { $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $expense = InvoiceList::where($where) ->order('id desc') ->paginate($rows, false, ['query' => $param]) ->each(function ($item, $key) { $item->user = Db::name('Admin')->where(['id' => $item->admin_id])->value('name'); $item->department = Db::name('Department')->where(['id' => $item->did])->value('title'); $item->check_name = Db::name('Admin')->where(['id' => $item->check_admin_id])->value('name'); $item->check_time = empty($item->check_time) ? '-' : date('Y-m-d H:i', $item->check_time); $item->open_name = Db::name('Admin')->where(['id' => $item->open_admin_id])->value('name'); $item->open_time = empty($item->open_time) ? '-' : date('Y-m-d H:i', $item->open_time); }); return $expense; } public function detail($id = 0) { $invoice = Db::name('Invoice')->where(['id' => $id])->find(); if ($invoice) { $invoice['user'] = Db::name('Admin')->where(['id' => $invoice['admin_id']])->value('name'); $invoice['department'] = Db::name('Department')->where(['id' => $invoice['did']])->value('title'); $invoice['check_admin'] = Db::name('Admin')->where(['id' => $invoice['check_admin_id']])->value('name'); $invoice['open_admin'] = Db::name('Admin')->where(['id' => $invoice['open_admin_id']])->value('name'); if ($invoice['check_time'] > 0) { $invoice['check_time'] = empty($invoice['check_time']) ? '0' : date('Y-m-d H:i', $invoice['check_time']); } if ($invoice['open_time'] > 0) { $invoice['open_time'] = empty($invoice['open_time']) ? '0' : date('Y-m-d H:i', $invoice['open_time']); } else{ $invoice['open_time'] = '-'; } } return $invoice; } public function index() { if (request()->isAjax()) { $param = get_params(); $where = []; $where[] = ['status', '=', 1]; //按时间检索 $start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0; $end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0; if ($start_time > 0 && $end_time > 0) { $where[] = ['create_time', 'between', [$start_time, $end_time]]; } if (isset($param['invoice_status']) && $param['invoice_status']!='') { $where[] = ['invoice_status', '=', $param['invoice_status']]; } $invoice = $this->get_list($param, $where); return table_assign(0, '', $invoice); } else { return view(); } } //添加&编辑 public function add() { $param = get_params(); if (request()->isAjax()) { $param['invoice_status'] = 1; if ($param['type'] == 1) { if (!$param['invoice_tax']) { return to_assign(1, '纳税人识别号不能为空'); } if (!$param['invoice_bank']) { return to_assign(1, '开户银行不能为空'); } if (!$param['invoice_account']) { return to_assign(1, '银行账号不能为空'); } if (!$param['invoice_banking']) { return to_assign(1, '银行营业网点不能为空'); } if (!$param['invoice_address']) { return to_assign(1, '银地址不能为空'); } } if (!empty($param['id']) && $param['id'] > 0) { try { validate(InvoiceCheck::class)->scene('edit')->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } $param['update_time'] = time(); $res = InvoiceList::where('id', $param['id'])->strict(false)->field(true)->update($param); if ($res !== false) { add_log('edit', $param['id'], $param); return to_assign(); } else { return to_assign(1, '操作失败'); } } else { try { validate(InvoiceCheck::class)->scene('add')->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } $admin_id = $this->uid; $param['admin_id'] = $admin_id; $param['did'] = get_login_admin('did'); $param['create_time'] = time(); $exid = InvoiceList::strict(false)->field(true)->insertGetId($param); if ($exid) { add_log('apply', $exid, $param); return to_assign(); } else { return to_assign(1, '操作失败'); } } } else { $id = isset($param['id']) ? $param['id'] : 0; if ($id > 0) { $detail = $this->detail($id); View::assign('detail', $detail); } View::assign('user', get_admin($this->uid)); View::assign('id', $id); return view(); } } //查看 public function view() { $id = empty(get_params('id')) ? 0 : get_params('id'); $detail = $this->detail($id); View::assign('uid', $this->uid); View::assign('detail', $detail); return view(); } //删除 public function delete() { $id = get_params("id"); $detail = $this->detail($id); if ($detail['invoice_status'] == 2) { return to_assign(1, "已审核的发票不能删除"); } if ($detail['invoice_status'] == 3) { return to_assign(1, "已开具的发票不能删除"); } $data['status'] = '-1'; $data['id'] = $id; $data['update_time'] = time(); if (Db::name('Invoice')->update($data) !== false) { add_log('delete', $id); return to_assign(0, "删除成功"); } else { return to_assign(1, "删除失败"); } } //设置 public function check() { $param = get_params(); if (request()->isAjax()) { if ($param['invoice_status'] == 2 || $param['invoice_status'] == 0) { $param['check_time'] = time(); add_log('check', $param['id'],$param); } if ($param['invoice_status'] == 3) { $param['open_time'] = time(); add_log('open', $param['id'],$param); } if ($param['invoice_status'] == 10) { $count = Db::name('InvoiceIncome')->where(['inid'=>$param['id'],'status'=>1])->count(); if($count>0){ return to_assign(1, "发票已经新增有到账记录,请先反到账后再作废发票"); } else{ $param['update_time'] = time(); add_log('tovoid', $param['id'],$param); } } $res = InvoiceList::where('id', $param['id'])->strict(false)->field(true)->update($param); if ($res !== false) { return to_assign(); } else { return to_assign(1, "操作失败"); } } } }