StoreCombination.php 7.1 KB

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