StoreCombination.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. ]);
  44. $where['is_del'] = 0;
  45. $list = $this->services->systemPage($where);
  46. return app('json')->success($list);
  47. }
  48. /**
  49. * 拼团统计
  50. * @return mixed
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. public function statistics()
  56. {
  57. /** @var StorePinkServices $storePinkServices */
  58. $storePinkServices = app()->make(StorePinkServices::class);
  59. $info = $storePinkServices->getStatistics();
  60. return app('json')->success($info);
  61. }
  62. /**
  63. * 详情
  64. * @param $id
  65. * @return mixed
  66. */
  67. public function read($id)
  68. {
  69. $info = $info = $this->services->getInfo((int)$id);
  70. return app('json')->success(compact('info'));
  71. }
  72. /**
  73. * 保存新建的资源
  74. * @param int $id
  75. */
  76. public function save($id = 0)
  77. {
  78. $data = $this->request->postMore([
  79. [['product_id', 'd'], 0],
  80. [['title', 's'], ''],
  81. [['info', 's'], ''],
  82. [['unit_name', 's'], ''],
  83. ['images', []],
  84. ['section_time', []],
  85. [['is_host', 'd'], 0],
  86. [['is_show', 'd'], 0],
  87. [['num', 'd'], 0],
  88. [['temp_id', 'd'], 0],
  89. [['effective_time', 'd'], 0],
  90. [['people', 'd'], 0],
  91. [['description', 's'], ''],
  92. ['attrs', []],
  93. ['items', []],
  94. ['num', 1],
  95. ['once_num', 1],
  96. ['sort', 0],
  97. ['copy', 0],
  98. ['virtual', 100],
  99. ['logistics', []],//物流方式
  100. ['freight', 1],//运费设置
  101. ['postage', 0],//邮费
  102. ['custom_form', ''],
  103. ['virtual_type', 0],
  104. ['is_commission', 0],
  105. ['head_commission', 0],
  106. ]);
  107. $this->validate($data, \app\adminapi\validate\marketing\StoreCombinationValidate::class, 'save');
  108. if ($data['section_time']) {
  109. [$start_time, $end_time] = $data['section_time'];
  110. if (strtotime($end_time) < time()) {
  111. return app('json')->fail(400507);
  112. }
  113. }
  114. $combination = [];
  115. if ($id) {
  116. $combination = $this->services->get((int)$id);
  117. if (!$combination) {
  118. return app('json')->fail(100026);
  119. }
  120. }
  121. //限制编辑
  122. if ($data['copy'] == 0 && $combination) {
  123. if ($combination['stop_time'] < time()) {
  124. return app('json')->fail(400508);
  125. }
  126. }
  127. if ($data['num'] < $data['once_num']) {
  128. return app('json')->fail(400500);
  129. }
  130. if ($data['copy'] == 1) {
  131. $id = 0;
  132. unset($data['copy']);
  133. }
  134. $this->services->saveData($id, $data);
  135. return app('json')->success(100000);
  136. }
  137. /**
  138. * 删除拼团
  139. * @param $id
  140. * @return mixed
  141. */
  142. public function delete($id)
  143. {
  144. $this->services->update($id, ['is_del' => 1]);
  145. return app('json')->success(100002);
  146. }
  147. /**
  148. * 修改状态
  149. * @param $id
  150. * @param $status
  151. * @return mixed
  152. */
  153. public function set_status($id, $status)
  154. {
  155. $this->services->update($id, ['is_show' => $status]);
  156. return app('json')->success($status == 0 ? 100014 : 100015);
  157. }
  158. /**
  159. * 拼团列表
  160. * @return mixed
  161. */
  162. public function combine_list()
  163. {
  164. $where = $this->request->getMore([
  165. ['status', ''],
  166. ['data', '', '', 'time'],
  167. ]);
  168. /** @var StorePinkServices $storePinkServices */
  169. $storePinkServices = app()->make(StorePinkServices::class);
  170. $list = $storePinkServices->systemPage($where);
  171. return app('json')->success($list);
  172. }
  173. /**
  174. * 拼团人列表
  175. * @param $id
  176. * @return mixed
  177. * @throws \think\db\exception\DataNotFoundException
  178. * @throws \think\db\exception\DbException
  179. * @throws \think\db\exception\ModelNotFoundException
  180. */
  181. public function order_pink($id)
  182. {
  183. /** @var StorePinkServices $storePinkServices */
  184. $storePinkServices = app()->make(StorePinkServices::class);
  185. $list = $storePinkServices->getPinkMember($id);
  186. return app('json')->success(compact('list'));
  187. }
  188. /**
  189. * 拼团统计
  190. * @param $id
  191. * @return mixed
  192. */
  193. public function combinationStatistics($id)
  194. {
  195. $data = $this->services->combinationStatistics($id);
  196. return app('json')->success($data);
  197. }
  198. /**
  199. * 活动参与人
  200. * @param $id
  201. * @return mixed
  202. * @throws \think\db\exception\DataNotFoundException
  203. * @throws \think\db\exception\DbException
  204. * @throws \think\db\exception\ModelNotFoundException
  205. */
  206. public function combinationStatisticsList($id)
  207. {
  208. $where = $this->request->getMore([
  209. ['real_name', '', '', 'keyword'],
  210. ['status', '']
  211. ]);
  212. $where['cid'] = $id;
  213. /** @var StorePinkServices $storePinkServices */
  214. $storePinkServices = app()->make(StorePinkServices::class);
  215. $list = $storePinkServices->systemPage($where);
  216. return app('json')->success($list);
  217. }
  218. /**
  219. * 拼团订单
  220. * @param $id
  221. * @return mixed
  222. */
  223. public function combinationStatisticsOrder($id)
  224. {
  225. $where = $this->request->getMore([
  226. ['real_name', ''],
  227. ['status', '']
  228. ]);
  229. return app('json')->success($this->services->combinationStatisticsOrder($id, $where));
  230. }
  231. }