Config.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\system\serve;
  12. use app\common\repositories\system\serve\ServeMealRepository;
  13. use app\validate\admin\MealValidata;
  14. use crmeb\basic\BaseController;
  15. use think\App;
  16. /**
  17. * 一号通套餐
  18. */
  19. class Config extends BaseController
  20. {
  21. protected $repository;
  22. public function __construct(App $app, ServeMealRepository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. /**
  28. * 平台配置 商户购买套餐列表
  29. * @return mixed
  30. * @author Qinii
  31. */
  32. public function lst()
  33. {
  34. [$page, $limit] = $this->getPage();
  35. $where = $this->request->params(['status', 'type']);
  36. $data = $this->repository->getList($where, $page, $limit);
  37. return app('json')->success($data);
  38. }
  39. /**
  40. * 添加套餐
  41. * @return mixed
  42. * @author Qinii
  43. */
  44. public function createForm()
  45. {
  46. return app('json')->success(formToData($this->repository->form()));
  47. }
  48. /**
  49. * 添加套餐
  50. * @return mixed
  51. * @author Qinii
  52. */
  53. public function create(MealValidata $validata)
  54. {
  55. $data = $this->request->params(['name', 'price', 'num', 'type', 'status', 'sort']);
  56. $validata->scene('create')->check($data);
  57. $this->repository->create($data);
  58. return app('json')->success('添加成功');
  59. }
  60. /**
  61. * 套餐详情
  62. * @param $id
  63. * @return mixed
  64. * @author Qinii
  65. */
  66. public function detail($id)
  67. {
  68. $data = $this->repository->get($id);
  69. if (!$data) return app('json')->fail('数据不存在');
  70. return app('json')->success($data);
  71. }
  72. /**
  73. * 修改套餐
  74. * @param $id
  75. * @return mixed
  76. * @author Qinii
  77. */
  78. public function updateForm($id)
  79. {
  80. return app('json')->success(formToData($this->repository->updateForm($id)));
  81. }
  82. /**
  83. * 修改套餐
  84. * @param $id
  85. * @return mixed
  86. * @author Qinii
  87. */
  88. public function update($id, MealValidata $validata)
  89. {
  90. $data = $this->request->params(['name', 'price', 'num', 'type', 'status', 'sort']);
  91. $validata->scene('create')->check($data);
  92. $this->repository->update($id, $data);
  93. return app('json')->success('编辑成功');
  94. }
  95. /**
  96. * 删除套餐
  97. * @param $id
  98. * @return \think\response\Json
  99. * @author Qinii
  100. */
  101. public function detele($id)
  102. {
  103. $this->repository->delete($id);
  104. return app('json')->success('删除成功');
  105. }
  106. /**
  107. * 套餐状态
  108. * @param $id
  109. * @return mixed
  110. * @author Qinii
  111. */
  112. public function switchStatus($id)
  113. {
  114. $status = $this->request->param('status', 1) == 1 ?: 0;
  115. $this->repository->update($id, ['status' => $status]);
  116. return app('json')->success('修改成功');
  117. }
  118. }