Printing.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * 打印设置控制器
  4. *
  5. * @author qifan
  6. * @date 2020-12-03
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\logic\PrintingLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class Printing extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission'=>[''],
  24. 'allow'=>['index', 'create', 'update', 'read', 'delete', 'field', 'copy']
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. if (!in_array($a, $action['permission'])) {
  30. parent::_initialize();
  31. }
  32. }
  33. /**
  34. * 打印模板列表
  35. *
  36. * @param PrintingLogic $printingLogic
  37. * @return \think\response\Json
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public function index(PrintingLogic $printingLogic)
  43. {
  44. $data = $printingLogic->index($this->param);
  45. return resultArray(['data' => $data]);
  46. }
  47. /**
  48. * 创建打印模板
  49. *
  50. * @param PrintingLogic $printingLogic
  51. * @return \think\response\Json
  52. */
  53. public function create(PrintingLogic $printingLogic)
  54. {
  55. $param = $this->param;
  56. if (empty($param['name'])) return resultArray(['error' => '缺少模板名称!']);
  57. if (empty($param['type'])) return resultArray(['error' => '缺少模板类型!']);
  58. if (!$printingLogic->create($param)) return resultArray(['error' => '添加失败!']);
  59. return resultArray(['data' => '添加成功!']);
  60. }
  61. /**
  62. * 获取模板详情
  63. *
  64. * @param PrintingLogic $printingLogic
  65. * @return \think\response\Json
  66. */
  67. public function read(PrintingLogic $printingLogic)
  68. {
  69. $id = $this->param['id'];
  70. if (empty($id)) return resultArray('缺少模板ID!');
  71. $data = $printingLogic->read($id);
  72. return resultArray(['data' => $data]);
  73. }
  74. /**
  75. * 更新模板数据
  76. *
  77. * @param PrintingLogic $printingLogic
  78. * @return \think\response\Json
  79. * @throws \think\Exception
  80. * @throws \think\exception\PDOException
  81. */
  82. public function update(PrintingLogic $printingLogic)
  83. {
  84. $param = $this->param;
  85. if (empty($param['id'])) return resultArray(['error' => '缺少模板ID!']);
  86. if (isset($param['name']) && empty($param['name'])) return resultArray(['error' => '名称不能为空!']);
  87. if ($printingLogic->update($param) === false) return resultArray(['error' => '更新失败!']);
  88. return resultArray(['data' => '更新成功!']);
  89. }
  90. /**
  91. * 删除模板数据
  92. *
  93. * @param PrintingLogic $printingLogic
  94. * @return \think\response\Json
  95. * @throws \think\Exception
  96. * @throws \think\exception\PDOException
  97. */
  98. public function delete(PrintingLogic $printingLogic)
  99. {
  100. $id = $this->param['id'];
  101. if (empty($id)) return resultArray(['error' => '缺少模板ID!']);
  102. if (!$printingLogic->delete($id)) return resultArray(['error' => '删除失败!']);
  103. return resultArray(['data' => '删除成功!']);
  104. }
  105. /**
  106. * 复制模板数据
  107. *
  108. * @param PrintingLogic $printingLogic
  109. * @return \think\response\Json
  110. * @throws \think\db\exception\DataNotFoundException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. * @throws \think\exception\DbException
  113. */
  114. public function copy(PrintingLogic $printingLogic)
  115. {
  116. $id = $this->param['id'];
  117. if (empty($id)) return resultArray(['error' => '缺少模板ID!']);
  118. if (!$printingLogic->copy($id)) return resultArray(['error' => '复制失败!']);
  119. return resultArray(['data' => '复制成功!']);
  120. }
  121. /**
  122. * 获取打印字段
  123. *
  124. * @param PrintingLogic $printingLogic
  125. * @return \think\response\Json
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. */
  130. public function field(PrintingLogic $printingLogic)
  131. {
  132. # 打印类型:5商机;6合同;7回款
  133. $type = !empty($this->param['type']) ? $this->param['type'] : 5;
  134. $data = $printingLogic->getFields($type);
  135. return resultArray(['data' => $data]);
  136. }
  137. }