StoreSeckill.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/13
  6. */
  7. namespace app\controller\admin\store;
  8. use think\App;
  9. use crmeb\basic\BaseController;
  10. use app\validate\admin\StoreSeckillValidate;
  11. use app\common\repositories\store\StoreSeckillTimeRepository as repository;
  12. class StoreSeckill extends BaseController
  13. {
  14. /**
  15. * @var repository
  16. */
  17. protected $repository;
  18. /**
  19. * Express constructor.
  20. * @param App $app
  21. * @param repository $repository
  22. */
  23. public function __construct(App $app, repository $repository)
  24. {
  25. parent::__construct($app);
  26. $this->repository = $repository;
  27. }
  28. /**
  29. * @Author:Qinii
  30. * @Date: 2020/5/13
  31. * @return mixed
  32. */
  33. public function lst()
  34. {
  35. [$page , $limit] = $this->getPage();
  36. $where = $this->request->params(['title','status']);
  37. return app('json')->success($this->repository->getList($where, $page, $limit));
  38. }
  39. /**
  40. * TODO
  41. * @return mixed
  42. * @author Qinii
  43. * @day 2020-08-01
  44. */
  45. public function select()
  46. {
  47. return app('json')->success($this->repository->select());
  48. }
  49. /**
  50. * @Author:Qinii
  51. * @Date: 2020/5/13
  52. * @return mixed
  53. */
  54. public function create(StoreSeckillValidate $validate)
  55. {
  56. $data = $this->checkParams($validate);
  57. if(!$this->repository->checkTime($data,null))
  58. return app('json')->fail('时间段不可重叠');
  59. $this->repository->create($data);
  60. return app('json')->success('添加成功');
  61. }
  62. /**
  63. * TODO
  64. * @param $id
  65. * @param StoreSeckillValidate $validate
  66. * @return mixed
  67. * @author Qinii
  68. * @day 2020-07-31
  69. */
  70. public function update($id,StoreSeckillValidate $validate)
  71. {
  72. $data = $this->checkParams($validate);
  73. if(!$this->repository->checkTime($data,$id))
  74. return app('json')->fail('时间段不可重叠');
  75. $this->repository->update($id,$data);
  76. return app('json')->success('编辑成功');
  77. }
  78. /**
  79. * TODO
  80. * @param $id
  81. * @return mixed
  82. * @author Qinii
  83. * @day 2020-07-31
  84. */
  85. public function delete($id)
  86. {
  87. if(!$this->repository->get($id))
  88. return app('json')->fail('数据不存在');
  89. $this->repository->delete($id);
  90. return app('json')->success('删除成功');
  91. }
  92. /**
  93. * TODO
  94. * @return mixed
  95. * @author Qinii
  96. * @day 2020-07-31
  97. */
  98. public function createForm()
  99. {
  100. return app('json')->success(formToData($this->repository->form()));
  101. }
  102. /**
  103. * TODO
  104. * @param $id
  105. * @return mixed
  106. * @author Qinii
  107. * @day 2020-07-31
  108. */
  109. public function updateForm($id)
  110. {
  111. return app('json')->success(formToData($this->repository->updateForm($id)));
  112. }
  113. /**
  114. * TODO
  115. * @param $id
  116. * @return mixed
  117. * @author Qinii
  118. * @day 2020-07-31
  119. */
  120. public function switchStatus($id)
  121. {
  122. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  123. if(!$this->repository->get($id))
  124. return app('json')->fail('数据不存在');
  125. $this->repository->update($id, ['status' =>$status]);
  126. return app('json')->success('修改成功');
  127. }
  128. public function checkParams(StoreSeckillValidate $validate)
  129. {
  130. $data = $this->request->params(['start_time','end_time','status','title','pic']);
  131. $validate->check($data);
  132. return $data;
  133. }
  134. }