StoreSeckill.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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\activity\StoreActivityServices;
  15. use app\services\product\sku\StoreProductAttrValueServices;
  16. use crmeb\services\CacheService;
  17. use think\facade\App;
  18. /**
  19. * 限时秒杀 控制器
  20. * Class StoreSeckill
  21. * @package app\admin\controller\store
  22. */
  23. class StoreSeckill extends AuthController
  24. {
  25. public function __construct(App $app, StoreSeckillServices $services)
  26. {
  27. parent::__construct($app);
  28. $this->services = $services;
  29. }
  30. /**
  31. * 显示资源列表
  32. * @return mixed
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function index()
  38. {
  39. $where = $this->request->getMore([
  40. ['start_status', ''],
  41. [['status', 's'], ''],
  42. [['store_name', 's'], ''],
  43. [['product_id', 'd'], 0],
  44. ['activity_name', ''],
  45. ['time', ''],
  46. ['time_ids', []],
  47. ]);
  48. return app('json')->success($this->services->systemPage($where));
  49. }
  50. /**
  51. * 详情
  52. * @param $id
  53. * @return mixed
  54. */
  55. public function read($id)
  56. {
  57. $info = $this->services->getInfo($id);
  58. return app('json')->success(compact('info'));
  59. }
  60. /**
  61. * 保存秒杀商品
  62. * @param int $id
  63. */
  64. public function save($id)
  65. {
  66. $data = $this->request->postMore([
  67. [['product_id', 'd'], 0],
  68. [['title', 's'], ''],
  69. [['info', 's'], ''],
  70. [['unit_name', 's'], ''],
  71. ['images', []],
  72. [['give_integral', 'd'], 0],
  73. ['section_time', []],
  74. [['is_hot', 'd'], 0],
  75. [['status', 'd'], 0],
  76. [['num', 'd'], 0],
  77. [['once_num', 'd'], 0],
  78. ['time_id', []],
  79. [['temp_id', 'd'], 0],
  80. [['sort', 'd'], 0],
  81. [['description', 's'], ''],
  82. ['attrs', []],
  83. ['items', []],
  84. ['copy', 0],
  85. ['logistics', []],//物流方式
  86. ['freight', 1],//运费设置
  87. ['postage', 0],//邮费
  88. ['custom_form', ''],
  89. ['virtual_type', 0],
  90. ['is_commission', 0],
  91. ]);
  92. $this->validate($data, \app\adminapi\validate\marketing\StoreSeckillValidate::class, 'save');
  93. $this->services->saveData($id, $data);
  94. return app('json')->success(100000);
  95. }
  96. /**
  97. * 删除秒杀
  98. * @param $id
  99. * @return mixed
  100. */
  101. public function delete($id)
  102. {
  103. if (!$id) return app('json')->fail(100100);
  104. $this->services->update($id, ['is_del' => 1]);
  105. /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
  106. $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
  107. $unique = $storeProductAttrValueServices->value(['product_id' => $id, 'type' => 1], 'unique');
  108. if ($unique) {
  109. CacheService::delete('seckill_' . $unique . '_1');
  110. }
  111. return app('json')->success(100002);
  112. }
  113. /**
  114. * 修改状态
  115. * @param $id
  116. * @param $status
  117. * @return mixed
  118. */
  119. public function set_status($id, $status)
  120. {
  121. if ($status == 1) {
  122. $info = $this->services->get($id);
  123. if ($info['stop_time'] < time()) {
  124. return app('json')->fail('活动已结束,无法继续上架');
  125. }
  126. }
  127. $this->services->update($id, ['status' => $status]);
  128. return app('json')->success(100014);
  129. }
  130. /**
  131. * 秒杀时间段列表
  132. * @return mixed
  133. */
  134. public function time_list()
  135. {
  136. $list['data'] = sys_data('routine_seckill_time');
  137. foreach ($list['data'] as &$item) {
  138. $startTime = sprintf("%02d:00", $item['time']);
  139. $endTime = sprintf("%02d:00", $item['time'] + $item['continued']);
  140. $item['time_name'] = $startTime . '-' . $endTime;
  141. }
  142. return app('json')->success(compact('list'));
  143. }
  144. /**
  145. * 秒杀统计
  146. * @param $id
  147. * @return mixed
  148. * @throws \think\db\exception\DataNotFoundException
  149. * @throws \think\db\exception\DbException
  150. * @throws \think\db\exception\ModelNotFoundException
  151. */
  152. public function seckillStatistics($id)
  153. {
  154. $data = $this->services->seckillStatistics($id);
  155. return app('json')->success($data);
  156. }
  157. /**
  158. * 秒杀参与人统计
  159. * @param $id
  160. * @return mixed
  161. */
  162. public function seckillPeople($id)
  163. {
  164. [$keyword] = $this->request->getMore([
  165. ['real_name', '', '', 'keyword']
  166. ], true);
  167. return app('json')->success($this->services->seckillPeople($id, $keyword));
  168. }
  169. /**
  170. * 秒杀订单统计
  171. * @param $id
  172. * @return mixed
  173. */
  174. public function seckillOrder($id)
  175. {
  176. $where = $this->request->getMore([
  177. ['real_name', ''],
  178. ['status', '']
  179. ]);
  180. return app('json')->success($this->services->seckillOrder($id, $where));
  181. }
  182. public function seckillActivityList()
  183. {
  184. $where = $this->request->getMore([
  185. ['time', ''],
  186. ['status', ''],
  187. ['title', ''],
  188. ['time_ids', []]
  189. ]);
  190. $where['is_del'] = 0;
  191. $where['type'] = 1;
  192. return app('json')->success(app()->make(StoreActivityServices::class)->activityList($where));
  193. }
  194. public function seckillActivityInfo($id)
  195. {
  196. return app('json')->success(app()->make(StoreActivityServices::class)->activityInfo($id));
  197. }
  198. public function seckillActivitySave($id)
  199. {
  200. $data = $this->request->postMore([
  201. ['title', ''],
  202. ['section_time', []],
  203. ['time_ids', []],
  204. ['num', 0],
  205. ['once_num', 0],
  206. ['status', 1],
  207. ['is_commission', 0],
  208. ['product_infos', []]
  209. ]);
  210. $this->services->seckillActivitySave($id, $data);
  211. return app('json')->success('保存成功');
  212. }
  213. public function seckillActivityDel($id)
  214. {
  215. app()->make(StoreActivityServices::class)->activityDel($id, 1);
  216. return app('json')->success('删除成功');
  217. }
  218. public function seckillActivityStatus($id, $status)
  219. {
  220. app()->make(StoreActivityServices::class)->activityStatus($id, $status, 1);
  221. return app('json')->success('修改成功');
  222. }
  223. }