StoreSeckill.php 4.0 KB

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