StoreSeckill.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\marketing;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\seckill\StoreSeckillServices;
  14. use app\services\product\sku\StoreProductAttrValueServices;
  15. use crmeb\services\CacheService;
  16. use think\facade\App;
  17. /**
  18. * 限时秒杀 控制器
  19. * Class StoreSeckill
  20. * @package app\admin\controller\store
  21. */
  22. class StoreSeckill extends AuthController
  23. {
  24. public function __construct(App $app, StoreSeckillServices $services)
  25. {
  26. parent::__construct($app);
  27. $this->services = $services;
  28. }
  29. /**
  30. * 显示资源列表
  31. * @return mixed
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function index()
  37. {
  38. $where = $this->request->getMore([
  39. ['start_status', ''],
  40. [['status', 's'], ''],
  41. [['store_name', 's'], '']
  42. ]);
  43. return app('json')->success($this->services->systemPage($where));
  44. }
  45. /**
  46. * 详情
  47. * @param $id
  48. * @return mixed
  49. */
  50. public function read($id)
  51. {
  52. $info = $this->services->getInfo($id);
  53. return app('json')->success(compact('info'));
  54. }
  55. /**
  56. * 保存秒杀商品
  57. * @param int $id
  58. */
  59. public function save($id)
  60. {
  61. $data = $this->request->postMore([
  62. [['product_id', 'd'], 0],
  63. [['title', 's'], ''],
  64. [['info', 's'], ''],
  65. [['unit_name', 's'], ''],
  66. ['images', []],
  67. [['give_integral', 'd'], 0],
  68. ['section_time', []],
  69. [['is_hot', 'd'], 0],
  70. [['status', 'd'], 0],
  71. [['num', 'd'], 0],
  72. [['once_num', 'd'], 0],
  73. [['time_id', 'd'], 0],
  74. [['temp_id', 'd'], 0],
  75. [['sort', 'd'], 0],
  76. [['description', 's'], ''],
  77. ['attrs', []],
  78. ['items', []],
  79. ['copy', 0],
  80. ['logistics', []],//物流方式
  81. ['freight', 1],//运费设置
  82. ['postage', 0],//邮费
  83. ['custom_form', ''],
  84. ['virtual_type', 0],
  85. ['is_commission', 0],
  86. ]);
  87. $this->validate($data, \app\adminapi\validate\marketing\StoreSeckillValidate::class, 'save');
  88. $this->services->saveData($id, $data);
  89. return app('json')->success(100000);
  90. }
  91. /**
  92. * 删除秒杀
  93. * @param $id
  94. * @return mixed
  95. */
  96. public function delete($id)
  97. {
  98. if (!$id) return app('json')->fail(100100);
  99. $this->services->update($id, ['is_del' => 1]);
  100. /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
  101. $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
  102. $unique = $storeProductAttrValueServices->value(['product_id' => $id, 'type' => 1], 'unique');
  103. if ($unique) {
  104. CacheService::delete('seckill_' . $unique . '_1');
  105. }
  106. return app('json')->success(100002);
  107. }
  108. /**
  109. * 修改状态
  110. * @param $id
  111. * @param $status
  112. * @return mixed
  113. */
  114. public function set_status($id, $status)
  115. {
  116. $this->services->update($id, ['status' => $status]);
  117. return app('json')->success(100014);
  118. }
  119. /**
  120. * 秒杀时间段列表
  121. * @return mixed
  122. */
  123. public function time_list()
  124. {
  125. $list['data'] = sys_data('routine_seckill_time');
  126. return app('json')->success(compact('list'));
  127. }
  128. /**
  129. * 秒杀统计
  130. * @param $id
  131. * @return mixed
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\DbException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. */
  136. public function seckillStatistics($id)
  137. {
  138. $data = $this->services->seckillStatistics($id);
  139. return app('json')->success($data);
  140. }
  141. /**
  142. * 秒杀参与人统计
  143. * @param $id
  144. * @return mixed
  145. */
  146. public function seckillPeople($id)
  147. {
  148. [$keyword] = $this->request->getMore([
  149. ['real_name', '', '', 'keyword']
  150. ], true);
  151. return app('json')->success($this->services->seckillPeople($id, $keyword));
  152. }
  153. /**
  154. * 秒杀订单统计
  155. * @param $id
  156. * @return mixed
  157. */
  158. public function seckillOrder($id)
  159. {
  160. $where = $this->request->getMore([
  161. ['real_name', ''],
  162. ['status', '']
  163. ]);
  164. return app('json')->success($this->services->seckillOrder($id, $where));
  165. }
  166. }