StoreAtmosphere.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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\store\marketing;
  12. use app\common\repositories\store\product\SpuRepository;
  13. use app\common\repositories\system\RelevanceRepository;
  14. use app\validate\admin\StoreActivityValidate;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. use app\common\repositories\store\StoreActivityRepository as repository;
  18. /**
  19. * 活动氛围图
  20. */
  21. class StoreAtmosphere extends BaseController
  22. {
  23. /**
  24. * @var repository
  25. */
  26. protected $repository;
  27. /**
  28. * StoreProduct constructor.
  29. * @param App $app
  30. * @param repository $repository
  31. */
  32. public function __construct(App $app, repository $repository)
  33. {
  34. parent::__construct($app);
  35. $this->repository = $repository;
  36. }
  37. /**
  38. * 列表
  39. * @return mixed
  40. * @Author: liusl
  41. * @Date: 2022/6/24
  42. */
  43. public function lst()
  44. {
  45. [$page, $limit] = $this->getPage();
  46. $where = $this->request->params(['keyword', 'status', 'date']);
  47. $where['activity_type'] = repository::ACTIVITY_TYPE_ATMOSPHERE;
  48. return app('json')->success($this->repository->getAdminList($where, $page, $limit));
  49. }
  50. /**
  51. * 添加
  52. * @param StoreActivityValidate $validate
  53. * @return \think\response\Json
  54. * @author Qinii
  55. * @day 2022/9/16
  56. */
  57. public function create(StoreActivityValidate $validate)
  58. {
  59. [$data, $extend] = $this->checkParams($validate);
  60. $this->repository->createActivity($data, $extend);
  61. return app('json')->success('添加成功');
  62. }
  63. /**
  64. * 参数验证
  65. * @param StoreActivityValidate $validate
  66. * @return array
  67. * @author Qinii
  68. * @day 2022/9/15
  69. */
  70. public function checkParams(StoreActivityValidate $validate)
  71. {
  72. $ids = [
  73. $this->repository::TYPE_ALL => '',
  74. $this->repository::TYPE_MUST_PRODUCT => 'spu_ids',
  75. $this->repository::TYPE_MUST_CATEGORY => 'cate_ids',
  76. $this->repository::TYPE_MUST_STORE => 'mer_ids',
  77. $this->repository::TYPE_MUST_PRODUCT_LABEL => 'label_ids',
  78. ];
  79. $params = ["activity_name", "start_time", "end_time", "is_show", "pic", 'scope_type'];
  80. $data = $this->request->params($params);
  81. $validate->check($data);
  82. $data['activity_type'] = repository::ACTIVITY_TYPE_ATMOSPHERE;
  83. if (strtotime($data['start_time']) <= time()) {
  84. $data['status'] = 1;
  85. }
  86. $extend = $this->request->params([$ids[$data['scope_type']]]);
  87. return [$data, $extend];
  88. }
  89. /**
  90. * 编辑
  91. * @param StoreActivityValidate $validate
  92. * @param $id
  93. * @return \think\response\Json
  94. * @author Qinii
  95. * @day 2022/9/17
  96. */
  97. public function update(StoreActivityValidate $validate, $id)
  98. {
  99. if (!$this->repository->exists($id))
  100. return app('json')->fail('数据不存在');
  101. [$data, $extend] = $this->checkParams($validate);
  102. $this->repository->updateActivity($id, $data, $extend);
  103. return app('json')->success('修改成功');
  104. }
  105. /**
  106. * 状态修改
  107. * @param $id
  108. * @return \think\response\Json
  109. * @author Qinii
  110. */
  111. public function statusSwitch($id)
  112. {
  113. if (!$this->repository->exists($id))
  114. return app('json')->fail('数据不存在');
  115. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  116. $this->repository->update($id, ['is_show' => $status]);
  117. return app('json')->success('修改成功');
  118. }
  119. /**
  120. * 详情
  121. * @param $id
  122. * @return \think\response\Json
  123. * @author Qinii
  124. * @day 2022/9/16
  125. */
  126. public function detail($id)
  127. {
  128. if (!$this->repository->exists($id))
  129. return app('json')->fail('数据不存在');
  130. return app('json')->success($this->repository->detail($id));
  131. }
  132. /**
  133. * 删除
  134. * @param $id
  135. * @return mixed
  136. * @Author: liusl
  137. * @Date: 2022/6/27
  138. */
  139. public function delete($id)
  140. {
  141. if (!$this->repository->exists($id))
  142. return app('json')->fail('数据不存在');
  143. $this->repository->deleteActivity($id);
  144. return app('json')->success('删除成功');
  145. }
  146. /**
  147. * 商品列表
  148. * @param SpuRepository $repository
  149. * @return \think\response\Json
  150. * @author Qinii
  151. */
  152. public function markLst(SpuRepository $repository)
  153. {
  154. [$page, $limit] = $this->getPage();
  155. $where = $this->request->params([
  156. 'keyword',
  157. 'cate_id',
  158. 'cate_pid',
  159. 'brand_id',
  160. 'product_type',
  161. 'spu_ids',
  162. 'mer_id',
  163. ['not_type',1]
  164. ]);
  165. $where['is_gift_bag'] = 0;
  166. $data = $repository->makinList($where, $page, $limit);
  167. return app('json')->success($data);
  168. }
  169. }