StoreCombination.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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\combination\StoreCombinationServices;
  14. use app\services\activity\combination\StorePinkServices;
  15. use think\facade\App;
  16. /**
  17. * 拼团管理
  18. * Class StoreCombination
  19. * @package app\admin\controller\store
  20. */
  21. class StoreCombination extends AuthController
  22. {
  23. /**
  24. * StoreCombination constructor.
  25. * @param App $app
  26. * @param StoreCombinationServices $services
  27. */
  28. public function __construct(App $app, StoreCombinationServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 拼团列表
  35. * @return mixed
  36. */
  37. public function index()
  38. {
  39. $where = $this->request->getMore([
  40. ['start_status', ''],
  41. ['is_show', ''],
  42. ['store_name', ''],
  43. ['product_id', 0]
  44. ]);
  45. $where['is_del'] = 0;
  46. $list = $this->services->systemPage($where);
  47. return app('json')->success($list);
  48. }
  49. /**
  50. * 拼团统计
  51. * @return mixed
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @throws \think\exception\DbException
  55. */
  56. public function statistics()
  57. {
  58. /** @var StorePinkServices $storePinkServices */
  59. $storePinkServices = app()->make(StorePinkServices::class);
  60. $info = $storePinkServices->getStatistics();
  61. return app('json')->success($info);
  62. }
  63. /**
  64. * 详情
  65. * @param $id
  66. * @return mixed
  67. */
  68. public function read($id)
  69. {
  70. $info = $info = $this->services->getInfo((int)$id);
  71. return app('json')->success(compact('info'));
  72. }
  73. /**
  74. * 保存新建的资源
  75. * @param int $id
  76. */
  77. public function save($id = 0)
  78. {
  79. $data = $this->request->postMore([
  80. [['product_id', 'd'], 0],
  81. [['title', 's'], ''],
  82. [['info', 's'], ''],
  83. [['unit_name', 's'], ''],
  84. ['image', ''],
  85. ['images', []],
  86. ['section_time', []],
  87. [['is_host', 'd'], 0],
  88. [['is_show', 'd'], 0],
  89. [['num', 'd'], 0],
  90. [['temp_id', 'd'], 0],
  91. [['effective_time', 'd'], 0],
  92. [['people', 'd'], 0],
  93. [['description', 's'], ''],
  94. ['attrs', []],
  95. ['items', []],
  96. ['num', 1],
  97. ['once_num', 1],
  98. ['sort', 0],
  99. ['copy', 0],
  100. ['virtual', 100],
  101. ['logistics', []],//物流方式
  102. ['freight', 1],//运费设置
  103. ['postage', 0],//邮费
  104. ['custom_form', ''],
  105. ['virtual_type', 0],
  106. ['is_commission', 0],
  107. ['head_commission', 0],
  108. ]);
  109. $this->validate($data, \app\adminapi\validate\marketing\StoreCombinationValidate::class, 'save');
  110. if ($data['section_time']) {
  111. [$start_time, $end_time] = $data['section_time'];
  112. if (strtotime($end_time) < time()) {
  113. return app('json')->fail(400507);
  114. }
  115. }
  116. $combination = [];
  117. if ($id) {
  118. $combination = $this->services->get((int)$id);
  119. if (!$combination) {
  120. return app('json')->fail(100026);
  121. }
  122. }
  123. //限制编辑
  124. if ($data['copy'] == 0 && $combination) {
  125. if ($combination['stop_time'] < time()) {
  126. return app('json')->fail(400508);
  127. }
  128. }
  129. if ($data['num'] < $data['once_num']) {
  130. return app('json')->fail(400500);
  131. }
  132. if ($data['copy'] == 1) {
  133. $id = 0;
  134. unset($data['copy']);
  135. }
  136. $this->services->saveData($id, $data);
  137. return app('json')->success(100000);
  138. }
  139. /**
  140. * 删除拼团
  141. * @param $id
  142. * @return mixed
  143. */
  144. public function delete($id)
  145. {
  146. $this->services->update($id, ['is_del' => 1]);
  147. return app('json')->success(100002);
  148. }
  149. /**
  150. * 修改状态
  151. * @param $id
  152. * @param $status
  153. * @return mixed
  154. */
  155. public function set_status($id, $status)
  156. {
  157. if ($status == 1) {
  158. $info = $this->services->get($id);
  159. if ($info['stop_time'] < time()) {
  160. return app('json')->fail('活动已结束,无法继续上架');
  161. }
  162. }
  163. $this->services->update($id, ['is_show' => $status]);
  164. return app('json')->success('设置成功');
  165. }
  166. /**
  167. * 拼团列表
  168. * @return mixed
  169. */
  170. public function combine_list()
  171. {
  172. $where = $this->request->getMore([
  173. ['status', ''],
  174. ['data', '', '', 'time'],
  175. ]);
  176. /** @var StorePinkServices $storePinkServices */
  177. $storePinkServices = app()->make(StorePinkServices::class);
  178. $list = $storePinkServices->systemPage($where);
  179. return app('json')->success($list);
  180. }
  181. /**
  182. * 拼团人列表
  183. * @param $id
  184. * @return mixed
  185. * @throws \think\db\exception\DataNotFoundException
  186. * @throws \think\db\exception\DbException
  187. * @throws \think\db\exception\ModelNotFoundException
  188. */
  189. public function order_pink($id)
  190. {
  191. /** @var StorePinkServices $storePinkServices */
  192. $storePinkServices = app()->make(StorePinkServices::class);
  193. $list = $storePinkServices->getPinkMember($id);
  194. return app('json')->success(compact('list'));
  195. }
  196. /**
  197. * 拼团统计
  198. * @param $id
  199. * @return mixed
  200. */
  201. public function combinationStatistics($id)
  202. {
  203. $data = $this->services->combinationStatistics($id);
  204. return app('json')->success($data);
  205. }
  206. /**
  207. * 活动参与人
  208. * @param $id
  209. * @return mixed
  210. * @throws \think\db\exception\DataNotFoundException
  211. * @throws \think\db\exception\DbException
  212. * @throws \think\db\exception\ModelNotFoundException
  213. */
  214. public function combinationStatisticsList($id)
  215. {
  216. $where = $this->request->getMore([
  217. ['real_name', '', '', 'keyword'],
  218. ['status', '']
  219. ]);
  220. $where['cid'] = $id;
  221. /** @var StorePinkServices $storePinkServices */
  222. $storePinkServices = app()->make(StorePinkServices::class);
  223. $list = $storePinkServices->systemPage($where);
  224. return app('json')->success($list);
  225. }
  226. /**
  227. * 拼团订单
  228. * @param $id
  229. * @return mixed
  230. */
  231. public function combinationStatisticsOrder($id)
  232. {
  233. $where = $this->request->getMore([
  234. ['real_name', ''],
  235. ['status', '']
  236. ]);
  237. return app('json')->success($this->services->combinationStatisticsOrder($id, $where));
  238. }
  239. /**
  240. * 立即成团
  241. * @param $id
  242. * @return \think\Response
  243. * @throws \think\db\exception\DataNotFoundException
  244. * @throws \think\db\exception\DbException
  245. * @throws \think\db\exception\ModelNotFoundException
  246. * @author wuhaotian
  247. * @email 442384644@qq.com
  248. * @date 2025/6/18
  249. */
  250. public function immediatelyCombination($id)
  251. {
  252. /** @var StorePinkServices $storePinkServices */
  253. $storePinkServices = app()->make(StorePinkServices::class);
  254. $storePinkServices->virtualCombination($id, 'admin');
  255. return app('json')->success('成团成功');
  256. }
  257. }