Guarantee.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\admin\store;
  12. use app\common\repositories\store\GuaranteeRepository;
  13. use app\validate\admin\GuaranteeValidate;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. class Guarantee extends BaseController
  17. {
  18. /**
  19. * @var GuaranteeRepository
  20. */
  21. protected $repository;
  22. /**
  23. * City constructor.
  24. * @param App $app
  25. * @param GuaranteeRepository $repository
  26. */
  27. public function __construct(App $app, GuaranteeRepository $repository)
  28. {
  29. parent::__construct($app);
  30. $this->repository = $repository;
  31. }
  32. public function lst()
  33. {
  34. [$page, $limit] = $this->getPage();
  35. $where = $this->request->params(['date','keyword']);
  36. $where['is_del'] = 0;
  37. $data = $this->repository->getList($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(GuaranteeValidate $validate)
  45. {
  46. $data = $this->checkParams($validate);
  47. $this->repository->create($data);
  48. return app('json')->success('添加成功');
  49. }
  50. public function updateForm($id)
  51. {
  52. return app('json')->success(formToData($this->repository->updateForm($id)));
  53. }
  54. public function update($id,GuaranteeValidate $validate)
  55. {
  56. $ret = $this->repository->get($id);
  57. if(!$ret) return app('json')->fail('数据不存在');
  58. $data = $this->checkParams($validate);
  59. $this->repository->update($id,$data);
  60. return app('json')->success('编辑成功');
  61. }
  62. public function sort($id)
  63. {
  64. $ret = $this->repository->get($id);
  65. if(!$ret) return app('json')->fail('数据不存在');
  66. $data = [
  67. 'sort' => $this->request->param('sort'),
  68. ];
  69. $this->repository->update($id,$data);
  70. return app('json')->success('修改成功');
  71. }
  72. public function switchStatus($id)
  73. {
  74. $ret = $this->repository->get($id);
  75. if(!$ret) return app('json')->fail('数据不存在');
  76. $data = [
  77. 'status' => $this->request->param('status') == 1 ?: 0,
  78. ];
  79. $this->repository->update($id,$data);
  80. return app('json')->success('修改成功');
  81. }
  82. public function detail($id)
  83. {
  84. $ret = $this->repository->get($id);
  85. if(!$ret) return app('json')->fail('数据不存在');
  86. return app('json')->success($ret);
  87. }
  88. public function delete($id)
  89. {
  90. $ret = $this->repository->get($id);
  91. if(!$ret) return app('json')->fail('数据不存在');
  92. $this->repository->update($id,['is_del' => 1]);
  93. return app('json')->success('删除成功');
  94. }
  95. public function checkParams(GuaranteeValidate $validate)
  96. {
  97. $params = [
  98. "guarantee_name", "guarantee_info", "image", "status", "sort",
  99. ];
  100. $data = $this->request->params($params);
  101. $validate->check($data);
  102. return $data;
  103. }
  104. }