StoreSeckill.php 3.4 KB

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