StorePrinter.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\merchant\store;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\store\StorePrinterRepository;
  14. use crmeb\exceptions\UploadException;
  15. use crmeb\services\ExcelService;
  16. use think\App;
  17. use crmeb\basic\BaseController;
  18. class StorePrinter extends BaseController
  19. {
  20. protected $repository;
  21. public function __construct(App $app, StorePrinterRepository $repository)
  22. {
  23. parent::__construct($app);
  24. $this->repository = $repository;
  25. }
  26. /**
  27. * TODO
  28. * @return mixed
  29. * @author Qinii
  30. * @day 2020-08-15
  31. */
  32. public function lst()
  33. {
  34. [$page, $limit] = $this->getPage();
  35. $where = $this->request->params(['status','keyword']);
  36. $where['mer_id'] = $this->request->merId();
  37. $data = $this->repository->merList($where,$page,$limit);
  38. return app('json')->success($data);
  39. }
  40. public function createForm()
  41. {
  42. return app('json')->success(formToData($this->repository->form(null)));
  43. }
  44. public function create()
  45. {
  46. $params = $this->request->params([
  47. 'printer_name',
  48. 'printer_appkey',
  49. 'printer_appid',
  50. 'printer_secret',
  51. 'printer_terminal',
  52. 'status',
  53. ]);
  54. if (!$params['printer_name'] ||
  55. !$params['printer_appkey'] ||
  56. !$params['printer_appid'] ||
  57. !$params['printer_secret'] ||
  58. !$params['printer_terminal']
  59. ) {
  60. return app('json')->fail('信息不完整');
  61. }
  62. $params['mer_id'] = $this->request->merId();
  63. $this->repository->create($params);
  64. return app('json')->success('添加成功');
  65. }
  66. public function updateForm($id)
  67. {
  68. return app('json')->success(formToData($this->repository->form($id)));
  69. }
  70. public function update($id)
  71. {
  72. $params = $this->request->params([
  73. 'printer_name',
  74. 'printer_appkey',
  75. 'printer_appid',
  76. 'printer_secret',
  77. 'printer_terminal',
  78. 'status',
  79. ]);
  80. if (!$params['printer_name'] ||
  81. !$params['printer_appkey'] ||
  82. !$params['printer_appid'] ||
  83. !$params['printer_secret'] ||
  84. !$params['printer_terminal']
  85. ) {
  86. return app('json')->fail('信息不完整');
  87. }
  88. $res = $this->repository->getWhere(['printer_id' => $id, 'mer_id' => $this->request->merId()]);
  89. if (!$res) return app('json')->fail('打印机信息不存在');
  90. $this->repository->update($id, $params);
  91. return app('json')->success('添加成功');
  92. }
  93. public function delete($id)
  94. {
  95. $res = $this->repository->getWhere(['printer_id' => $id, 'mer_id' => $this->request->merId()]);
  96. if (!$res) return app('json')->fail('打印机信息不存在');
  97. $this->repository->delete($id);
  98. return app('json')->success('删除成功');
  99. }
  100. public function switchWithStatus($id)
  101. {
  102. $status = $this->request->param('status') == 1 ? 1 : 0;
  103. $this->repository->update($id,['status' => $status]);
  104. return app('json')->success('修改成功');
  105. }
  106. }