Template.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\controller\ps;
  3. use app\common\controller\Backend;
  4. use app\common\library\ps\PaperSize;
  5. use app\common\library\ps\PrintPlanner;
  6. use app\common\library\ps\TemplateIngest;
  7. /**
  8. * 流程单-模板
  9. *
  10. * @icon fa fa-file-text-o
  11. */
  12. class Template extends Backend
  13. {
  14. /**
  15. * Template模型对象
  16. * @var \app\admin\model\ps\Template
  17. */
  18. protected $model = null;
  19. protected $relationSearch = true;
  20. protected $searchFields = 'id,name';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\admin\model\ps\Template;
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. $this->view->assign("sourceList", $this->model->getSourceList());
  27. $this->view->assign("licenseTypeList", $this->model->getLicenseTypeList());
  28. $this->view->assign('paperList', PaperSize::presets());
  29. $this->view->assign('fieldCatalog', PrintPlanner::fieldCatalog());
  30. $factories = [];
  31. try {
  32. $factories = (new \app\admin\model\ps\Factory())
  33. ->where('status', 'normal')
  34. ->order('id desc')
  35. ->column('name', 'id');
  36. } catch (\Exception $e) {
  37. $factories = [];
  38. }
  39. $this->view->assign('factories', $factories);
  40. }
  41. /**
  42. * 上传标准图 + 色块图并识版入库
  43. */
  44. public function add()
  45. {
  46. if (false === $this->request->isPost()) {
  47. return $this->view->fetch();
  48. }
  49. $params = $this->request->post('row/a');
  50. if (empty($params)) {
  51. $this->error(__('Parameter %s can not be empty', ''));
  52. }
  53. try {
  54. $result = TemplateIngest::ingest($params);
  55. } catch (\Exception $e) {
  56. $this->error($e->getMessage());
  57. }
  58. $msg = '已入库,识别到 ' . $result['cells'] . ' 个填写格(' . $result['paper'] . ',图 ' . $result['image'] . ')';
  59. if (!empty($result['unlabeled'])) {
  60. $msg .= ',其中 ' . $result['unlabeled'] . ' 个未读出色块文字,套打时这些格不会填值';
  61. }
  62. $this->success($msg, null, $result);
  63. }
  64. /**
  65. * 查看
  66. */
  67. public function index()
  68. {
  69. $this->request->filter(['strip_tags', 'trim']);
  70. if ($this->request->isAjax()) {
  71. if ($this->request->request('keyField')) {
  72. return $this->selectpage();
  73. }
  74. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  75. $list = $this->model
  76. ->with(['factory'])
  77. ->where($where)
  78. ->order($sort, $order)
  79. ->paginate($limit);
  80. $result = array("total" => $list->total(), "rows" => $list->items());
  81. return json($result);
  82. }
  83. return $this->view->fetch();
  84. }
  85. }