Printing.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * 模板打印控制器
  4. *
  5. * @author qifan
  6. * @date 2020-12-15
  7. */
  8. namespace app\crm\controller;
  9. use app\admin\controller\ApiCommon;
  10. use app\crm\logic\PrintingLogic;
  11. use think\Hook;
  12. use think\Request;
  13. class Printing extends ApiCommon
  14. {
  15. public function _initialize()
  16. {
  17. $action = [
  18. 'permission'=>[''],
  19. 'allow'=>['printingdata', 'template', 'setrecord', 'getrecord']
  20. ];
  21. Hook::listen('check_auth',$action);
  22. $request = Request::instance();
  23. $a = strtolower($request->action());
  24. if (!in_array($a, $action['permission'])) {
  25. parent::_initialize();
  26. }
  27. }
  28. /**
  29. * 获取打印的数据
  30. *
  31. * @param PrintingLogic $printingLogic
  32. * @return \think\response\Json
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \think\exception\DbException
  36. */
  37. public function printingData(PrintingLogic $printingLogic)
  38. {
  39. $actionId = $this->param['action_id'];
  40. $templateId = $this->param['template_id'];
  41. $type = $this->param['type'];
  42. if (empty($actionId)) return resultArray(['error' => '请选择打印的数据!']);
  43. if (empty($templateId)) return resultArray(['error' => '请选择打印的模板!']);
  44. if (empty($type)) return resultArray(['error' => '请选择打印的类型!']);
  45. $data = $printingLogic->getPrintingData($type, $actionId, $templateId);
  46. return resultArray(['data' => $data]);
  47. }
  48. /**
  49. * 获取打印模板列表
  50. *
  51. * @param PrintingLogic $printingLogic
  52. * @return \think\response\Json
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. */
  57. public function template(PrintingLogic $printingLogic)
  58. {
  59. if (empty($this->param['type'])) return resultArray(['error' => '请选择打印的类型!']);
  60. $data = $printingLogic->getTemplateList($this->param['type']);
  61. return resultArray(['data' => $data]);
  62. }
  63. /**
  64. * 创建模板打印记录
  65. *
  66. * @param PrintingLogic $printingLogic
  67. * @return \think\response\Json
  68. */
  69. public function setRecord(PrintingLogic $printingLogic)
  70. {
  71. if (empty($this->param['type'])) return resultArray(['error' => '请选择模块!']);
  72. if (empty($this->param['action_id'])) return resultArray(['error' => '缺少数据ID!']);
  73. if (empty($this->param['template_id'])) return resultArray(['error' => '缺少模板ID!']);
  74. $userId = $this->userInfo['id'];
  75. if (!$printingLogic->setRecord($userId, $this->param)) return resultArray(['error' => '操作失败!']);
  76. return resultArray(['data' => '操作成功!']);
  77. }
  78. /**
  79. * 获取打印记录
  80. *
  81. * @param PrintingLogic $printingLogic
  82. * @return \think\response\Json
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. * @throws \think\exception\DbException
  86. */
  87. public function getRecord(PrintingLogic $printingLogic)
  88. {
  89. if (empty($this->param['type'])) return resultArray(['error' => '请选择模块!']);
  90. $data = $printingLogic->getRecord($this->param, $this->userInfo['id']);
  91. return resultArray(['data' => $data]);
  92. }
  93. }