model = new \app\admin\model\fastflow\flow\Ebill; } public function index() { $bill_model = new \app\admin\model\fastflow\flow\Bill; if ($this->request->isAjax()) { $bill_table = ''; if ($this->request->has('bill')) { $bill_table = input('bill'); } else { $bill_id = input('bill_id'); if ($bill_id) { $bill_row = $bill_model->find($bill_id); if (!$bill_row) { return ['code' => 0, 'msg' => '未找到单据']; } $bill_table = $bill_row['bill_table']; } } $ebill_rows = $this->model->field(['id', 'title', 'info', 'thumbnail', 'thumb_width', 'thumb_height', 'createtime'])->where(['bill' => $bill_table])->select(); return ['code' => 1, 'msg' => '获取成功', 'ebills' => $ebill_rows]; } $bills = $bill_model->field(['id', 'bill_name', 'bill_table'])->select(); $this->view->assign(['bills' => $bills]); return $this->view->fetch(); } /** * 添加 * * @return string * @throws \think\Exception */ public function add() { if (false === $this->request->isPost()) { $bill_id = input('bill_id'); if ($bill_id == null) { return '参数错误:未传递单据ID'; } $this->view->assign(['bill_id' => $bill_id]); return $this->view->fetch(); } $params = $this->request->post(''); $params_row = $params['row']; unset($params['row']); $params = array_merge($params_row, $params); if ($params['title'] == '') { $this->error('请填写表单名称'); } if ($params['file'] == '') { $this->error('文件路径不能为空'); } $bill_id = $params['bill']; $bill_row = (new \app\admin\model\fastflow\flow\Bill())->find($bill_id); if (!$bill_row) { $this->error('未查询到相应单据'); } $params['md5'] = md5_file(ltrim($params['file'], '/')); $params['bill'] = $bill_row['bill_table']; $ebill_rows = $this->model->where(['bill' => $params['bill']])->select(); foreach ($ebill_rows as $ebill_row) { if ($params['md5'] == $ebill_row['md5']) { $this->error('该单据已存在相同电子表单'); } } if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException()->validate($validate); } $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success('添加成功'); } /** * 编辑 * * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post(); $params_row = $params['row']; unset($params['row']); $params = array_merge($params_row, $params); if ($params['title'] == '') { $this->error('请填写表单名称'); } if ($params['file'] == '') { $this->error('文件路径不能为空'); } $params['md5'] = md5_file(ltrim($params['file'], '/')); $ebill_rows = $this->model->where(['bill' => $row['bill']])->select(); foreach ($ebill_rows as $ebill_row) { if ($ids != $ebill_row['id'] && $params['md5'] == $ebill_row['md5']) { $this->error('该单据已存在相同电子表单'); } } if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success('修改成功'); } //文件路径优先,同时存在id和路径,选择路径 public function preview() { $path = null; $row = []; $action = input('action'); if ($action == 'detail') {//查看电子表单详情 $bill = input('bill'); $bill_id = input('bill_id'); $ebill_copy = $this->getEbillCopy($bill, $bill_id); if ($ebill_copy) { //查询是否有发起签章 $signature = (new Signature())->where(['bill' => $bill, 'bill_id' => $bill_id])->find(); if ($signature) { $this->view->assign(['code' => 1, 'hasSignature' => true, 'ebill' => $signature['ebill'], 'size' => ['width' => $signature['ebill_width'], 'height' => $signature['ebill_height']], 'ebill_title' => $ebill_copy['title']]); $this->assignconfig(['hasSignature' => true]); return $this->view->fetch(); } //为无签章时提供电子表单标题 $bill_row = (new Bill())->where(['bill_table' => $bill])->find(); $this->assignconfig(['bill_name' => $bill_row['bill_name']]); //传递二维码数据 $configModel = new \app\admin\model\fastflow\flow\Config(); $config_qrcode = $configModel->where(['name' => 'qrcode'])->find(); $config_qrcodepos = $configModel->where(['name' => 'qrcodepos'])->find(); $config_qrcodesize = $configModel->where(['name' => 'qrcodesize'])->find(); $detail_url = url('/fastflow/flow/flow/detail', ['bill' => $bill, 'bill_id' => $bill_id], false, true); $this->assignconfig(['qrcode' => $config_qrcode['value'], 'qrcodepos' => $config_qrcodepos['value'], 'qrcodesieze' => $config_qrcodesize['value'], 'bill' => $bill, 'bill_id' => $bill_id, 'detail_url' => $detail_url]); /// $path = $ebill_copy['file']; } } elseif ($action == 'preview') { if ($this->request->has('file')) {//新增电子表单 $path = input('file'); } elseif ($this->request->has('id')) {//编辑电子表单、发起时添加电子表单 $ebill = $this->model->where(['id' => input('id')])->find(); if ($ebill) { $path = $ebill['file']; $this->assignconfig(['ebill_title' => $ebill['title']]); } } } if ($path == null) { $this->view->assign(['code' => 0, 'msg' => '参数错误:未找到文件']); return $this->view->fetch(); } if (input('row/a')) { $row = input('row/a'); } $row = $this->updateBillRow(input('bill'), input('bill_id'), $row); $result = $this->word2html($path, $row); if (!$result['code']) { $this->view->assign(['code' => 0, 'msg' => $result['msg']]); } else { $content = $result['content']; $style_pattern = '/(?<=